@@ -104,8 +104,8 @@ void _declareTests(String name, SyncOptions options) {
104104 addTearDown (status.cancel);
105105
106106 syncService.addKeepAlive ();
107- await expectLater (
108- status, emits (isSyncStatus (connected: true , hasSynced: false )));
107+ await expectLater (status,
108+ emitsThrough (isSyncStatus (connected: true , hasSynced: false )));
109109 return status;
110110 }
111111
@@ -774,6 +774,58 @@ void _declareTests(String name, SyncOptions options) {
774774 await Future <void >.delayed (const Duration (milliseconds: 500 ));
775775 expect (syncService.controller.hasListener, isTrue);
776776 });
777+
778+ test ('uploads writes made while offline' , () async {
779+ // Local write while not connected
780+ await database.execute (
781+ 'insert into customers (id, name) values (uuid(), ?)' ,
782+ ['local customer' ]);
783+ uploadData = (db) async {
784+ final batch = await db.getNextCrudTransaction ();
785+ if (batch != null ) {
786+ await batch.complete ();
787+ }
788+ };
789+ syncService.writeCheckpoint = () => {
790+ 'data' : {'write_checkpoint' : '1' }
791+ };
792+
793+ final query = StreamQueue (database
794+ .watch ('SELECT name FROM customers' )
795+ .map ((e) => e.single['name' ]));
796+ expect (await query.next, 'local customer' );
797+
798+ await waitForConnection ();
799+
800+ syncService
801+ ..addLine ({
802+ 'checkpoint' : Checkpoint (
803+ lastOpId: '1' ,
804+ writeCheckpoint: '1' ,
805+ checksums: [BucketChecksum (bucket: 'a' , priority: 3 , checksum: 0 )],
806+ )
807+ })
808+ ..addLine ({
809+ 'data' : {
810+ 'bucket' : 'a' ,
811+ 'data' : < Map <String , Object ?>> [
812+ {
813+ 'op_id' : '1' ,
814+ 'op' : 'PUT' ,
815+ 'object_type' : 'customers' ,
816+ 'object_id' : '1' ,
817+ 'checksum' : 0 ,
818+ 'data' : json.encode ({'name' : 'from server' }),
819+ }
820+ ],
821+ }
822+ })
823+ ..addLine ({
824+ 'checkpoint_complete' : {'last_op_id' : '1' }
825+ });
826+
827+ expect (await query.next, 'from server' );
828+ });
777829 });
778830}
779831
0 commit comments