@powersync/service-module-postgres-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 +10 -9
- package/dist/.tsbuildinfo +1 -1
- package/dist/@types/storage/PostgresReportStorageFactory.d.ts +6 -6
- package/dist/migrations/scripts/1684951997326-init.js +7 -5
- package/dist/migrations/scripts/1684951997326-init.js.map +1 -1
- package/dist/storage/PostgresReportStorageFactory.js +13 -13
- package/dist/storage/PostgresReportStorageFactory.js.map +1 -1
- package/dist/utils/db.js +1 -1
- package/dist/utils/db.js.map +1 -1
- package/package.json +10 -10
- package/src/migrations/scripts/1684951997326-init.ts +7 -5
- package/src/storage/PostgresReportStorageFactory.ts +17 -23
- package/src/utils/db.ts +1 -1
- package/test/src/__snapshots__/{sdk-report-storage.test.ts.snap → connection-report-storage.test.ts.snap} +70 -31
- package/test/src/__snapshots__/storage_sync.test.ts.snap +197 -0
- package/test/src/{sdk-report-storage.test.ts → connection-report-storage.test.ts} +23 -23
|
@@ -10,9 +10,21 @@ exports[`sync - postgres > 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 - postgres > 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 - postgres > 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 - postgres > 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 - postgres > 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 - postgres > 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 - postgres > sync interrupts low-priority buckets on new checkpoin
|
|
|
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 - postgres > sync interrupts low-priority buckets on new checkpoin
|
|
|
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 - postgres > 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 - postgres > 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 - postgres > 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 - postgres > 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 - postgres > 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 - postgres > 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 - postgres > 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 - postgres > 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 - postgres > 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 - postgres > 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,
|
|
@@ -2,7 +2,7 @@ import { afterAll, beforeAll, describe, expect, it } from 'vitest';
|
|
|
2
2
|
import { POSTGRES_REPORT_STORAGE_FACTORY } from './util.js';
|
|
3
3
|
import { event_types } from '@powersync/service-types';
|
|
4
4
|
|
|
5
|
-
function removeVolatileFields(sdks: event_types.
|
|
5
|
+
function removeVolatileFields(sdks: event_types.ClientConnection[]): Partial<event_types.ClientConnection>[] {
|
|
6
6
|
return sdks.map((sdk) => {
|
|
7
7
|
const { id, disconnected_at, connected_at, jwt_exp, ...rest } = sdk;
|
|
8
8
|
return {
|
|
@@ -11,7 +11,7 @@ function removeVolatileFields(sdks: event_types.SdkConnection[]): Partial<event_
|
|
|
11
11
|
});
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
describe('
|
|
14
|
+
describe('Connection report storage', async () => {
|
|
15
15
|
const factory = await POSTGRES_REPORT_STORAGE_FACTORY();
|
|
16
16
|
const now = new Date();
|
|
17
17
|
const nowAdd5minutes = new Date(
|
|
@@ -103,7 +103,7 @@ describe('SDK reporting storage', async () => {
|
|
|
103
103
|
async function loadData() {
|
|
104
104
|
await factory.db.sql`
|
|
105
105
|
INSERT INTO
|
|
106
|
-
|
|
106
|
+
connection_report_events (
|
|
107
107
|
user_id,
|
|
108
108
|
client_id,
|
|
109
109
|
connected_at,
|
|
@@ -188,7 +188,7 @@ describe('SDK reporting storage', async () => {
|
|
|
188
188
|
}
|
|
189
189
|
|
|
190
190
|
function deleteData() {
|
|
191
|
-
return factory.db.sql`TRUNCATE TABLE
|
|
191
|
+
return factory.db.sql`TRUNCATE TABLE connection_report_events`.execute();
|
|
192
192
|
}
|
|
193
193
|
|
|
194
194
|
beforeAll(async () => {
|
|
@@ -199,7 +199,7 @@ describe('SDK reporting storage', async () => {
|
|
|
199
199
|
await deleteData();
|
|
200
200
|
});
|
|
201
201
|
it('Should show connected users with start range', async () => {
|
|
202
|
-
const current = await factory.
|
|
202
|
+
const current = await factory.getConnectedClients({
|
|
203
203
|
range: {
|
|
204
204
|
start: new Date(
|
|
205
205
|
now.getFullYear(),
|
|
@@ -213,7 +213,7 @@ describe('SDK reporting storage', async () => {
|
|
|
213
213
|
expect(current).toMatchSnapshot();
|
|
214
214
|
});
|
|
215
215
|
it('Should show connected users with start range and end range', async () => {
|
|
216
|
-
const current = await factory.
|
|
216
|
+
const current = await factory.getConnectedClients({
|
|
217
217
|
range: {
|
|
218
218
|
end: nowLess5minutes.toISOString(),
|
|
219
219
|
start: new Date(
|
|
@@ -227,29 +227,29 @@ describe('SDK reporting storage', async () => {
|
|
|
227
227
|
});
|
|
228
228
|
expect(current).toMatchSnapshot();
|
|
229
229
|
});
|
|
230
|
-
it('Should show
|
|
231
|
-
const sdk = await factory.
|
|
230
|
+
it('Should show connection report data for user over the past month', async () => {
|
|
231
|
+
const sdk = await factory.getClientConnectionReports({
|
|
232
232
|
start: monthAgo,
|
|
233
233
|
end: now
|
|
234
234
|
});
|
|
235
235
|
expect(sdk).toMatchSnapshot();
|
|
236
236
|
});
|
|
237
|
-
it('Should show
|
|
238
|
-
const sdk = await factory.
|
|
237
|
+
it('Should show connection report data for user over the past week', async () => {
|
|
238
|
+
const sdk = await factory.getClientConnectionReports({
|
|
239
239
|
start: weekAgo,
|
|
240
240
|
end: now
|
|
241
241
|
});
|
|
242
242
|
expect(sdk).toMatchSnapshot();
|
|
243
243
|
});
|
|
244
|
-
it('Should show
|
|
245
|
-
const sdk = await factory.
|
|
244
|
+
it('Should show connection report data for user over the past day', async () => {
|
|
245
|
+
const sdk = await factory.getClientConnectionReports({
|
|
246
246
|
start: dayAgo,
|
|
247
247
|
end: now
|
|
248
248
|
});
|
|
249
249
|
expect(sdk).toMatchSnapshot();
|
|
250
250
|
});
|
|
251
251
|
|
|
252
|
-
it('Should update a
|
|
252
|
+
it('Should update a connection event if its within a day', async () => {
|
|
253
253
|
const newConnectAt = new Date(
|
|
254
254
|
now.getFullYear(),
|
|
255
255
|
now.getMonth(),
|
|
@@ -258,7 +258,7 @@ describe('SDK reporting storage', async () => {
|
|
|
258
258
|
now.getMinutes() + 20
|
|
259
259
|
);
|
|
260
260
|
const jwtExp = new Date(newConnectAt.getFullYear(), newConnectAt.getMonth(), newConnectAt.getDate() + 1);
|
|
261
|
-
await factory.
|
|
261
|
+
await factory.reportClientConnection({
|
|
262
262
|
sdk: user_one.sdk,
|
|
263
263
|
connected_at: newConnectAt,
|
|
264
264
|
jwt_exp: jwtExp,
|
|
@@ -268,7 +268,7 @@ describe('SDK reporting storage', async () => {
|
|
|
268
268
|
});
|
|
269
269
|
|
|
270
270
|
const sdk = await factory.db
|
|
271
|
-
.sql`SELECT * FROM
|
|
271
|
+
.sql`SELECT * FROM connection_report_events WHERE user_id = ${{ type: 'varchar', value: user_one.user_id }}`.rows<event_types.ClientConnection>();
|
|
272
272
|
expect(sdk).toHaveLength(1);
|
|
273
273
|
expect(new Date(sdk[0].connected_at).toISOString()).toEqual(newConnectAt.toISOString());
|
|
274
274
|
expect(new Date(sdk[0].jwt_exp!).toISOString()).toEqual(jwtExp.toISOString());
|
|
@@ -277,7 +277,7 @@ describe('SDK reporting storage', async () => {
|
|
|
277
277
|
expect(cleaned).toMatchSnapshot();
|
|
278
278
|
});
|
|
279
279
|
|
|
280
|
-
it('Should update a
|
|
280
|
+
it('Should update a connection event and make it disconnected', async () => {
|
|
281
281
|
const disconnectAt = new Date(
|
|
282
282
|
now.getFullYear(),
|
|
283
283
|
now.getMonth(),
|
|
@@ -287,7 +287,7 @@ describe('SDK reporting storage', async () => {
|
|
|
287
287
|
);
|
|
288
288
|
const jwtExp = new Date(disconnectAt.getFullYear(), disconnectAt.getMonth(), disconnectAt.getDate() + 1);
|
|
289
289
|
|
|
290
|
-
await factory.
|
|
290
|
+
await factory.reportClientDisconnection({
|
|
291
291
|
disconnected_at: disconnectAt,
|
|
292
292
|
jwt_exp: jwtExp,
|
|
293
293
|
client_id: user_three.client_id,
|
|
@@ -297,18 +297,18 @@ describe('SDK reporting storage', async () => {
|
|
|
297
297
|
});
|
|
298
298
|
|
|
299
299
|
const sdk = await factory.db
|
|
300
|
-
.sql`SELECT * FROM
|
|
300
|
+
.sql`SELECT * FROM connection_report_events WHERE user_id = ${{ type: 'varchar', value: user_three.user_id }}`.rows<event_types.ClientConnection>();
|
|
301
301
|
expect(sdk).toHaveLength(1);
|
|
302
302
|
expect(new Date(sdk[0].disconnected_at!).toISOString()).toEqual(disconnectAt.toISOString());
|
|
303
303
|
const cleaned = removeVolatileFields(sdk);
|
|
304
304
|
expect(cleaned).toMatchSnapshot();
|
|
305
305
|
});
|
|
306
306
|
|
|
307
|
-
it('Should create a
|
|
307
|
+
it('Should create a connection event if its after a day', async () => {
|
|
308
308
|
const newConnectAt = new Date(now.getFullYear(), now.getMonth(), now.getDate() + 1, now.getHours());
|
|
309
309
|
const jwtExp = new Date(newConnectAt.getFullYear(), newConnectAt.getMonth(), newConnectAt.getDate() + 1);
|
|
310
310
|
|
|
311
|
-
await factory.
|
|
311
|
+
await factory.reportClientConnection({
|
|
312
312
|
sdk: user_week.sdk,
|
|
313
313
|
connected_at: newConnectAt,
|
|
314
314
|
jwt_exp: jwtExp,
|
|
@@ -318,7 +318,7 @@ describe('SDK reporting storage', async () => {
|
|
|
318
318
|
});
|
|
319
319
|
|
|
320
320
|
const sdk = await factory.db
|
|
321
|
-
.sql`SELECT * FROM
|
|
321
|
+
.sql`SELECT * FROM connection_report_events WHERE user_id = ${{ type: 'varchar', value: user_week.user_id }}`.rows<event_types.ClientConnection>();
|
|
322
322
|
expect(sdk).toHaveLength(2);
|
|
323
323
|
const cleaned = removeVolatileFields(sdk);
|
|
324
324
|
expect(cleaned).toMatchSnapshot();
|
|
@@ -327,10 +327,10 @@ describe('SDK reporting storage', async () => {
|
|
|
327
327
|
it('Should delete rows older than specified range', async () => {
|
|
328
328
|
await deleteData();
|
|
329
329
|
await loadData();
|
|
330
|
-
await factory.
|
|
330
|
+
await factory.deleteOldConnectionData({
|
|
331
331
|
date: weekAgo
|
|
332
332
|
});
|
|
333
|
-
const sdk = await factory.
|
|
333
|
+
const sdk = await factory.getClientConnectionReports({
|
|
334
334
|
start: monthAgo,
|
|
335
335
|
end: now
|
|
336
336
|
});
|