@@ -12,6 +12,7 @@ import 'package:zulip/model/store.dart';
1212import 'package:zulip/notifications.dart' ;
1313
1414import '../api/fake_api.dart' ;
15+ import '../api/model/model_checks.dart' ;
1516import '../example_data.dart' as eg;
1617import '../fake_async.dart' ;
1718import '../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