@@ -2,6 +2,7 @@ import { stringify } from '@dm3-org/dm3-lib-shared';
2
2
import { createStorage } from './index' ;
3
3
import { makeEnvelop } from './testHelper' ;
4
4
import { Chunk , Encryption , ReadStrategy , StorageAPI } from './types' ;
5
+ import { MessageState } from '@dm3-org/dm3-lib-messaging' ;
5
6
6
7
describe ( 'createStorage Integration Tests' , ( ) => {
7
8
let storageApi : StorageAPI ;
@@ -98,10 +99,15 @@ describe('createStorage Integration Tests', () => {
98
99
'Hello Bob' ,
99
100
1706084571962 ,
100
101
) ;
101
- await storageApi . addMessage ( 'bob.eth' , envelop ) ;
102
+
103
+ const storageEnvelopContainer = {
104
+ envelop,
105
+ messageState : MessageState . Created ,
106
+ } ;
107
+ await storageApi . addMessage ( 'bob.eth' , storageEnvelopContainer ) ;
102
108
const messageChunk = await storageApi . getMessages ( 'bob.eth' , 0 ) ;
103
109
expect ( messageChunk . length ) . toBe ( 1 ) ;
104
- expect ( messageChunk [ 0 ] ) . toEqual ( envelop ) ;
110
+ expect ( messageChunk [ 0 ] ) . toEqual ( storageEnvelopContainer ) ;
105
111
} ) ;
106
112
it ( 'add new message - updates number of messages' , async ( ) => {
107
113
await storageApi . addConversation ( 'bob.eth' ) ;
@@ -121,7 +127,12 @@ describe('createStorage Integration Tests', () => {
121
127
1706084571962 ,
122
128
) ;
123
129
124
- await storageApi . addMessage ( 'bob.eth' , envelop ) ;
130
+ const storageEnvelopContainer = {
131
+ envelop,
132
+ messageState : MessageState . Created ,
133
+ } ;
134
+
135
+ await storageApi . addMessage ( 'bob.eth' , storageEnvelopContainer ) ;
125
136
//We acreate an newStorageApi to verify that the data is stored in remote storage and not just locally
126
137
storageApi = await createStorage ( 'alice.eth' , mockSign , {
127
138
readStrategy : ReadStrategy . RemoteFirst ,
@@ -130,7 +141,7 @@ describe('createStorage Integration Tests', () => {
130
141
messageCounter = await storageApi . getNumberOfMessages ( 'bob.eth' ) ;
131
142
expect ( messageCounter ) . toBe ( 1 ) ;
132
143
133
- await storageApi . addMessage ( 'bob.eth' , envelop ) ;
144
+ await storageApi . addMessage ( 'bob.eth' , storageEnvelopContainer ) ;
134
145
//We acreate an newStorageApi to verify that the data is stored in remote storage and not just locally
135
146
storageApi = await createStorage ( 'alice.eth' , mockSign , {
136
147
readStrategy : ReadStrategy . RemoteFirst ,
@@ -139,7 +150,7 @@ describe('createStorage Integration Tests', () => {
139
150
messageCounter = await storageApi . getNumberOfMessages ( 'bob.eth' ) ;
140
151
expect ( messageCounter ) . toBe ( 2 ) ;
141
152
142
- await storageApi . addMessage ( 'bob.eth' , envelop ) ;
153
+ await storageApi . addMessage ( 'bob.eth' , storageEnvelopContainer ) ;
143
154
//We acreate an newStorageApi to verify that the data is stored in remote storage and not just locally
144
155
storageApi = await createStorage ( 'alice.eth' , mockSign , {
145
156
readStrategy : ReadStrategy . RemoteFirst ,
@@ -151,9 +162,9 @@ describe('createStorage Integration Tests', () => {
151
162
const messages = await storageApi . getMessages ( 'bob.eth' , 0 ) ;
152
163
expect ( messages . length ) . toBe ( 3 ) ;
153
164
154
- expect ( messages [ 0 ] ) . toEqual ( envelop ) ;
155
- expect ( messages [ 1 ] ) . toEqual ( envelop ) ;
156
- expect ( messages [ 2 ] ) . toEqual ( envelop ) ;
165
+ expect ( messages [ 0 ] ) . toEqual ( storageEnvelopContainer ) ;
166
+ expect ( messages [ 1 ] ) . toEqual ( storageEnvelopContainer ) ;
167
+ expect ( messages [ 2 ] ) . toEqual ( storageEnvelopContainer ) ;
157
168
} ) ;
158
169
it ( 'getMessages -- return [] if no converation exists' , async ( ) => {
159
170
const messages = await storageApi . getMessages ( 'bob.eth' , 0 ) ;
@@ -209,7 +220,13 @@ describe('createStorage Integration Tests', () => {
209
220
'Hello Bob' ,
210
221
1706084571962 ,
211
222
) ;
212
- await storageApi . addMessage ( 'bob.eth' , envelop ) ;
223
+
224
+ const storageEnvelopContainer = {
225
+ envelop,
226
+ messageState : MessageState . Created ,
227
+ } ;
228
+
229
+ await storageApi . addMessage ( 'bob.eth' , storageEnvelopContainer ) ;
213
230
//We acreate an newStorageApi to verify that the data is stored in remote storage and not just locally
214
231
storageApi = await createStorage ( 'alice.eth' , mockSign , {
215
232
readStrategy : ReadStrategy . RemoteFirst ,
@@ -224,7 +241,7 @@ describe('createStorage Integration Tests', () => {
224
241
225
242
const getMessages = await storageApi . getMessages ( 'bob.eth' , 0 ) ;
226
243
expect ( getMessages . length ) . toBe ( 1 ) ;
227
- expect ( getMessages [ 0 ] ) . toEqual ( envelop ) ;
244
+ expect ( getMessages [ 0 ] ) . toEqual ( storageEnvelopContainer ) ;
228
245
} ) ;
229
246
it ( 'hide conversation -- conversation can be hidden' , async ( ) => {
230
247
await storageApi . addConversation ( 'bob.eth' ) ;
@@ -288,10 +305,16 @@ describe('createStorage Integration Tests', () => {
288
305
'Hello Bob' ,
289
306
1706084571962 ,
290
307
) ;
291
- await storageApi . addMessage ( 'bob.eth' , envelop ) ;
308
+
309
+ const storageEnvelopContainer = {
310
+ envelop,
311
+ messageState : MessageState . Created ,
312
+ } ;
313
+
314
+ await storageApi . addMessage ( 'bob.eth' , storageEnvelopContainer ) ;
292
315
const messageChunk = await storageApi . getMessages ( 'bob.eth' , 0 ) ;
293
316
expect ( messageChunk . length ) . toBe ( 1 ) ;
294
- expect ( messageChunk [ 0 ] ) . toEqual ( envelop ) ;
317
+ expect ( messageChunk [ 0 ] ) . toEqual ( storageEnvelopContainer ) ;
295
318
} ) ;
296
319
it ( 'add new message - updates number of messages' , async ( ) => {
297
320
await storageApi . addConversation ( 'bob.eth' ) ;
@@ -305,25 +328,29 @@ describe('createStorage Integration Tests', () => {
305
328
'Hello Bob' ,
306
329
1706084571962 ,
307
330
) ;
331
+ const storageEnvelopContainer = {
332
+ envelop,
333
+ messageState : MessageState . Created ,
334
+ } ;
308
335
309
- await storageApi . addMessage ( 'bob.eth' , envelop ) ;
336
+ await storageApi . addMessage ( 'bob.eth' , storageEnvelopContainer ) ;
310
337
messageCounter = await storageApi . getNumberOfMessages ( 'bob.eth' ) ;
311
338
expect ( messageCounter ) . toBe ( 1 ) ;
312
339
313
- await storageApi . addMessage ( 'bob.eth' , envelop ) ;
340
+ await storageApi . addMessage ( 'bob.eth' , storageEnvelopContainer ) ;
314
341
messageCounter = await storageApi . getNumberOfMessages ( 'bob.eth' ) ;
315
342
expect ( messageCounter ) . toBe ( 2 ) ;
316
343
317
- await storageApi . addMessage ( 'bob.eth' , envelop ) ;
344
+ await storageApi . addMessage ( 'bob.eth' , storageEnvelopContainer ) ;
318
345
messageCounter = await storageApi . getNumberOfMessages ( 'bob.eth' ) ;
319
346
expect ( messageCounter ) . toBe ( 3 ) ;
320
347
321
348
const messages = await storageApi . getMessages ( 'bob.eth' , 0 ) ;
322
349
expect ( messages . length ) . toBe ( 3 ) ;
323
350
324
- expect ( messages [ 0 ] ) . toEqual ( envelop ) ;
325
- expect ( messages [ 1 ] ) . toEqual ( envelop ) ;
326
- expect ( messages [ 2 ] ) . toEqual ( envelop ) ;
351
+ expect ( messages [ 0 ] ) . toEqual ( storageEnvelopContainer ) ;
352
+ expect ( messages [ 1 ] ) . toEqual ( storageEnvelopContainer ) ;
353
+ expect ( messages [ 2 ] ) . toEqual ( storageEnvelopContainer ) ;
327
354
} ) ;
328
355
it ( 'getMessages -- return [] if no converation exists' , async ( ) => {
329
356
const messages = await storageApi . getMessages ( 'bob.eth' , 0 ) ;
@@ -354,7 +381,13 @@ describe('createStorage Integration Tests', () => {
354
381
'Hello Bob' ,
355
382
1706084571962 ,
356
383
) ;
357
- await storageApi . addMessage ( 'bob.eth' , envelop ) ;
384
+
385
+ const storageEnvelopContainer = {
386
+ envelop,
387
+ messageState : MessageState . Created ,
388
+ } ;
389
+
390
+ await storageApi . addMessage ( 'bob.eth' , storageEnvelopContainer ) ;
358
391
359
392
const conversations = await storageApi . getConversationList ( 0 ) ;
360
393
expect ( conversations . length ) . toBe ( 1 ) ;
@@ -364,7 +397,7 @@ describe('createStorage Integration Tests', () => {
364
397
365
398
const getMessages = await storageApi . getMessages ( 'bob.eth' , 0 ) ;
366
399
expect ( getMessages . length ) . toBe ( 1 ) ;
367
- expect ( getMessages [ 0 ] ) . toEqual ( envelop ) ;
400
+ expect ( getMessages [ 0 ] ) . toEqual ( storageEnvelopContainer ) ;
368
401
} ) ;
369
402
it ( 'hide conversation -- conversation can be hidden' , async ( ) => {
370
403
await storageApi . addConversation ( 'bob.eth' ) ;
0 commit comments