Skip to content

Commit 44bdbd1

Browse files
committed
store test [nfc]: Inline checkReloadFailure helper at both callsites
For #1354, we'll need an alternative to TestGlobalStore that runs UpdateMachine.load with prepared API responses instead of mocking it. Since FakeApiConnection doesn't yet offer a `Completer`-based way of completing/awaiting requests, these two tests will have to diverge, preparing and awaiting different delays as needed.
1 parent dc1c806 commit 44bdbd1

File tree

1 file changed

+19
-20
lines changed

1 file changed

+19
-20
lines changed

test/model/store_test.dart

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,13 +1018,15 @@ void main() {
10181018
check(store).isLoading.isTrue();
10191019
}
10201020

1021-
void checkReloadFailure(FakeAsync async, {
1022-
required FutureOr<void> Function() completeLoading,
1023-
}) async {
1021+
test('user logged out before new store is loaded', () => awaitFakeAsync((async) async {
10241022
await prepareReload(async);
10251023
check(completers()).single.isCompleted.isFalse();
10261024

1027-
await completeLoading();
1025+
// [PerAccountStore.fromInitialSnapshot] requires the account
1026+
// to be in the global store when called; do so before logging out.
1027+
final newStore = eg.store(globalStore: globalStore, account: eg.selfAccount);
1028+
await logOutAccount(globalStore, eg.selfAccount.id);
1029+
completers().single.complete(newStore);
10281030
check(completers()).single.isCompleted.isTrue();
10291031
check(globalStore.takeDoRemoveAccountCalls()).single.equals(eg.selfAccount.id);
10301032

@@ -1034,26 +1036,23 @@ void main() {
10341036
async.flushTimers();
10351037
// Reload never succeeds and there are no unhandled errors.
10361038
check(globalStore.perAccountSync(eg.selfAccount.id)).isNull();
1037-
}
1038-
1039-
Future<void> logOutAndCompleteWithNewStore() async {
1040-
// [PerAccountStore.fromInitialSnapshot] requires the account
1041-
// to be in the global store when called; do so before logging out.
1042-
final newStore = eg.store(globalStore: globalStore, account: eg.selfAccount);
1043-
await logOutAccount(globalStore, eg.selfAccount.id);
1044-
completers().single.complete(newStore);
1045-
}
1046-
1047-
test('user logged out before new store is loaded', () => awaitFakeAsync((async) async {
1048-
checkReloadFailure(async, completeLoading: logOutAndCompleteWithNewStore);
10491039
}));
10501040

1051-
void completeWithApiExceptionUnauthorized() {
1041+
test('new store is not loaded, gets HTTP 401 error instead', () => awaitFakeAsync((async) async {
1042+
await prepareReload(async);
1043+
check(completers()).single.isCompleted.isFalse();
1044+
10521045
completers().single.completeError(eg.apiExceptionUnauthorized());
1053-
}
1046+
async.elapse(Duration.zero);
1047+
check(completers()).single.isCompleted.isTrue();
1048+
check(globalStore.takeDoRemoveAccountCalls()).single.equals(eg.selfAccount.id);
10541049

1055-
test('new store is not loaded, gets HTTP 401 error instead', () => awaitFakeAsync((async) async {
1056-
checkReloadFailure(async, completeLoading: completeWithApiExceptionUnauthorized);
1050+
async.elapse(TestGlobalStore.removeAccountDuration);
1051+
check(globalStore.perAccountSync(eg.selfAccount.id)).isNull();
1052+
1053+
async.flushTimers();
1054+
// Reload never succeeds and there are no unhandled errors.
1055+
check(globalStore.perAccountSync(eg.selfAccount.id)).isNull();
10571056
}));
10581057
});
10591058

0 commit comments

Comments
 (0)