Skip to content

Commit d09a122

Browse files
committed
store test [nfc]: Inline checkReloadFailure helper at both callsites
For zulip#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 fcce4f2 commit d09a122

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
@@ -991,13 +991,15 @@ void main() {
991991
check(store).isLoading.isTrue();
992992
}
993993

994-
void checkReloadFailure(FakeAsync async, {
995-
required FutureOr<void> Function() completeLoading,
996-
}) async {
994+
test('user logged out before new store is loaded', () => awaitFakeAsync((async) async {
997995
await prepareReload(async);
998996
check(completers()).single.isCompleted.isFalse();
999997

1000-
await completeLoading();
998+
// [PerAccountStore.fromInitialSnapshot] requires the account
999+
// to be in the global store when called; do so before logging out.
1000+
final newStore = eg.store(globalStore: globalStore, account: eg.selfAccount);
1001+
await logOutAccount(globalStore, eg.selfAccount.id);
1002+
completers().single.complete(newStore);
10011003
check(completers()).single.isCompleted.isTrue();
10021004
check(globalStore.takeDoRemoveAccountCalls()).single.equals(eg.selfAccount.id);
10031005

@@ -1007,26 +1009,23 @@ void main() {
10071009
async.flushTimers();
10081010
// Reload never succeeds and there are no unhandled errors.
10091011
check(globalStore.perAccountSync(eg.selfAccount.id)).isNull();
1010-
}
1011-
1012-
Future<void> logOutAndCompleteWithNewStore() async {
1013-
// [PerAccountStore.fromInitialSnapshot] requires the account
1014-
// to be in the global store when called; do so before logging out.
1015-
final newStore = eg.store(globalStore: globalStore, account: eg.selfAccount);
1016-
await logOutAccount(globalStore, eg.selfAccount.id);
1017-
completers().single.complete(newStore);
1018-
}
1019-
1020-
test('user logged out before new store is loaded', () => awaitFakeAsync((async) async {
1021-
checkReloadFailure(async, completeLoading: logOutAndCompleteWithNewStore);
10221012
}));
10231013

1024-
void completeWithApiExceptionUnauthorized() {
1014+
test('new store is not loaded, gets HTTP 401 error instead', () => awaitFakeAsync((async) async {
1015+
await prepareReload(async);
1016+
check(completers()).single.isCompleted.isFalse();
1017+
10251018
completers().single.completeError(eg.apiExceptionUnauthorized());
1026-
}
1019+
async.elapse(Duration.zero);
1020+
check(completers()).single.isCompleted.isTrue();
1021+
check(globalStore.takeDoRemoveAccountCalls()).single.equals(eg.selfAccount.id);
10271022

1028-
test('new store is not loaded, gets HTTP 401 error instead', () => awaitFakeAsync((async) async {
1029-
checkReloadFailure(async, completeLoading: completeWithApiExceptionUnauthorized);
1023+
async.elapse(TestGlobalStore.removeAccountDuration);
1024+
check(globalStore.perAccountSync(eg.selfAccount.id)).isNull();
1025+
1026+
async.flushTimers();
1027+
// Reload never succeeds and there are no unhandled errors.
1028+
check(globalStore.perAccountSync(eg.selfAccount.id)).isNull();
10301029
}));
10311030
});
10321031

0 commit comments

Comments
 (0)