@@ -56,10 +56,13 @@ describe('createStorage Integration Tests', () => {
56
56
readStrategy : ReadStrategy . RemoteFirst ,
57
57
keyValueStoreRemote : remoteKeyValueStore ,
58
58
} ) ;
59
- const list = await storageApi . getConversationList ( 0 ) ;
59
+ const conversations = await storageApi . getConversationList ( 0 ) ;
60
+
61
+ expect ( conversations . length ) . toBe ( 1 ) ;
60
62
61
- expect ( list . length ) . toBe ( 1 ) ;
62
- expect ( list [ 0 ] ) . toBe ( 'bob.eth' ) ;
63
+ expect ( conversations [ 0 ] . contactEnsName ) . toBe ( 'bob.eth' ) ;
64
+ expect ( conversations [ 0 ] . isHidden ) . toBe ( false ) ;
65
+ expect ( conversations [ 0 ] . messageCounter ) . toBe ( 0 ) ;
63
66
} ) ;
64
67
it ( 'addConversation - conversationList should not contain duplicates' , async ( ) => {
65
68
await storageApi . addConversation ( 'bob.eth' ) ;
@@ -70,12 +73,17 @@ describe('createStorage Integration Tests', () => {
70
73
readStrategy : ReadStrategy . RemoteFirst ,
71
74
keyValueStoreRemote : remoteKeyValueStore ,
72
75
} ) ;
73
- const list = await storageApi . getConversationList ( 0 ) ;
76
+ const conversations = await storageApi . getConversationList ( 0 ) ;
77
+
78
+ expect ( conversations . length ) . toBe ( 2 ) ;
79
+
80
+ expect ( conversations [ 0 ] . contactEnsName ) . toBe ( 'bob.eth' ) ;
81
+ expect ( conversations [ 0 ] . isHidden ) . toBe ( false ) ;
82
+ expect ( conversations [ 0 ] . messageCounter ) . toBe ( 0 ) ;
74
83
75
- expect ( list . length ) . toBe ( 2 ) ;
76
- expect ( list [ 0 ] ) . toBe ( 'bob.eth' ) ;
77
- expect ( list [ 1 ] ) . toBe ( 'max.eth' ) ;
78
- expect ( list [ 2 ] ) . toBe ( undefined ) ;
84
+ expect ( conversations [ 1 ] . contactEnsName ) . toBe ( 'max.eth' ) ;
85
+ expect ( conversations [ 1 ] . isHidden ) . toBe ( false ) ;
86
+ expect ( conversations [ 1 ] . messageCounter ) . toBe ( 0 ) ;
79
87
} ) ;
80
88
it ( 'add new message - stores new message' , async ( ) => {
81
89
await storageApi . addConversation ( 'bob.eth' ) ;
@@ -210,12 +218,37 @@ describe('createStorage Integration Tests', () => {
210
218
211
219
const conversations = await storageApi . getConversationList ( 0 ) ;
212
220
expect ( conversations . length ) . toBe ( 1 ) ;
213
- expect ( conversations [ 0 ] ) . toBe ( 'bob.eth' ) ;
221
+ expect ( conversations [ 0 ] . contactEnsName ) . toBe ( 'bob.eth' ) ;
222
+ expect ( conversations [ 0 ] . isHidden ) . toBe ( false ) ;
223
+ expect ( conversations [ 0 ] . messageCounter ) . toBe ( 1 ) ;
214
224
215
225
const getMessages = await storageApi . getMessages ( 'bob.eth' , 0 ) ;
216
226
expect ( getMessages . length ) . toBe ( 1 ) ;
217
227
expect ( getMessages [ 0 ] ) . toEqual ( envelop ) ;
218
228
} ) ;
229
+ it ( 'hide conversation -- conversation can be hidden' , async ( ) => {
230
+ await storageApi . addConversation ( 'bob.eth' ) ;
231
+ await storageApi . addConversation ( 'max.eth' ) ;
232
+ await storageApi . toggleHideConversation ( 'max.eth' , true ) ;
233
+ //We acreate an newStorageApi to verify that the data is stored in remote storage and not just locally
234
+ storageApi = await createStorage ( 'alice.eth' , mockSign , {
235
+ readStrategy : ReadStrategy . RemoteFirst ,
236
+ keyValueStoreRemote : remoteKeyValueStore ,
237
+ } ) ;
238
+ const conversations = await storageApi . getConversationList ( 0 ) ;
239
+
240
+ expect ( conversations . length ) . toBe ( 2 ) ;
241
+ expect ( conversations [ 0 ] . isHidden ) . toBe ( false ) ;
242
+ expect ( conversations [ 1 ] . isHidden ) . toBe ( true ) ;
243
+
244
+ //Can unhide conversation aswell
245
+ await storageApi . toggleHideConversation ( 'max.eth' , false ) ;
246
+ const conversations2 = await storageApi . getConversationList ( 0 ) ;
247
+
248
+ expect ( conversations2 . length ) . toBe ( 2 ) ;
249
+ expect ( conversations2 [ 0 ] . isHidden ) . toBe ( false ) ;
250
+ expect ( conversations2 [ 1 ] . isHidden ) . toBe ( false ) ;
251
+ } ) ;
219
252
} ) ;
220
253
221
254
describe ( 'Local first' , ( ) => {
@@ -239,10 +272,13 @@ describe('createStorage Integration Tests', () => {
239
272
} ) ;
240
273
it ( 'addConversation - conversationList should include the previously added conversation' , async ( ) => {
241
274
await storageApi . addConversation ( 'bob.eth' ) ;
242
- const list = await storageApi . getConversationList ( 0 ) ;
275
+ const conversations = await storageApi . getConversationList ( 0 ) ;
243
276
244
- expect ( list . length ) . toBe ( 1 ) ;
245
- expect ( list [ 0 ] ) . toBe ( 'bob.eth' ) ;
277
+ expect ( conversations . length ) . toBe ( 1 ) ;
278
+ expect ( conversations . length ) . toBe ( 1 ) ;
279
+ expect ( conversations [ 0 ] . contactEnsName ) . toBe ( 'bob.eth' ) ;
280
+ expect ( conversations [ 0 ] . isHidden ) . toBe ( false ) ;
281
+ expect ( conversations [ 0 ] . messageCounter ) . toBe ( 0 ) ;
246
282
} ) ;
247
283
it ( 'add new message - stores new message' , async ( ) => {
248
284
await storageApi . addConversation ( 'bob.eth' ) ;
@@ -322,11 +358,32 @@ describe('createStorage Integration Tests', () => {
322
358
323
359
const conversations = await storageApi . getConversationList ( 0 ) ;
324
360
expect ( conversations . length ) . toBe ( 1 ) ;
325
- expect ( conversations [ 0 ] ) . toBe ( 'bob.eth' ) ;
361
+ expect ( conversations [ 0 ] . contactEnsName ) . toBe ( 'bob.eth' ) ;
362
+ expect ( conversations [ 0 ] . isHidden ) . toBe ( false ) ;
363
+ expect ( conversations [ 0 ] . messageCounter ) . toBe ( 1 ) ;
326
364
327
365
const getMessages = await storageApi . getMessages ( 'bob.eth' , 0 ) ;
328
366
expect ( getMessages . length ) . toBe ( 1 ) ;
329
367
expect ( getMessages [ 0 ] ) . toEqual ( envelop ) ;
330
368
} ) ;
369
+ it ( 'hide conversation -- conversation can be hidden' , async ( ) => {
370
+ await storageApi . addConversation ( 'bob.eth' ) ;
371
+ await storageApi . addConversation ( 'max.eth' ) ;
372
+ await storageApi . toggleHideConversation ( 'max.eth' , true ) ;
373
+
374
+ const conversations = await storageApi . getConversationList ( 0 ) ;
375
+
376
+ expect ( conversations . length ) . toBe ( 2 ) ;
377
+ expect ( conversations [ 0 ] . isHidden ) . toBe ( false ) ;
378
+ expect ( conversations [ 1 ] . isHidden ) . toBe ( true ) ;
379
+
380
+ //Can unhide conversation aswell
381
+ await storageApi . toggleHideConversation ( 'max.eth' , false ) ;
382
+ const conversations2 = await storageApi . getConversationList ( 0 ) ;
383
+
384
+ expect ( conversations2 . length ) . toBe ( 2 ) ;
385
+ expect ( conversations2 [ 0 ] . isHidden ) . toBe ( false ) ;
386
+ expect ( conversations2 [ 1 ] . isHidden ) . toBe ( false ) ;
387
+ } ) ;
331
388
} ) ;
332
389
} ) ;
0 commit comments