@@ -1019,6 +1019,55 @@ describe('message deletion', () => {
1019
1019
} ) ;
1020
1020
} ) ;
1021
1021
1022
+ describe ( 'dispatchEvent: offlineDb.executeQuerySafely' , ( ) => {
1023
+ let client ;
1024
+ let executeQuerySafelySpy ;
1025
+
1026
+ beforeEach ( async ( ) => {
1027
+ client = await getClientWithUser ( { id : 'user-abc' } ) ;
1028
+ const offlineDb = new MockOfflineDB ( { client } ) ;
1029
+ await offlineDb . init ( client . userID ) ;
1030
+ client . setOfflineDBApi ( offlineDb ) ;
1031
+
1032
+ executeQuerySafelySpy = vi . spyOn ( offlineDb , 'executeQuerySafely' ) ;
1033
+ } ) ;
1034
+
1035
+ afterEach ( ( ) => {
1036
+ vi . restoreAllMocks ( ) ;
1037
+ } ) ;
1038
+
1039
+ it ( 'should call executeQuerySafely with correct event' , ( ) => {
1040
+ const testEvent = {
1041
+ type : 'message.new' ,
1042
+ cid : 'messaging:test' ,
1043
+ } ;
1044
+
1045
+ vi . spyOn ( client . offlineDb , 'handleEvent' ) . mockResolvedValue ( { } ) ;
1046
+
1047
+ client . dispatchEvent ( testEvent ) ;
1048
+
1049
+ expect ( executeQuerySafelySpy ) . toHaveBeenCalledTimes ( 1 ) ;
1050
+ expect ( executeQuerySafelySpy ) . toHaveBeenCalledWith ( expect . any ( Function ) , {
1051
+ method : 'handleEvent;message.new' ,
1052
+ } ) ;
1053
+
1054
+ // Verify the inner function calls db.handleEvent correctly
1055
+ const fn = executeQuerySafelySpy . mock . calls [ 0 ] [ 0 ] ;
1056
+ fn ( client . offlineDb ) ;
1057
+
1058
+ expect ( client . offlineDb . handleEvent ) . toHaveBeenCalledWith ( { event : testEvent } ) ;
1059
+ } ) ;
1060
+
1061
+ it ( 'should work normally if client.offlineDb is not set' , ( ) => {
1062
+ client . offlineDb = undefined ;
1063
+
1064
+ const event = { type : 'user.updated' } ;
1065
+
1066
+ expect ( ( ) => client . dispatchEvent ( event ) ) . not . toThrow ( ) ;
1067
+ expect ( executeQuerySafelySpy ) . not . toHaveBeenCalled ( ) ;
1068
+ } ) ;
1069
+ } ) ;
1070
+
1022
1071
describe ( 'X-Stream-Client header' , ( ) => {
1023
1072
let client ;
1024
1073
0 commit comments