@powersync/service-core-tests 0.0.0-dev-20250820110726 → 0.0.0-dev-20250827072023
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 -4
- package/dist/tests/register-report-tests.d.ts +78 -0
- package/dist/tests/register-report-tests.js +119 -0
- package/dist/tests/register-report-tests.js.map +1 -0
- package/dist/tests/register-sync-tests.js +30 -15
- package/dist/tests/register-sync-tests.js.map +1 -1
- package/dist/tests/tests-index.d.ts +1 -0
- package/dist/tests/tests-index.js +1 -0
- package/dist/tests/tests-index.js.map +1 -1
- package/package.json +4 -4
- package/src/tests/register-report-tests.ts +136 -0
- package/src/tests/register-sync-tests.ts +30 -15
- package/src/tests/tests-index.ts +1 -0
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { storage } from '@powersync/service-core';
|
|
2
|
+
import { expect, it } from 'vitest';
|
|
3
|
+
|
|
4
|
+
const now = new Date();
|
|
5
|
+
const nowAdd5minutes = new Date(now.getFullYear(), now.getMonth(), now.getDate(), now.getHours(), now.getMinutes() + 5);
|
|
6
|
+
const nowLess5minutes = new Date(
|
|
7
|
+
now.getFullYear(),
|
|
8
|
+
now.getMonth(),
|
|
9
|
+
now.getDate(),
|
|
10
|
+
now.getHours(),
|
|
11
|
+
now.getMinutes() - 5
|
|
12
|
+
);
|
|
13
|
+
const dayAgo = new Date(now.getFullYear(), now.getMonth(), now.getDate() - 1, now.getHours());
|
|
14
|
+
const yesterday = new Date(now.getFullYear(), now.getMonth(), now.getDate() - 1);
|
|
15
|
+
const weekAgo = new Date(now.getFullYear(), now.getMonth(), now.getDate() - 7);
|
|
16
|
+
const monthAgo = new Date(now.getFullYear(), now.getMonth() - 1, now.getDate());
|
|
17
|
+
|
|
18
|
+
export const REPORT_TEST_DATES = {
|
|
19
|
+
now,
|
|
20
|
+
nowAdd5minutes,
|
|
21
|
+
nowLess5minutes,
|
|
22
|
+
dayAgo,
|
|
23
|
+
yesterday,
|
|
24
|
+
weekAgo,
|
|
25
|
+
monthAgo
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const user_one = {
|
|
29
|
+
user_id: 'user_one',
|
|
30
|
+
client_id: 'client_one',
|
|
31
|
+
connected_at: now,
|
|
32
|
+
sdk: 'powersync-dart/1.6.4',
|
|
33
|
+
user_agent: 'powersync-dart/1.6.4 Dart (flutter-web) Chrome/128 android',
|
|
34
|
+
jwt_exp: nowAdd5minutes
|
|
35
|
+
};
|
|
36
|
+
const user_two = {
|
|
37
|
+
user_id: 'user_two',
|
|
38
|
+
client_id: 'client_two',
|
|
39
|
+
connected_at: nowLess5minutes,
|
|
40
|
+
sdk: 'powersync-js/1.21.1',
|
|
41
|
+
user_agent: 'powersync-js/1.21.0 powersync-web Chromium/138 linux',
|
|
42
|
+
jwt_exp: nowAdd5minutes
|
|
43
|
+
};
|
|
44
|
+
const user_three = {
|
|
45
|
+
user_id: 'user_three',
|
|
46
|
+
client_id: 'client_three',
|
|
47
|
+
connected_at: yesterday,
|
|
48
|
+
sdk: 'powersync-js/1.21.2',
|
|
49
|
+
user_agent: 'powersync-js/1.21.0 powersync-web Firefox/141 linux',
|
|
50
|
+
disconnected_at: yesterday
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const user_four = {
|
|
54
|
+
user_id: 'user_four',
|
|
55
|
+
client_id: 'client_four',
|
|
56
|
+
connected_at: now,
|
|
57
|
+
sdk: 'powersync-js/1.21.4',
|
|
58
|
+
user_agent: 'powersync-js/1.21.0 powersync-web Firefox/141 linux',
|
|
59
|
+
jwt_exp: nowLess5minutes
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const user_old = {
|
|
63
|
+
user_id: 'user_one',
|
|
64
|
+
client_id: '',
|
|
65
|
+
connected_at: now,
|
|
66
|
+
sdk: 'unknown',
|
|
67
|
+
user_agent: 'Dart (flutter-web) Chrome/128 android',
|
|
68
|
+
jwt_exp: nowAdd5minutes
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const user_week = {
|
|
72
|
+
user_id: 'user_week',
|
|
73
|
+
client_id: 'client_week',
|
|
74
|
+
connected_at: weekAgo,
|
|
75
|
+
sdk: 'powersync-js/1.24.5',
|
|
76
|
+
user_agent: 'powersync-js/1.21.0 powersync-web Firefox/141 linux',
|
|
77
|
+
disconnected_at: weekAgo
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const user_month = {
|
|
81
|
+
user_id: 'user_month',
|
|
82
|
+
client_id: 'client_month',
|
|
83
|
+
connected_at: monthAgo,
|
|
84
|
+
sdk: 'powersync-js/1.23.6',
|
|
85
|
+
user_agent: 'powersync-js/1.23.0 powersync-web Firefox/141 linux',
|
|
86
|
+
disconnected_at: monthAgo
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
const user_expired = {
|
|
90
|
+
user_id: 'user_expired',
|
|
91
|
+
client_id: 'client_expired',
|
|
92
|
+
connected_at: monthAgo,
|
|
93
|
+
sdk: 'powersync-js/1.23.7',
|
|
94
|
+
user_agent: 'powersync-js/1.23.0 powersync-web Firefox/141 linux',
|
|
95
|
+
jwt_exp: monthAgo
|
|
96
|
+
};
|
|
97
|
+
export const REPORT_TEST_USERS = {
|
|
98
|
+
user_one,
|
|
99
|
+
user_two,
|
|
100
|
+
user_three,
|
|
101
|
+
user_four,
|
|
102
|
+
user_old,
|
|
103
|
+
user_week,
|
|
104
|
+
user_month,
|
|
105
|
+
user_expired
|
|
106
|
+
};
|
|
107
|
+
export type ReportUserData = typeof REPORT_TEST_USERS;
|
|
108
|
+
|
|
109
|
+
export async function registerReportTests(factory: storage.ReportStorage) {
|
|
110
|
+
it('Should show currently connected users', async () => {
|
|
111
|
+
const current = await factory.getConnectedClients();
|
|
112
|
+
expect(current).toMatchSnapshot();
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it('Should show connection report data for user over the past month', async () => {
|
|
116
|
+
const sdk = await factory.getClientConnectionReports({
|
|
117
|
+
start: monthAgo,
|
|
118
|
+
end: now
|
|
119
|
+
});
|
|
120
|
+
expect(sdk).toMatchSnapshot();
|
|
121
|
+
});
|
|
122
|
+
it('Should show connection report data for user over the past week', async () => {
|
|
123
|
+
const sdk = await factory.getClientConnectionReports({
|
|
124
|
+
start: weekAgo,
|
|
125
|
+
end: now
|
|
126
|
+
});
|
|
127
|
+
expect(sdk).toMatchSnapshot();
|
|
128
|
+
});
|
|
129
|
+
it('Should show connection report data for user over the past day', async () => {
|
|
130
|
+
const sdk = await factory.getClientConnectionReports({
|
|
131
|
+
start: dayAgo,
|
|
132
|
+
end: now
|
|
133
|
+
});
|
|
134
|
+
expect(sdk).toMatchSnapshot();
|
|
135
|
+
});
|
|
136
|
+
}
|
|
@@ -89,7 +89,8 @@ export function registerSyncTests(factory: storage.TestStorageFactory) {
|
|
|
89
89
|
raw_data: true
|
|
90
90
|
},
|
|
91
91
|
tracker,
|
|
92
|
-
token: { sub: '', exp: Date.now() / 1000 + 10 } as any
|
|
92
|
+
token: { sub: '', exp: Date.now() / 1000 + 10 } as any,
|
|
93
|
+
isEncodingAsBson: false
|
|
93
94
|
});
|
|
94
95
|
|
|
95
96
|
const lines = await consumeCheckpointLines(stream);
|
|
@@ -149,7 +150,8 @@ bucket_definitions:
|
|
|
149
150
|
raw_data: true
|
|
150
151
|
},
|
|
151
152
|
tracker,
|
|
152
|
-
token: { sub: '', exp: Date.now() / 1000 + 10 } as any
|
|
153
|
+
token: { sub: '', exp: Date.now() / 1000 + 10 } as any,
|
|
154
|
+
isEncodingAsBson: false
|
|
153
155
|
});
|
|
154
156
|
|
|
155
157
|
const lines = await consumeCheckpointLines(stream);
|
|
@@ -211,7 +213,8 @@ bucket_definitions:
|
|
|
211
213
|
raw_data: true
|
|
212
214
|
},
|
|
213
215
|
tracker,
|
|
214
|
-
token: { sub: '', exp: Date.now() / 1000 + 10 } as any
|
|
216
|
+
token: { sub: '', exp: Date.now() / 1000 + 10 } as any,
|
|
217
|
+
isEncodingAsBson: false
|
|
215
218
|
});
|
|
216
219
|
|
|
217
220
|
let sentCheckpoints = 0;
|
|
@@ -320,7 +323,8 @@ bucket_definitions:
|
|
|
320
323
|
raw_data: true
|
|
321
324
|
},
|
|
322
325
|
tracker,
|
|
323
|
-
token: { sub: 'user_one', exp: Date.now() / 1000 + 100000 } as any
|
|
326
|
+
token: { sub: 'user_one', exp: Date.now() / 1000 + 100000 } as any,
|
|
327
|
+
isEncodingAsBson: false
|
|
324
328
|
});
|
|
325
329
|
|
|
326
330
|
let sentCheckpoints = 0;
|
|
@@ -460,7 +464,8 @@ bucket_definitions:
|
|
|
460
464
|
raw_data: true
|
|
461
465
|
},
|
|
462
466
|
tracker,
|
|
463
|
-
token: { sub: '', exp: Date.now() / 1000 + 10 } as any
|
|
467
|
+
token: { sub: '', exp: Date.now() / 1000 + 10 } as any,
|
|
468
|
+
isEncodingAsBson: false
|
|
464
469
|
});
|
|
465
470
|
|
|
466
471
|
let sentRows = 0;
|
|
@@ -575,7 +580,8 @@ bucket_definitions:
|
|
|
575
580
|
raw_data: true
|
|
576
581
|
},
|
|
577
582
|
tracker,
|
|
578
|
-
token: { sub: '', exp: Date.now() / 1000 + 100000 } as any
|
|
583
|
+
token: { sub: '', exp: Date.now() / 1000 + 100000 } as any,
|
|
584
|
+
isEncodingAsBson: false
|
|
579
585
|
});
|
|
580
586
|
|
|
581
587
|
const lines: any[] = [];
|
|
@@ -640,7 +646,8 @@ bucket_definitions:
|
|
|
640
646
|
raw_data: false
|
|
641
647
|
},
|
|
642
648
|
tracker,
|
|
643
|
-
token: { sub: '', exp: Date.now() / 1000 + 10 } as any
|
|
649
|
+
token: { sub: '', exp: Date.now() / 1000 + 10 } as any,
|
|
650
|
+
isEncodingAsBson: false
|
|
644
651
|
});
|
|
645
652
|
|
|
646
653
|
const lines = await consumeCheckpointLines(stream);
|
|
@@ -668,7 +675,8 @@ bucket_definitions:
|
|
|
668
675
|
raw_data: true
|
|
669
676
|
},
|
|
670
677
|
tracker,
|
|
671
|
-
token: { sub: '', exp: 0 } as any
|
|
678
|
+
token: { sub: '', exp: 0 } as any,
|
|
679
|
+
isEncodingAsBson: false
|
|
672
680
|
});
|
|
673
681
|
|
|
674
682
|
const lines = await consumeCheckpointLines(stream);
|
|
@@ -698,7 +706,8 @@ bucket_definitions:
|
|
|
698
706
|
raw_data: true
|
|
699
707
|
},
|
|
700
708
|
tracker,
|
|
701
|
-
token: { sub: '', exp: Date.now() / 1000 + 10 } as any
|
|
709
|
+
token: { sub: '', exp: Date.now() / 1000 + 10 } as any,
|
|
710
|
+
isEncodingAsBson: false
|
|
702
711
|
});
|
|
703
712
|
const iter = stream[Symbol.asyncIterator]();
|
|
704
713
|
context.onTestFinished(() => {
|
|
@@ -771,7 +780,8 @@ bucket_definitions:
|
|
|
771
780
|
raw_data: true
|
|
772
781
|
},
|
|
773
782
|
tracker,
|
|
774
|
-
token: { sub: 'user1', exp: Date.now() / 1000 + 100 } as any
|
|
783
|
+
token: { sub: 'user1', exp: Date.now() / 1000 + 100 } as any,
|
|
784
|
+
isEncodingAsBson: false
|
|
775
785
|
});
|
|
776
786
|
const iter = stream[Symbol.asyncIterator]();
|
|
777
787
|
context.onTestFinished(() => {
|
|
@@ -846,7 +856,8 @@ bucket_definitions:
|
|
|
846
856
|
raw_data: true
|
|
847
857
|
},
|
|
848
858
|
tracker,
|
|
849
|
-
token: { sub: 'user1', exp: Date.now() / 1000 + 100 } as any
|
|
859
|
+
token: { sub: 'user1', exp: Date.now() / 1000 + 100 } as any,
|
|
860
|
+
isEncodingAsBson: false
|
|
850
861
|
});
|
|
851
862
|
const iter = stream[Symbol.asyncIterator]();
|
|
852
863
|
context.onTestFinished(() => {
|
|
@@ -912,7 +923,8 @@ bucket_definitions:
|
|
|
912
923
|
raw_data: true
|
|
913
924
|
},
|
|
914
925
|
tracker,
|
|
915
|
-
token: { sub: 'user1', exp: Date.now() / 1000 + 100 } as any
|
|
926
|
+
token: { sub: 'user1', exp: Date.now() / 1000 + 100 } as any,
|
|
927
|
+
isEncodingAsBson: false
|
|
916
928
|
});
|
|
917
929
|
const iter = stream[Symbol.asyncIterator]();
|
|
918
930
|
context.onTestFinished(() => {
|
|
@@ -979,7 +991,8 @@ bucket_definitions:
|
|
|
979
991
|
raw_data: true
|
|
980
992
|
},
|
|
981
993
|
tracker,
|
|
982
|
-
token: { sub: '', exp: exp } as any
|
|
994
|
+
token: { sub: '', exp: exp } as any,
|
|
995
|
+
isEncodingAsBson: false
|
|
983
996
|
});
|
|
984
997
|
const iter = stream[Symbol.asyncIterator]();
|
|
985
998
|
context.onTestFinished(() => {
|
|
@@ -1041,7 +1054,8 @@ bucket_definitions:
|
|
|
1041
1054
|
raw_data: true
|
|
1042
1055
|
},
|
|
1043
1056
|
tracker,
|
|
1044
|
-
token: { sub: '', exp: Date.now() / 1000 + 10 } as any
|
|
1057
|
+
token: { sub: '', exp: Date.now() / 1000 + 10 } as any,
|
|
1058
|
+
isEncodingAsBson: false
|
|
1045
1059
|
});
|
|
1046
1060
|
|
|
1047
1061
|
const iter = stream[Symbol.asyncIterator]();
|
|
@@ -1166,7 +1180,8 @@ bucket_definitions:
|
|
|
1166
1180
|
raw_data: true
|
|
1167
1181
|
},
|
|
1168
1182
|
tracker,
|
|
1169
|
-
token: { sub: 'test', exp: Date.now() / 1000 + 10 } as any
|
|
1183
|
+
token: { sub: 'test', exp: Date.now() / 1000 + 10 } as any,
|
|
1184
|
+
isEncodingAsBson: false
|
|
1170
1185
|
};
|
|
1171
1186
|
const stream1 = sync.streamResponse(params);
|
|
1172
1187
|
const lines1 = await consumeCheckpointLines(stream1);
|
package/src/tests/tests-index.ts
CHANGED