@powersync/service-module-mongodb-storage 0.0.0-dev-20250818104041 → 0.0.0-dev-20250820110726
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -7
- package/dist/migrations/db/migrations/1752661449910-connection-reporting.js +48 -0
- package/dist/migrations/db/migrations/1752661449910-connection-reporting.js.map +1 -0
- package/dist/storage/MongoReportStorage.d.ts +7 -7
- package/dist/storage/MongoReportStorage.js +17 -17
- package/dist/storage/MongoReportStorage.js.map +1 -1
- package/dist/storage/implementation/MongoTestReportStorageFactoryGenerator.js +1 -1
- package/dist/storage/implementation/MongoTestReportStorageFactoryGenerator.js.map +1 -1
- package/dist/storage/implementation/db.d.ts +3 -3
- package/dist/storage/implementation/db.js +6 -6
- package/dist/storage/implementation/db.js.map +1 -1
- package/dist/storage/implementation/models.d.ts +1 -1
- package/package.json +8 -8
- package/src/migrations/db/migrations/1752661449910-connection-reporting.ts +70 -0
- package/src/storage/MongoReportStorage.ts +22 -20
- package/src/storage/implementation/MongoTestReportStorageFactoryGenerator.ts +1 -1
- package/src/storage/implementation/db.ts +7 -7
- package/src/storage/implementation/models.ts +1 -1
- package/test/src/__snapshots__/{sdk-report-storage.test.ts.snap → connection-report-storage.test.ts.snap} +32 -32
- package/test/src/__snapshots__/storage_sync.test.ts.snap +197 -0
- package/test/src/{sdk-report-storage.test.ts → connection-report-storage.test.ts} +24 -24
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/migrations/db/migrations/1752661449910-sdk-reporting.js +0 -48
- package/dist/migrations/db/migrations/1752661449910-sdk-reporting.js.map +0 -1
- package/src/migrations/db/migrations/1752661449910-sdk-reporting.ts +0 -70
- /package/dist/migrations/db/migrations/{1752661449910-sdk-reporting.d.ts → 1752661449910-connection-reporting.d.ts} +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
|
2
2
|
|
|
3
|
-
exports[`SDK reporting storage > Should create a
|
|
3
|
+
exports[`SDK reporting storage > Should create a connection report if its after a day 1`] = `
|
|
4
4
|
[
|
|
5
5
|
{
|
|
6
6
|
"client_id": "client_week",
|
|
@@ -50,7 +50,33 @@ exports[`SDK reporting storage > Should delete rows older than specified range 1
|
|
|
50
50
|
}
|
|
51
51
|
`;
|
|
52
52
|
|
|
53
|
-
exports[`SDK reporting storage > Should show
|
|
53
|
+
exports[`SDK reporting storage > Should show connected users with start range 1`] = `
|
|
54
|
+
{
|
|
55
|
+
"sdks": [
|
|
56
|
+
{
|
|
57
|
+
"clients": 1,
|
|
58
|
+
"sdk": "powersync-dart/1.6.4",
|
|
59
|
+
"users": 1,
|
|
60
|
+
},
|
|
61
|
+
],
|
|
62
|
+
"users": 1,
|
|
63
|
+
}
|
|
64
|
+
`;
|
|
65
|
+
|
|
66
|
+
exports[`SDK reporting storage > Should show connected users with start range and end range 1`] = `
|
|
67
|
+
{
|
|
68
|
+
"sdks": [
|
|
69
|
+
{
|
|
70
|
+
"clients": 1,
|
|
71
|
+
"sdk": "powersync-js/1.21.1",
|
|
72
|
+
"users": 1,
|
|
73
|
+
},
|
|
74
|
+
],
|
|
75
|
+
"users": 1,
|
|
76
|
+
}
|
|
77
|
+
`;
|
|
78
|
+
|
|
79
|
+
exports[`SDK reporting storage > Should show connection report data for user over the past day 1`] = `
|
|
54
80
|
{
|
|
55
81
|
"sdks": [
|
|
56
82
|
{
|
|
@@ -73,7 +99,7 @@ exports[`SDK reporting storage > Should show SDK scrape data for user over the p
|
|
|
73
99
|
}
|
|
74
100
|
`;
|
|
75
101
|
|
|
76
|
-
exports[`SDK reporting storage > Should show
|
|
102
|
+
exports[`SDK reporting storage > Should show connection report data for user over the past month 1`] = `
|
|
77
103
|
{
|
|
78
104
|
"sdks": [
|
|
79
105
|
{
|
|
@@ -116,7 +142,7 @@ exports[`SDK reporting storage > Should show SDK scrape data for user over the p
|
|
|
116
142
|
}
|
|
117
143
|
`;
|
|
118
144
|
|
|
119
|
-
exports[`SDK reporting storage > Should show
|
|
145
|
+
exports[`SDK reporting storage > Should show connection report data for user over the past week 1`] = `
|
|
120
146
|
{
|
|
121
147
|
"sdks": [
|
|
122
148
|
{
|
|
@@ -149,33 +175,7 @@ exports[`SDK reporting storage > Should show SDK scrape data for user over the p
|
|
|
149
175
|
}
|
|
150
176
|
`;
|
|
151
177
|
|
|
152
|
-
exports[`SDK reporting storage > Should
|
|
153
|
-
{
|
|
154
|
-
"sdks": [
|
|
155
|
-
{
|
|
156
|
-
"clients": 1,
|
|
157
|
-
"sdk": "powersync-dart/1.6.4",
|
|
158
|
-
"users": 1,
|
|
159
|
-
},
|
|
160
|
-
],
|
|
161
|
-
"users": 1,
|
|
162
|
-
}
|
|
163
|
-
`;
|
|
164
|
-
|
|
165
|
-
exports[`SDK reporting storage > Should show connected users with start range and end range 1`] = `
|
|
166
|
-
{
|
|
167
|
-
"sdks": [
|
|
168
|
-
{
|
|
169
|
-
"clients": 1,
|
|
170
|
-
"sdk": "powersync-js/1.21.1",
|
|
171
|
-
"users": 1,
|
|
172
|
-
},
|
|
173
|
-
],
|
|
174
|
-
"users": 1,
|
|
175
|
-
}
|
|
176
|
-
`;
|
|
177
|
-
|
|
178
|
-
exports[`SDK reporting storage > Should update a connected sdk event and make it disconnected 1`] = `
|
|
178
|
+
exports[`SDK reporting storage > Should update a connected connection report and make it disconnected 1`] = `
|
|
179
179
|
[
|
|
180
180
|
{
|
|
181
181
|
"client_id": "client_three",
|
|
@@ -186,7 +186,7 @@ exports[`SDK reporting storage > Should update a connected sdk event and make it
|
|
|
186
186
|
]
|
|
187
187
|
`;
|
|
188
188
|
|
|
189
|
-
exports[`SDK reporting storage > Should update a
|
|
189
|
+
exports[`SDK reporting storage > Should update a connection report if its within a day 1`] = `
|
|
190
190
|
[
|
|
191
191
|
{
|
|
192
192
|
"client_id": "client_one",
|
|
@@ -10,9 +10,21 @@ exports[`sync - mongodb > compacting data - invalidate checkpoint 1`] = `
|
|
|
10
10
|
"checksum": -93886621,
|
|
11
11
|
"count": 2,
|
|
12
12
|
"priority": 3,
|
|
13
|
+
"subscriptions": [
|
|
14
|
+
{
|
|
15
|
+
"default": 0,
|
|
16
|
+
},
|
|
17
|
+
],
|
|
13
18
|
},
|
|
14
19
|
],
|
|
15
20
|
"last_op_id": "2",
|
|
21
|
+
"streams": [
|
|
22
|
+
{
|
|
23
|
+
"errors": [],
|
|
24
|
+
"is_default": true,
|
|
25
|
+
"name": "mybucket",
|
|
26
|
+
},
|
|
27
|
+
],
|
|
16
28
|
"write_checkpoint": undefined,
|
|
17
29
|
},
|
|
18
30
|
},
|
|
@@ -46,6 +58,11 @@ exports[`sync - mongodb > compacting data - invalidate checkpoint 2`] = `
|
|
|
46
58
|
"checksum": 499012468,
|
|
47
59
|
"count": 4,
|
|
48
60
|
"priority": 3,
|
|
61
|
+
"subscriptions": [
|
|
62
|
+
{
|
|
63
|
+
"default": 0,
|
|
64
|
+
},
|
|
65
|
+
],
|
|
49
66
|
},
|
|
50
67
|
],
|
|
51
68
|
"write_checkpoint": undefined,
|
|
@@ -105,9 +122,21 @@ exports[`sync - mongodb > expiring token 1`] = `
|
|
|
105
122
|
"checksum": 0,
|
|
106
123
|
"count": 0,
|
|
107
124
|
"priority": 3,
|
|
125
|
+
"subscriptions": [
|
|
126
|
+
{
|
|
127
|
+
"default": 0,
|
|
128
|
+
},
|
|
129
|
+
],
|
|
108
130
|
},
|
|
109
131
|
],
|
|
110
132
|
"last_op_id": "0",
|
|
133
|
+
"streams": [
|
|
134
|
+
{
|
|
135
|
+
"errors": [],
|
|
136
|
+
"is_default": true,
|
|
137
|
+
"name": "mybucket",
|
|
138
|
+
},
|
|
139
|
+
],
|
|
111
140
|
"write_checkpoint": undefined,
|
|
112
141
|
},
|
|
113
142
|
},
|
|
@@ -137,9 +166,21 @@ exports[`sync - mongodb > sends checkpoint complete line for empty checkpoint 1`
|
|
|
137
166
|
"checksum": -1221282404,
|
|
138
167
|
"count": 1,
|
|
139
168
|
"priority": 3,
|
|
169
|
+
"subscriptions": [
|
|
170
|
+
{
|
|
171
|
+
"default": 0,
|
|
172
|
+
},
|
|
173
|
+
],
|
|
140
174
|
},
|
|
141
175
|
],
|
|
142
176
|
"last_op_id": "1",
|
|
177
|
+
"streams": [
|
|
178
|
+
{
|
|
179
|
+
"errors": [],
|
|
180
|
+
"is_default": true,
|
|
181
|
+
"name": "mybucket",
|
|
182
|
+
},
|
|
183
|
+
],
|
|
143
184
|
"write_checkpoint": undefined,
|
|
144
185
|
},
|
|
145
186
|
},
|
|
@@ -193,15 +234,37 @@ exports[`sync - mongodb > sync buckets in order 1`] = `
|
|
|
193
234
|
"checksum": 920318466,
|
|
194
235
|
"count": 1,
|
|
195
236
|
"priority": 2,
|
|
237
|
+
"subscriptions": [
|
|
238
|
+
{
|
|
239
|
+
"default": 0,
|
|
240
|
+
},
|
|
241
|
+
],
|
|
196
242
|
},
|
|
197
243
|
{
|
|
198
244
|
"bucket": "b1[]",
|
|
199
245
|
"checksum": -1382098757,
|
|
200
246
|
"count": 1,
|
|
201
247
|
"priority": 1,
|
|
248
|
+
"subscriptions": [
|
|
249
|
+
{
|
|
250
|
+
"default": 1,
|
|
251
|
+
},
|
|
252
|
+
],
|
|
202
253
|
},
|
|
203
254
|
],
|
|
204
255
|
"last_op_id": "2",
|
|
256
|
+
"streams": [
|
|
257
|
+
{
|
|
258
|
+
"errors": [],
|
|
259
|
+
"is_default": true,
|
|
260
|
+
"name": "b0",
|
|
261
|
+
},
|
|
262
|
+
{
|
|
263
|
+
"errors": [],
|
|
264
|
+
"is_default": true,
|
|
265
|
+
"name": "b1",
|
|
266
|
+
},
|
|
267
|
+
],
|
|
205
268
|
"write_checkpoint": undefined,
|
|
206
269
|
},
|
|
207
270
|
},
|
|
@@ -267,9 +330,21 @@ exports[`sync - mongodb > sync global data 1`] = `
|
|
|
267
330
|
"checksum": -93886621,
|
|
268
331
|
"count": 2,
|
|
269
332
|
"priority": 3,
|
|
333
|
+
"subscriptions": [
|
|
334
|
+
{
|
|
335
|
+
"default": 0,
|
|
336
|
+
},
|
|
337
|
+
],
|
|
270
338
|
},
|
|
271
339
|
],
|
|
272
340
|
"last_op_id": "2",
|
|
341
|
+
"streams": [
|
|
342
|
+
{
|
|
343
|
+
"errors": [],
|
|
344
|
+
"is_default": true,
|
|
345
|
+
"name": "mybucket",
|
|
346
|
+
},
|
|
347
|
+
],
|
|
273
348
|
"write_checkpoint": undefined,
|
|
274
349
|
},
|
|
275
350
|
},
|
|
@@ -319,21 +394,53 @@ exports[`sync - mongodb > sync interrupts low-priority buckets on new checkpoint
|
|
|
319
394
|
"checksum": -659831575,
|
|
320
395
|
"count": 2000,
|
|
321
396
|
"priority": 2,
|
|
397
|
+
"subscriptions": [
|
|
398
|
+
{
|
|
399
|
+
"default": 0,
|
|
400
|
+
},
|
|
401
|
+
],
|
|
322
402
|
},
|
|
323
403
|
{
|
|
324
404
|
"bucket": "b0b[]",
|
|
325
405
|
"checksum": -659831575,
|
|
326
406
|
"count": 2000,
|
|
327
407
|
"priority": 2,
|
|
408
|
+
"subscriptions": [
|
|
409
|
+
{
|
|
410
|
+
"default": 1,
|
|
411
|
+
},
|
|
412
|
+
],
|
|
328
413
|
},
|
|
329
414
|
{
|
|
330
415
|
"bucket": "b1[]",
|
|
331
416
|
"checksum": -1096116670,
|
|
332
417
|
"count": 1,
|
|
333
418
|
"priority": 1,
|
|
419
|
+
"subscriptions": [
|
|
420
|
+
{
|
|
421
|
+
"default": 2,
|
|
422
|
+
},
|
|
423
|
+
],
|
|
334
424
|
},
|
|
335
425
|
],
|
|
336
426
|
"last_op_id": "4001",
|
|
427
|
+
"streams": [
|
|
428
|
+
{
|
|
429
|
+
"errors": [],
|
|
430
|
+
"is_default": true,
|
|
431
|
+
"name": "b0a",
|
|
432
|
+
},
|
|
433
|
+
{
|
|
434
|
+
"errors": [],
|
|
435
|
+
"is_default": true,
|
|
436
|
+
"name": "b0b",
|
|
437
|
+
},
|
|
438
|
+
{
|
|
439
|
+
"errors": [],
|
|
440
|
+
"is_default": true,
|
|
441
|
+
"name": "b1",
|
|
442
|
+
},
|
|
443
|
+
],
|
|
337
444
|
"write_checkpoint": undefined,
|
|
338
445
|
},
|
|
339
446
|
},
|
|
@@ -380,18 +487,33 @@ exports[`sync - mongodb > sync interrupts low-priority buckets on new checkpoint
|
|
|
380
487
|
"checksum": 883076828,
|
|
381
488
|
"count": 2001,
|
|
382
489
|
"priority": 2,
|
|
490
|
+
"subscriptions": [
|
|
491
|
+
{
|
|
492
|
+
"default": 0,
|
|
493
|
+
},
|
|
494
|
+
],
|
|
383
495
|
},
|
|
384
496
|
{
|
|
385
497
|
"bucket": "b0b[]",
|
|
386
498
|
"checksum": 883076828,
|
|
387
499
|
"count": 2001,
|
|
388
500
|
"priority": 2,
|
|
501
|
+
"subscriptions": [
|
|
502
|
+
{
|
|
503
|
+
"default": 1,
|
|
504
|
+
},
|
|
505
|
+
],
|
|
389
506
|
},
|
|
390
507
|
{
|
|
391
508
|
"bucket": "b1[]",
|
|
392
509
|
"checksum": 1841937527,
|
|
393
510
|
"count": 2,
|
|
394
511
|
"priority": 1,
|
|
512
|
+
"subscriptions": [
|
|
513
|
+
{
|
|
514
|
+
"default": 2,
|
|
515
|
+
},
|
|
516
|
+
],
|
|
395
517
|
},
|
|
396
518
|
],
|
|
397
519
|
"write_checkpoint": undefined,
|
|
@@ -466,9 +588,21 @@ exports[`sync - mongodb > sync legacy non-raw data 1`] = `
|
|
|
466
588
|
"checksum": -852817836,
|
|
467
589
|
"count": 1,
|
|
468
590
|
"priority": 3,
|
|
591
|
+
"subscriptions": [
|
|
592
|
+
{
|
|
593
|
+
"default": 0,
|
|
594
|
+
},
|
|
595
|
+
],
|
|
469
596
|
},
|
|
470
597
|
],
|
|
471
598
|
"last_op_id": "1",
|
|
599
|
+
"streams": [
|
|
600
|
+
{
|
|
601
|
+
"errors": [],
|
|
602
|
+
"is_default": true,
|
|
603
|
+
"name": "mybucket",
|
|
604
|
+
},
|
|
605
|
+
],
|
|
472
606
|
"write_checkpoint": undefined,
|
|
473
607
|
},
|
|
474
608
|
},
|
|
@@ -514,9 +648,21 @@ exports[`sync - mongodb > sync updates to data query only 1`] = `
|
|
|
514
648
|
"checksum": 0,
|
|
515
649
|
"count": 0,
|
|
516
650
|
"priority": 3,
|
|
651
|
+
"subscriptions": [
|
|
652
|
+
{
|
|
653
|
+
"default": 0,
|
|
654
|
+
},
|
|
655
|
+
],
|
|
517
656
|
},
|
|
518
657
|
],
|
|
519
658
|
"last_op_id": "1",
|
|
659
|
+
"streams": [
|
|
660
|
+
{
|
|
661
|
+
"errors": [],
|
|
662
|
+
"is_default": true,
|
|
663
|
+
"name": "by_user",
|
|
664
|
+
},
|
|
665
|
+
],
|
|
520
666
|
"write_checkpoint": undefined,
|
|
521
667
|
},
|
|
522
668
|
},
|
|
@@ -540,6 +686,11 @@ exports[`sync - mongodb > sync updates to data query only 2`] = `
|
|
|
540
686
|
"checksum": 1418351250,
|
|
541
687
|
"count": 1,
|
|
542
688
|
"priority": 3,
|
|
689
|
+
"subscriptions": [
|
|
690
|
+
{
|
|
691
|
+
"default": 0,
|
|
692
|
+
},
|
|
693
|
+
],
|
|
543
694
|
},
|
|
544
695
|
],
|
|
545
696
|
"write_checkpoint": undefined,
|
|
@@ -582,9 +733,21 @@ exports[`sync - mongodb > sync updates to global data 1`] = `
|
|
|
582
733
|
"checksum": 0,
|
|
583
734
|
"count": 0,
|
|
584
735
|
"priority": 3,
|
|
736
|
+
"subscriptions": [
|
|
737
|
+
{
|
|
738
|
+
"default": 0,
|
|
739
|
+
},
|
|
740
|
+
],
|
|
585
741
|
},
|
|
586
742
|
],
|
|
587
743
|
"last_op_id": "0",
|
|
744
|
+
"streams": [
|
|
745
|
+
{
|
|
746
|
+
"errors": [],
|
|
747
|
+
"is_default": true,
|
|
748
|
+
"name": "mybucket",
|
|
749
|
+
},
|
|
750
|
+
],
|
|
588
751
|
"write_checkpoint": undefined,
|
|
589
752
|
},
|
|
590
753
|
},
|
|
@@ -608,6 +771,11 @@ exports[`sync - mongodb > sync updates to global data 2`] = `
|
|
|
608
771
|
"checksum": 920318466,
|
|
609
772
|
"count": 1,
|
|
610
773
|
"priority": 3,
|
|
774
|
+
"subscriptions": [
|
|
775
|
+
{
|
|
776
|
+
"default": 0,
|
|
777
|
+
},
|
|
778
|
+
],
|
|
611
779
|
},
|
|
612
780
|
],
|
|
613
781
|
"write_checkpoint": undefined,
|
|
@@ -652,6 +820,11 @@ exports[`sync - mongodb > sync updates to global data 3`] = `
|
|
|
652
820
|
"checksum": -93886621,
|
|
653
821
|
"count": 2,
|
|
654
822
|
"priority": 3,
|
|
823
|
+
"subscriptions": [
|
|
824
|
+
{
|
|
825
|
+
"default": 0,
|
|
826
|
+
},
|
|
827
|
+
],
|
|
655
828
|
},
|
|
656
829
|
],
|
|
657
830
|
"write_checkpoint": undefined,
|
|
@@ -690,6 +863,13 @@ exports[`sync - mongodb > sync updates to parameter query + data 1`] = `
|
|
|
690
863
|
"checkpoint": {
|
|
691
864
|
"buckets": [],
|
|
692
865
|
"last_op_id": "0",
|
|
866
|
+
"streams": [
|
|
867
|
+
{
|
|
868
|
+
"errors": [],
|
|
869
|
+
"is_default": true,
|
|
870
|
+
"name": "by_user",
|
|
871
|
+
},
|
|
872
|
+
],
|
|
693
873
|
"write_checkpoint": undefined,
|
|
694
874
|
},
|
|
695
875
|
},
|
|
@@ -713,6 +893,11 @@ exports[`sync - mongodb > sync updates to parameter query + data 2`] = `
|
|
|
713
893
|
"checksum": 1418351250,
|
|
714
894
|
"count": 1,
|
|
715
895
|
"priority": 3,
|
|
896
|
+
"subscriptions": [
|
|
897
|
+
{
|
|
898
|
+
"default": 0,
|
|
899
|
+
},
|
|
900
|
+
],
|
|
716
901
|
},
|
|
717
902
|
],
|
|
718
903
|
"write_checkpoint": undefined,
|
|
@@ -751,6 +936,13 @@ exports[`sync - mongodb > sync updates to parameter query only 1`] = `
|
|
|
751
936
|
"checkpoint": {
|
|
752
937
|
"buckets": [],
|
|
753
938
|
"last_op_id": "0",
|
|
939
|
+
"streams": [
|
|
940
|
+
{
|
|
941
|
+
"errors": [],
|
|
942
|
+
"is_default": true,
|
|
943
|
+
"name": "by_user",
|
|
944
|
+
},
|
|
945
|
+
],
|
|
754
946
|
"write_checkpoint": undefined,
|
|
755
947
|
},
|
|
756
948
|
},
|
|
@@ -774,6 +966,11 @@ exports[`sync - mongodb > sync updates to parameter query only 2`] = `
|
|
|
774
966
|
"checksum": 0,
|
|
775
967
|
"count": 0,
|
|
776
968
|
"priority": 3,
|
|
969
|
+
"subscriptions": [
|
|
970
|
+
{
|
|
971
|
+
"default": 0,
|
|
972
|
+
},
|
|
973
|
+
],
|
|
777
974
|
},
|
|
778
975
|
],
|
|
779
976
|
"write_checkpoint": undefined,
|
|
@@ -3,9 +3,9 @@ import { INITIALIZED_MONGO_REPORT_STORAGE_FACTORY } from './util.js';
|
|
|
3
3
|
import { event_types } from '@powersync/service-types';
|
|
4
4
|
|
|
5
5
|
function removeVolatileFields(
|
|
6
|
-
sdks: event_types.
|
|
7
|
-
): Partial<event_types.
|
|
8
|
-
return sdks.map((sdk: Partial<event_types.
|
|
6
|
+
sdks: event_types.ClientConnection[]
|
|
7
|
+
): Partial<event_types.ClientConnection & { _id: string }>[] {
|
|
8
|
+
return sdks.map((sdk: Partial<event_types.ClientConnection & { _id: string }>) => {
|
|
9
9
|
const { _id, disconnected_at, connected_at, jwt_exp, ...rest } = sdk;
|
|
10
10
|
return {
|
|
11
11
|
...rest
|
|
@@ -96,7 +96,7 @@ describe('SDK reporting storage', async () => {
|
|
|
96
96
|
};
|
|
97
97
|
|
|
98
98
|
async function loadData() {
|
|
99
|
-
await factory.db.
|
|
99
|
+
await factory.db.connection_report_events.insertMany([
|
|
100
100
|
user_one,
|
|
101
101
|
user_two,
|
|
102
102
|
user_three,
|
|
@@ -108,7 +108,7 @@ describe('SDK reporting storage', async () => {
|
|
|
108
108
|
}
|
|
109
109
|
|
|
110
110
|
function deleteData() {
|
|
111
|
-
return factory.db.
|
|
111
|
+
return factory.db.connection_report_events.deleteMany();
|
|
112
112
|
}
|
|
113
113
|
|
|
114
114
|
beforeAll(async () => {
|
|
@@ -119,7 +119,7 @@ describe('SDK reporting storage', async () => {
|
|
|
119
119
|
await deleteData();
|
|
120
120
|
});
|
|
121
121
|
it('Should show connected users with start range', async () => {
|
|
122
|
-
const current = await factory.
|
|
122
|
+
const current = await factory.getConnectedClients({
|
|
123
123
|
range: {
|
|
124
124
|
start: new Date(
|
|
125
125
|
now.getFullYear(),
|
|
@@ -133,7 +133,7 @@ describe('SDK reporting storage', async () => {
|
|
|
133
133
|
expect(current).toMatchSnapshot();
|
|
134
134
|
});
|
|
135
135
|
it('Should show connected users with start range and end range', async () => {
|
|
136
|
-
const current = await factory.
|
|
136
|
+
const current = await factory.getConnectedClients({
|
|
137
137
|
range: {
|
|
138
138
|
end: nowLess5minutes.toISOString(),
|
|
139
139
|
start: new Date(
|
|
@@ -147,29 +147,29 @@ describe('SDK reporting storage', async () => {
|
|
|
147
147
|
});
|
|
148
148
|
expect(current).toMatchSnapshot();
|
|
149
149
|
});
|
|
150
|
-
it('Should show
|
|
151
|
-
const sdk = await factory.
|
|
150
|
+
it('Should show connection report data for user over the past month', async () => {
|
|
151
|
+
const sdk = await factory.getClientConnectionReports({
|
|
152
152
|
start: monthAgo,
|
|
153
153
|
end: now
|
|
154
154
|
});
|
|
155
155
|
expect(sdk).toMatchSnapshot();
|
|
156
156
|
});
|
|
157
|
-
it('Should show
|
|
158
|
-
const sdk = await factory.
|
|
157
|
+
it('Should show connection report data for user over the past week', async () => {
|
|
158
|
+
const sdk = await factory.getClientConnectionReports({
|
|
159
159
|
start: weekAgo,
|
|
160
160
|
end: now
|
|
161
161
|
});
|
|
162
162
|
expect(sdk).toMatchSnapshot();
|
|
163
163
|
});
|
|
164
|
-
it('Should show
|
|
165
|
-
const sdk = await factory.
|
|
164
|
+
it('Should show connection report data for user over the past day', async () => {
|
|
165
|
+
const sdk = await factory.getClientConnectionReports({
|
|
166
166
|
start: dayAgo,
|
|
167
167
|
end: now
|
|
168
168
|
});
|
|
169
169
|
expect(sdk).toMatchSnapshot();
|
|
170
170
|
});
|
|
171
171
|
|
|
172
|
-
it('Should update a
|
|
172
|
+
it('Should update a connection report if its within a day', async () => {
|
|
173
173
|
const newConnectAt = new Date(
|
|
174
174
|
now.getFullYear(),
|
|
175
175
|
now.getMonth(),
|
|
@@ -178,7 +178,7 @@ describe('SDK reporting storage', async () => {
|
|
|
178
178
|
now.getMinutes() + 20
|
|
179
179
|
);
|
|
180
180
|
const jwtExp = new Date(newConnectAt.getFullYear(), newConnectAt.getMonth(), newConnectAt.getDate() + 1);
|
|
181
|
-
await factory.
|
|
181
|
+
await factory.reportClientConnection({
|
|
182
182
|
sdk: user_one.sdk,
|
|
183
183
|
connected_at: newConnectAt,
|
|
184
184
|
jwt_exp: jwtExp,
|
|
@@ -187,7 +187,7 @@ describe('SDK reporting storage', async () => {
|
|
|
187
187
|
user_agent: user_one.user_agent
|
|
188
188
|
});
|
|
189
189
|
|
|
190
|
-
const sdk = await factory.db.
|
|
190
|
+
const sdk = await factory.db.connection_report_events.find({ user_id: user_one.user_id }).toArray();
|
|
191
191
|
expect(sdk).toHaveLength(1);
|
|
192
192
|
expect(new Date(sdk[0].connected_at)).toEqual(newConnectAt);
|
|
193
193
|
expect(new Date(sdk[0].jwt_exp!)).toEqual(jwtExp);
|
|
@@ -196,7 +196,7 @@ describe('SDK reporting storage', async () => {
|
|
|
196
196
|
expect(cleaned).toMatchSnapshot();
|
|
197
197
|
});
|
|
198
198
|
|
|
199
|
-
it('Should update a connected
|
|
199
|
+
it('Should update a connected connection report and make it disconnected', async () => {
|
|
200
200
|
const disconnectAt = new Date(
|
|
201
201
|
now.getFullYear(),
|
|
202
202
|
now.getMonth(),
|
|
@@ -206,7 +206,7 @@ describe('SDK reporting storage', async () => {
|
|
|
206
206
|
);
|
|
207
207
|
const jwtExp = new Date(disconnectAt.getFullYear(), disconnectAt.getMonth(), disconnectAt.getDate() + 1);
|
|
208
208
|
|
|
209
|
-
await factory.
|
|
209
|
+
await factory.reportClientDisconnection({
|
|
210
210
|
disconnected_at: disconnectAt,
|
|
211
211
|
jwt_exp: jwtExp,
|
|
212
212
|
client_id: user_three.client_id,
|
|
@@ -215,18 +215,18 @@ describe('SDK reporting storage', async () => {
|
|
|
215
215
|
connected_at: user_three.connected_at
|
|
216
216
|
});
|
|
217
217
|
|
|
218
|
-
const sdk = await factory.db.
|
|
218
|
+
const sdk = await factory.db.connection_report_events.find({ user_id: user_three.user_id }).toArray();
|
|
219
219
|
expect(sdk).toHaveLength(1);
|
|
220
220
|
expect(new Date(sdk[0].disconnected_at!)).toEqual(disconnectAt);
|
|
221
221
|
const cleaned = removeVolatileFields(sdk);
|
|
222
222
|
expect(cleaned).toMatchSnapshot();
|
|
223
223
|
});
|
|
224
224
|
|
|
225
|
-
it('Should create a
|
|
225
|
+
it('Should create a connection report if its after a day', async () => {
|
|
226
226
|
const newConnectAt = new Date(now.getFullYear(), now.getMonth(), now.getDate() + 1, now.getHours());
|
|
227
227
|
const jwtExp = new Date(newConnectAt.getFullYear(), newConnectAt.getMonth(), newConnectAt.getDate() + 1);
|
|
228
228
|
|
|
229
|
-
await factory.
|
|
229
|
+
await factory.reportClientConnection({
|
|
230
230
|
sdk: user_week.sdk,
|
|
231
231
|
connected_at: newConnectAt,
|
|
232
232
|
jwt_exp: jwtExp,
|
|
@@ -235,7 +235,7 @@ describe('SDK reporting storage', async () => {
|
|
|
235
235
|
user_agent: user_week.user_agent
|
|
236
236
|
});
|
|
237
237
|
|
|
238
|
-
const sdk = await factory.db.
|
|
238
|
+
const sdk = await factory.db.connection_report_events.find({ user_id: user_week.user_id }).toArray();
|
|
239
239
|
expect(sdk).toHaveLength(2);
|
|
240
240
|
const cleaned = removeVolatileFields(sdk);
|
|
241
241
|
expect(cleaned).toMatchSnapshot();
|
|
@@ -244,10 +244,10 @@ describe('SDK reporting storage', async () => {
|
|
|
244
244
|
it('Should delete rows older than specified range', async () => {
|
|
245
245
|
await deleteData();
|
|
246
246
|
await loadData();
|
|
247
|
-
await factory.
|
|
247
|
+
await factory.deleteOldConnectionData({
|
|
248
248
|
date: weekAgo
|
|
249
249
|
});
|
|
250
|
-
const sdk = await factory.
|
|
250
|
+
const sdk = await factory.getClientConnectionReports({
|
|
251
251
|
start: monthAgo,
|
|
252
252
|
end: now
|
|
253
253
|
});
|