Skip to content

Commit ba46924

Browse files
committed
store test: Start testing UpdateMachine.load
1 parent c6d024b commit ba46924

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

lib/model/store.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,6 @@ class UpdateMachine {
602602
/// In the future this might load an old snapshot from local storage first.
603603
static Future<UpdateMachine> load(GlobalStore globalStore, int accountId) async {
604604
final account = globalStore.getAccount(accountId)!;
605-
// TODO test UpdateMachine.load, now that it uses [GlobalStore.apiConnection]
606605
final connection = globalStore.apiConnectionFromAccount(account);
607606

608607
final stopwatch = Stopwatch()..start();

test/model/store_test.dart

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import 'package:zulip/model/store.dart';
1212
import 'package:zulip/notifications.dart';
1313

1414
import '../api/fake_api.dart';
15+
import '../api/model/model_checks.dart';
1516
import '../example_data.dart' as eg;
1617
import '../fake_async.dart';
1718
import '../stdlib_checks.dart';
@@ -135,6 +136,47 @@ void main() {
135136
});
136137
});
137138

139+
group('UpdateMachine.load', () {
140+
late TestGlobalStore globalStore;
141+
late FakeApiConnection connection;
142+
143+
Future<void> prepareStore() async {
144+
globalStore = TestGlobalStore(accounts: []);
145+
await globalStore.insertAccount(eg.selfAccount.toCompanion(false));
146+
connection = (globalStore.apiConnectionFromAccount(eg.selfAccount)
147+
as FakeApiConnection);
148+
UpdateMachine.debugEnableRegisterNotificationToken = false;
149+
addTearDown(() => UpdateMachine.debugEnableRegisterNotificationToken = true);
150+
}
151+
152+
// ignore: unused_element
153+
void checkLastRequest() {
154+
check(connection.takeLastRequest()).isA<http.Request>()
155+
..method.equals('POST')
156+
..url.path.equals('/api/v1/register');
157+
}
158+
159+
test('smoke', () => awaitFakeAsync((async) async {
160+
await prepareStore();
161+
final users = [eg.selfUser, eg.otherUser];
162+
connection.prepare(json: eg.initialSnapshot(realmUsers: users).toJson());
163+
final updateMachine = await UpdateMachine.load(
164+
globalStore, eg.selfAccount.id);
165+
updateMachine.debugPauseLoop();
166+
167+
// TODO UpdateMachine.debugPauseLoop is too late to prevent first poll attempt;
168+
// because of the polling retry, that doesn't fail the test, but
169+
// it clobbers the recorded registerQueue request so we can't check it.
170+
// checkLastRequest();
171+
172+
check(updateMachine.store.users.values).unorderedMatches(
173+
users.map((expected) => (it) => it.fullName.equals(expected.fullName)));
174+
}));
175+
176+
// TODO test UpdateMachine.load starts polling loop
177+
// TODO test UpdateMachine.load calls registerNotificationToken
178+
});
179+
138180
group('UpdateMachine.poll', () {
139181
late TestGlobalStore globalStore;
140182
late UpdateMachine updateMachine;

0 commit comments

Comments
 (0)