@powersync/service-module-postgres-storage 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.
@@ -39,7 +39,7 @@ exports[`sync - postgres > compacting data - invalidate checkpoint 2`] = `
39
39
  "bucket": "mybucket[]",
40
40
  "data": [
41
41
  {
42
- "checksum": -93886621n,
42
+ "checksum": -93886621,
43
43
  "op": "CLEAR",
44
44
  "op_id": "2",
45
45
  },
@@ -74,7 +74,7 @@ exports[`sync - postgres > compacting data - invalidate checkpoint 2`] = `
74
74
  "bucket": "mybucket[]",
75
75
  "data": [
76
76
  {
77
- "checksum": 1859363232n,
77
+ "checksum": 1859363232,
78
78
  "data": "{"id":"t1","description":"Test 1b"}",
79
79
  "object_id": "t1",
80
80
  "object_type": "test",
@@ -83,7 +83,7 @@ exports[`sync - postgres > compacting data - invalidate checkpoint 2`] = `
83
83
  "subkey": "02d285ac-4f96-5124-8fba-c6d1df992dd1",
84
84
  },
85
85
  {
86
- "checksum": 3028503153n,
86
+ "checksum": 3028503153,
87
87
  "data": "{"id":"t2","description":"Test 2b"}",
88
88
  "object_id": "t2",
89
89
  "object_type": "test",
@@ -203,6 +203,7 @@ exports[`sync - postgres > sends checkpoint complete line for empty checkpoint 1
203
203
  "next_after": "1",
204
204
  },
205
205
  },
206
+ null,
206
207
  {
207
208
  "checkpoint_complete": {
208
209
  "last_op_id": "1",
@@ -274,7 +275,7 @@ exports[`sync - postgres > sync buckets in order 1`] = `
274
275
  "bucket": "b1[]",
275
276
  "data": [
276
277
  {
277
- "checksum": 2912868539n,
278
+ "checksum": 2912868539,
278
279
  "data": "{"id":"earlier","description":"Test 2"}",
279
280
  "object_id": "earlier",
280
281
  "object_type": "test",
@@ -299,7 +300,7 @@ exports[`sync - postgres > sync buckets in order 1`] = `
299
300
  "bucket": "b0[]",
300
301
  "data": [
301
302
  {
302
- "checksum": 920318466n,
303
+ "checksum": 920318466,
303
304
  "data": "{"id":"t1","description":"Test 1"}",
304
305
  "object_id": "t1",
305
306
  "object_type": "test",
@@ -354,7 +355,7 @@ exports[`sync - postgres > sync global data 1`] = `
354
355
  "bucket": "mybucket[]",
355
356
  "data": [
356
357
  {
357
- "checksum": 920318466n,
358
+ "checksum": 920318466,
358
359
  "data": "{"id":"t1","description":"Test 1"}",
359
360
  "object_id": "t1",
360
361
  "object_type": "test",
@@ -363,7 +364,7 @@ exports[`sync - postgres > sync global data 1`] = `
363
364
  "subkey": "02d285ac-4f96-5124-8fba-c6d1df992dd1",
364
365
  },
365
366
  {
366
- "checksum": 3280762209n,
367
+ "checksum": 3280762209,
367
368
  "data": "{"id":"t2","description":"Test 2"}",
368
369
  "object_id": "t2",
369
370
  "object_type": "test",
@@ -702,7 +703,7 @@ exports[`sync - postgres > sync updates to data query only 2`] = `
702
703
  "bucket": "by_user["user1"]",
703
704
  "data": [
704
705
  {
705
- "checksum": 1418351250n,
706
+ "checksum": 1418351250,
706
707
  "data": "{"id":"list1","user_id":"user1","name":"User 1"}",
707
708
  "object_id": "list1",
708
709
  "object_type": "lists",
@@ -787,7 +788,7 @@ exports[`sync - postgres > sync updates to global data 2`] = `
787
788
  "bucket": "mybucket[]",
788
789
  "data": [
789
790
  {
790
- "checksum": 920318466n,
791
+ "checksum": 920318466,
791
792
  "data": "{"id":"t1","description":"Test 1"}",
792
793
  "object_id": "t1",
793
794
  "object_type": "test",
@@ -836,7 +837,7 @@ exports[`sync - postgres > sync updates to global data 3`] = `
836
837
  "bucket": "mybucket[]",
837
838
  "data": [
838
839
  {
839
- "checksum": 3280762209n,
840
+ "checksum": 3280762209,
840
841
  "data": "{"id":"t2","description":"Test 2"}",
841
842
  "object_id": "t2",
842
843
  "object_type": "test",
@@ -909,7 +910,7 @@ exports[`sync - postgres > sync updates to parameter query + data 2`] = `
909
910
  "bucket": "by_user["user1"]",
910
911
  "data": [
911
912
  {
912
- "checksum": 1418351250n,
913
+ "checksum": 1418351250,
913
914
  "data": "{"id":"list1","user_id":"user1","name":"User 1"}",
914
915
  "object_id": "list1",
915
916
  "object_type": "lists",
@@ -1,6 +1,13 @@
1
1
  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
+ import { register, ReportUserData } from '@powersync/service-core-tests';
5
+ import { PostgresReportStorageFactory } from '../../src/storage/PostgresReportStorageFactory.js';
6
+ import { DateTimeValue } from '@powersync/service-sync-rules';
7
+
8
+ const factory = await POSTGRES_REPORT_STORAGE_FACTORY();
9
+ const userData = register.REPORT_TEST_USERS;
10
+ const dates = register.REPORT_TEST_DATES;
4
11
 
5
12
  function removeVolatileFields(sdks: event_types.ClientConnection[]): Partial<event_types.ClientConnection>[] {
6
13
  return sdks.map((sdk) => {
@@ -11,97 +18,8 @@ function removeVolatileFields(sdks: event_types.ClientConnection[]): Partial<eve
11
18
  });
12
19
  }
13
20
 
14
- describe('Connection report storage', async () => {
15
- const factory = await POSTGRES_REPORT_STORAGE_FACTORY();
16
- const now = new Date();
17
- const nowAdd5minutes = new Date(
18
- now.getFullYear(),
19
- now.getMonth(),
20
- now.getDate(),
21
- now.getHours(),
22
- now.getMinutes() + 5
23
- );
24
- const nowLess5minutes = new Date(
25
- now.getFullYear(),
26
- now.getMonth(),
27
- now.getDate(),
28
- now.getHours(),
29
- now.getMinutes() - 5
30
- );
31
- const dayAgo = new Date(now.getFullYear(), now.getMonth(), now.getDate() - 1, now.getHours());
32
- const yesterday = new Date(now.getFullYear(), now.getMonth(), now.getDate() - 1);
33
- const weekAgo = new Date(now.getFullYear(), now.getMonth(), now.getDate() - 7);
34
- const monthAgo = new Date(now.getFullYear(), now.getMonth() - 1, now.getDate());
35
- const user_one = {
36
- user_id: 'user_one',
37
- client_id: 'client_one',
38
- connected_at: now.toISOString(),
39
- sdk: 'powersync-dart/1.6.4',
40
- user_agent: 'powersync-dart/1.6.4 Dart (flutter-web) Chrome/128 android',
41
- jwt_exp: nowAdd5minutes.toISOString(),
42
- id: '1'
43
- };
44
- const user_two = {
45
- user_id: 'user_two',
46
- client_id: 'client_two',
47
- connected_at: nowLess5minutes.toISOString(),
48
- sdk: 'powersync-js/1.21.1',
49
- user_agent: 'powersync-js/1.21.0 powersync-web Chromium/138 linux',
50
- jwt_exp: nowAdd5minutes.toISOString(),
51
- id: '2'
52
- };
53
- const user_three = {
54
- user_id: 'user_three',
55
- client_id: 'client_three',
56
- connected_at: yesterday.toISOString(),
57
- sdk: 'powersync-js/1.21.2',
58
- user_agent: 'powersync-js/1.21.0 powersync-web Firefox/141 linux',
59
- disconnected_at: yesterday.toISOString(),
60
- id: '3'
61
- };
62
-
63
- const user_four = {
64
- user_id: 'user_four',
65
- client_id: 'client_four',
66
- connected_at: now.toISOString(),
67
- sdk: 'powersync-js/1.21.4',
68
- user_agent: 'powersync-js/1.21.0 powersync-web Firefox/141 linux',
69
- jwt_exp: nowLess5minutes.toISOString(),
70
- id: '4'
71
- };
72
-
73
- const user_week = {
74
- user_id: 'user_week',
75
- client_id: 'client_week',
76
- connected_at: weekAgo.toISOString(),
77
- sdk: 'powersync-js/1.24.5',
78
- user_agent: 'powersync-js/1.21.0 powersync-web Firefox/141 linux',
79
- disconnected_at: weekAgo.toISOString(),
80
- id: 'week'
81
- };
82
-
83
- const user_month = {
84
- user_id: 'user_month',
85
- client_id: 'client_month',
86
- connected_at: monthAgo.toISOString(),
87
- sdk: 'powersync-js/1.23.6',
88
- user_agent: 'powersync-js/1.23.0 powersync-web Firefox/141 linux',
89
- disconnected_at: monthAgo.toISOString(),
90
- id: 'month'
91
- };
92
-
93
- const user_expired = {
94
- user_id: 'user_expired',
95
- client_id: 'client_expired',
96
- connected_at: monthAgo.toISOString(),
97
- sdk: 'powersync-js/1.23.7',
98
- user_agent: 'powersync-js/1.23.0 powersync-web Firefox/141 linux',
99
- jwt_exp: monthAgo.toISOString(),
100
- id: 'expired'
101
- };
102
-
103
- async function loadData() {
104
- await factory.db.sql`
21
+ async function loadData(userData: ReportUserData, factory: PostgresReportStorageFactory) {
22
+ await factory.db.sql`
105
23
  INSERT INTO
106
24
  connection_report_events (
107
25
  user_id,
@@ -115,163 +33,131 @@ describe('Connection report storage', async () => {
115
33
  )
116
34
  VALUES
117
35
  (
118
- ${{ type: 'varchar', value: user_one.user_id }},
119
- ${{ type: 'varchar', value: user_one.client_id }},
120
- ${{ type: 1184, value: user_one.connected_at }},
121
- ${{ type: 'varchar', value: user_one.sdk }},
122
- ${{ type: 'varchar', value: user_one.user_agent }},
123
- ${{ type: 1184, value: user_one.jwt_exp }},
124
- ${{ type: 'varchar', value: user_one.id }},
36
+ ${{ type: 'varchar', value: userData.user_one.user_id }},
37
+ ${{ type: 'varchar', value: userData.user_one.client_id }},
38
+ ${{ type: 1184, value: userData.user_one.connected_at.toISOString() }},
39
+ ${{ type: 'varchar', value: userData.user_one.sdk }},
40
+ ${{ type: 'varchar', value: userData.user_one.user_agent }},
41
+ ${{ type: 1184, value: userData.user_one.jwt_exp.toISOString() }},
42
+ ${{ type: 'varchar', value: '1' }},
43
+ NULL
44
+ ),
45
+ (
46
+ ${{ type: 'varchar', value: userData.user_two.user_id }},
47
+ ${{ type: 'varchar', value: userData.user_two.client_id }},
48
+ ${{ type: 1184, value: userData.user_two.connected_at.toISOString() }},
49
+ ${{ type: 'varchar', value: userData.user_two.sdk }},
50
+ ${{ type: 'varchar', value: userData.user_two.user_agent }},
51
+ ${{ type: 1184, value: userData.user_two.jwt_exp.toISOString() }},
52
+ ${{ type: 'varchar', value: '2' }},
125
53
  NULL
126
54
  ),
127
55
  (
128
- ${{ type: 'varchar', value: user_two.user_id }},
129
- ${{ type: 'varchar', value: user_two.client_id }},
130
- ${{ type: 1184, value: user_two.connected_at }},
131
- ${{ type: 'varchar', value: user_two.sdk }},
132
- ${{ type: 'varchar', value: user_two.user_agent }},
133
- ${{ type: 1184, value: user_two.jwt_exp }},
134
- ${{ type: 'varchar', value: user_two.id }},
56
+ ${{ type: 'varchar', value: userData.user_four.user_id }},
57
+ ${{ type: 'varchar', value: userData.user_four.client_id }},
58
+ ${{ type: 1184, value: userData.user_four.connected_at.toISOString() }},
59
+ ${{ type: 'varchar', value: userData.user_four.sdk }},
60
+ ${{ type: 'varchar', value: userData.user_four.user_agent }},
61
+ ${{ type: 1184, value: userData.user_four.jwt_exp.toISOString() }},
62
+ ${{ type: 'varchar', value: '4' }},
135
63
  NULL
136
64
  ),
137
65
  (
138
- ${{ type: 'varchar', value: user_four.user_id }},
139
- ${{ type: 'varchar', value: user_four.client_id }},
140
- ${{ type: 1184, value: user_four.connected_at }},
141
- ${{ type: 'varchar', value: user_four.sdk }},
142
- ${{ type: 'varchar', value: user_four.user_agent }},
143
- ${{ type: 1184, value: user_four.jwt_exp }},
144
- ${{ type: 'varchar', value: user_four.id }},
66
+ ${{ type: 'varchar', value: userData.user_old.user_id }},
67
+ ${{ type: 'varchar', value: userData.user_old.client_id }},
68
+ ${{ type: 1184, value: userData.user_old.connected_at.toISOString() }},
69
+ ${{ type: 'varchar', value: userData.user_old.sdk }},
70
+ ${{ type: 'varchar', value: userData.user_old.user_agent }},
71
+ ${{ type: 1184, value: userData.user_old.jwt_exp.toISOString() }},
72
+ ${{ type: 'varchar', value: '5' }},
145
73
  NULL
146
74
  ),
147
75
  (
148
- ${{ type: 'varchar', value: user_three.user_id }},
149
- ${{ type: 'varchar', value: user_three.client_id }},
150
- ${{ type: 1184, value: user_three.connected_at }},
151
- ${{ type: 'varchar', value: user_three.sdk }},
152
- ${{ type: 'varchar', value: user_three.user_agent }},
76
+ ${{ type: 'varchar', value: userData.user_three.user_id }},
77
+ ${{ type: 'varchar', value: userData.user_three.client_id }},
78
+ ${{ type: 1184, value: userData.user_three.connected_at.toISOString() }},
79
+ ${{ type: 'varchar', value: userData.user_three.sdk }},
80
+ ${{ type: 'varchar', value: userData.user_three.user_agent }},
153
81
  NULL,
154
- ${{ type: 'varchar', value: user_three.id }},
155
- ${{ type: 1184, value: user_three.disconnected_at }}
82
+ ${{ type: 'varchar', value: '3' }},
83
+ ${{ type: 1184, value: userData.user_three.disconnected_at.toISOString() }}
156
84
  ),
157
85
  (
158
- ${{ type: 'varchar', value: user_week.user_id }},
159
- ${{ type: 'varchar', value: user_week.client_id }},
160
- ${{ type: 1184, value: user_week.connected_at }},
161
- ${{ type: 'varchar', value: user_week.sdk }},
162
- ${{ type: 'varchar', value: user_week.user_agent }},
86
+ ${{ type: 'varchar', value: userData.user_week.user_id }},
87
+ ${{ type: 'varchar', value: userData.user_week.client_id }},
88
+ ${{ type: 1184, value: userData.user_week.connected_at.toISOString() }},
89
+ ${{ type: 'varchar', value: userData.user_week.sdk }},
90
+ ${{ type: 'varchar', value: userData.user_week.user_agent }},
163
91
  NULL,
164
- ${{ type: 'varchar', value: user_week.id }},
165
- ${{ type: 1184, value: user_week.disconnected_at }}
92
+ ${{ type: 'varchar', value: 'week' }},
93
+ ${{ type: 1184, value: userData.user_week.disconnected_at.toISOString() }}
166
94
  ),
167
95
  (
168
- ${{ type: 'varchar', value: user_month.user_id }},
169
- ${{ type: 'varchar', value: user_month.client_id }},
170
- ${{ type: 1184, value: user_month.connected_at }},
171
- ${{ type: 'varchar', value: user_month.sdk }},
172
- ${{ type: 'varchar', value: user_month.user_agent }},
96
+ ${{ type: 'varchar', value: userData.user_month.user_id }},
97
+ ${{ type: 'varchar', value: userData.user_month.client_id }},
98
+ ${{ type: 1184, value: userData.user_month.connected_at.toISOString() }},
99
+ ${{ type: 'varchar', value: userData.user_month.sdk }},
100
+ ${{ type: 'varchar', value: userData.user_month.user_agent }},
173
101
  NULL,
174
- ${{ type: 'varchar', value: user_month.id }},
175
- ${{ type: 1184, value: user_month.disconnected_at }}
102
+ ${{ type: 'varchar', value: 'month' }},
103
+ ${{ type: 1184, value: userData.user_month.disconnected_at.toISOString() }}
176
104
  ),
177
105
  (
178
- ${{ type: 'varchar', value: user_expired.user_id }},
179
- ${{ type: 'varchar', value: user_expired.client_id }},
180
- ${{ type: 1184, value: user_expired.connected_at }},
181
- ${{ type: 'varchar', value: user_expired.sdk }},
182
- ${{ type: 'varchar', value: user_expired.user_agent }},
183
- ${{ type: 1184, value: user_expired.jwt_exp }},
184
- ${{ type: 'varchar', value: user_expired.id }},
106
+ ${{ type: 'varchar', value: userData.user_expired.user_id }},
107
+ ${{ type: 'varchar', value: userData.user_expired.client_id }},
108
+ ${{ type: 1184, value: userData.user_expired.connected_at.toISOString() }},
109
+ ${{ type: 'varchar', value: userData.user_expired.sdk }},
110
+ ${{ type: 'varchar', value: userData.user_expired.user_agent }},
111
+ ${{ type: 1184, value: userData.user_expired.jwt_exp.toISOString() }},
112
+ ${{ type: 'varchar', value: 'expired' }},
185
113
  NULL
186
114
  )
187
115
  `.execute();
188
- }
116
+ }
189
117
 
190
- function deleteData() {
191
- return factory.db.sql`TRUNCATE TABLE connection_report_events`.execute();
192
- }
118
+ async function deleteData(factory: PostgresReportStorageFactory) {
119
+ await factory.db.sql`TRUNCATE TABLE connection_report_events`.execute();
120
+ }
193
121
 
194
- beforeAll(async () => {
195
- await loadData();
196
- });
122
+ beforeAll(async () => {
123
+ await loadData(userData, factory);
124
+ });
125
+ afterAll(async () => {
126
+ await deleteData(factory);
127
+ });
197
128
 
198
- afterAll(async () => {
199
- await deleteData();
200
- });
201
- it('Should show connected users with start range', async () => {
202
- const current = await factory.getConnectedClients({
203
- range: {
204
- start: new Date(
205
- now.getFullYear(),
206
- now.getMonth(),
207
- now.getDate(),
208
- now.getHours(),
209
- now.getMinutes() - 1
210
- ).toISOString()
211
- }
212
- });
213
- expect(current).toMatchSnapshot();
214
- });
215
- it('Should show connected users with start range and end range', async () => {
216
- const current = await factory.getConnectedClients({
217
- range: {
218
- end: nowLess5minutes.toISOString(),
219
- start: new Date(
220
- now.getFullYear(),
221
- now.getMonth(),
222
- now.getDate(),
223
- now.getHours(),
224
- now.getMinutes() - 6
225
- ).toISOString()
226
- }
227
- });
228
- expect(current).toMatchSnapshot();
229
- });
230
- it('Should show connection report data for user over the past month', async () => {
231
- const sdk = await factory.getClientConnectionReports({
232
- start: monthAgo,
233
- end: now
234
- });
235
- expect(sdk).toMatchSnapshot();
236
- });
237
- it('Should show connection report data for user over the past week', async () => {
238
- const sdk = await factory.getClientConnectionReports({
239
- start: weekAgo,
240
- end: now
241
- });
242
- expect(sdk).toMatchSnapshot();
243
- });
244
- it('Should show connection report data for user over the past day', async () => {
245
- const sdk = await factory.getClientConnectionReports({
246
- start: dayAgo,
247
- end: now
248
- });
249
- expect(sdk).toMatchSnapshot();
250
- });
129
+ describe('Report storage tests', async () => {
130
+ await register.registerReportTests(factory);
131
+ });
251
132
 
133
+ describe('Connection report storage', async () => {
252
134
  it('Should update a connection event if its within a day', async () => {
253
135
  const newConnectAt = new Date(
254
- now.getFullYear(),
255
- now.getMonth(),
256
- now.getDate(),
257
- now.getHours(),
258
- now.getMinutes() + 20
136
+ dates.now.getFullYear(),
137
+ dates.now.getMonth(),
138
+ dates.now.getDate(),
139
+ dates.now.getHours(),
140
+ dates.now.getMinutes() + 20
259
141
  );
260
142
  const jwtExp = new Date(newConnectAt.getFullYear(), newConnectAt.getMonth(), newConnectAt.getDate() + 1);
261
143
  await factory.reportClientConnection({
262
- sdk: user_one.sdk,
144
+ sdk: userData.user_one.sdk,
263
145
  connected_at: newConnectAt,
264
146
  jwt_exp: jwtExp,
265
- client_id: user_one.client_id,
266
- user_id: user_one.user_id,
267
- user_agent: user_one.user_agent
147
+ client_id: userData.user_one.client_id,
148
+ user_id: userData.user_one.user_id,
149
+ user_agent: userData.user_one.user_agent
268
150
  });
269
151
 
270
152
  const sdk = await factory.db
271
- .sql`SELECT * FROM connection_report_events WHERE user_id = ${{ type: 'varchar', value: user_one.user_id }}`.rows<event_types.ClientConnection>();
153
+ .sql`SELECT * FROM connection_report_events WHERE user_id = ${{ type: 'varchar', value: userData.user_one.user_id }} AND client_id = ${{ type: 'varchar', value: userData.user_one.client_id }}`.rows<event_types.ClientConnection>();
272
154
  expect(sdk).toHaveLength(1);
273
- expect(new Date(sdk[0].connected_at).toISOString()).toEqual(newConnectAt.toISOString());
274
- expect(new Date(sdk[0].jwt_exp!).toISOString()).toEqual(jwtExp.toISOString());
155
+ expect(new Date((sdk[0].connected_at as unknown as DateTimeValue).iso8601Representation).toISOString()).toEqual(
156
+ newConnectAt.toISOString()
157
+ );
158
+ expect(new Date((sdk[0].jwt_exp! as unknown as DateTimeValue).iso8601Representation).toISOString()).toEqual(
159
+ jwtExp.toISOString()
160
+ );
275
161
  expect(sdk[0].disconnected_at).toBeNull();
276
162
  const cleaned = removeVolatileFields(sdk);
277
163
  expect(cleaned).toMatchSnapshot();
@@ -279,60 +165,68 @@ describe('Connection report storage', async () => {
279
165
 
280
166
  it('Should update a connection event and make it disconnected', async () => {
281
167
  const disconnectAt = new Date(
282
- now.getFullYear(),
283
- now.getMonth(),
284
- now.getDate(),
285
- now.getHours(),
286
- now.getMinutes() + 20
168
+ dates.now.getFullYear(),
169
+ dates.now.getMonth(),
170
+ dates.now.getDate(),
171
+ dates.now.getHours(),
172
+ dates.now.getMinutes() + 20
287
173
  );
288
174
  const jwtExp = new Date(disconnectAt.getFullYear(), disconnectAt.getMonth(), disconnectAt.getDate() + 1);
289
175
 
290
176
  await factory.reportClientDisconnection({
291
177
  disconnected_at: disconnectAt,
292
178
  jwt_exp: jwtExp,
293
- client_id: user_three.client_id,
294
- user_id: user_three.user_id,
295
- user_agent: user_three.user_agent,
296
- connected_at: yesterday
179
+ client_id: userData.user_three.client_id,
180
+ user_id: userData.user_three.user_id,
181
+ user_agent: userData.user_three.user_agent,
182
+ connected_at: dates.yesterday
297
183
  });
298
184
 
299
185
  const sdk = await factory.db
300
- .sql`SELECT * FROM connection_report_events WHERE user_id = ${{ type: 'varchar', value: user_three.user_id }}`.rows<event_types.ClientConnection>();
186
+ .sql`SELECT * FROM connection_report_events WHERE user_id = ${{ type: 'varchar', value: userData.user_three.user_id }}`.rows<event_types.ClientConnection>();
301
187
  expect(sdk).toHaveLength(1);
302
- expect(new Date(sdk[0].disconnected_at!).toISOString()).toEqual(disconnectAt.toISOString());
188
+ console.log(sdk[0]);
189
+ expect(new Date((sdk[0].disconnected_at! as unknown as DateTimeValue).iso8601Representation).toISOString()).toEqual(
190
+ disconnectAt.toISOString()
191
+ );
303
192
  const cleaned = removeVolatileFields(sdk);
304
193
  expect(cleaned).toMatchSnapshot();
305
194
  });
306
195
 
307
196
  it('Should create a connection event if its after a day', async () => {
308
- const newConnectAt = new Date(now.getFullYear(), now.getMonth(), now.getDate() + 1, now.getHours());
197
+ const newConnectAt = new Date(
198
+ dates.now.getFullYear(),
199
+ dates.now.getMonth(),
200
+ dates.now.getDate() + 1,
201
+ dates.now.getHours()
202
+ );
309
203
  const jwtExp = new Date(newConnectAt.getFullYear(), newConnectAt.getMonth(), newConnectAt.getDate() + 1);
310
204
 
311
205
  await factory.reportClientConnection({
312
- sdk: user_week.sdk,
206
+ sdk: userData.user_week.sdk,
313
207
  connected_at: newConnectAt,
314
208
  jwt_exp: jwtExp,
315
- client_id: user_week.client_id,
316
- user_id: user_week.user_id,
317
- user_agent: user_week.user_agent
209
+ client_id: userData.user_week.client_id,
210
+ user_id: userData.user_week.user_id,
211
+ user_agent: userData.user_week.user_agent
318
212
  });
319
213
 
320
214
  const sdk = await factory.db
321
- .sql`SELECT * FROM connection_report_events WHERE user_id = ${{ type: 'varchar', value: user_week.user_id }}`.rows<event_types.ClientConnection>();
215
+ .sql`SELECT * FROM connection_report_events WHERE user_id = ${{ type: 'varchar', value: userData.user_week.user_id }}`.rows<event_types.ClientConnection>();
322
216
  expect(sdk).toHaveLength(2);
323
217
  const cleaned = removeVolatileFields(sdk);
324
218
  expect(cleaned).toMatchSnapshot();
325
219
  });
326
220
 
327
221
  it('Should delete rows older than specified range', async () => {
328
- await deleteData();
329
- await loadData();
222
+ await deleteData(factory);
223
+ await loadData(userData, factory);
330
224
  await factory.deleteOldConnectionData({
331
- date: weekAgo
225
+ date: dates.weekAgo
332
226
  });
333
227
  const sdk = await factory.getClientConnectionReports({
334
- start: monthAgo,
335
- end: now
228
+ start: dates.monthAgo,
229
+ end: dates.now
336
230
  });
337
231
  expect(sdk).toMatchSnapshot();
338
232
  });
package/test/src/util.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  import path from 'path';
2
2
  import { fileURLToPath } from 'url';
3
- import { normalizePostgresStorageConfig, PostgresMigrationAgent, postgresTestSetup } from '../../src/index.js';
3
+ import { normalizePostgresStorageConfig, PostgresMigrationAgent } from '../../src/index.js';
4
4
  import { env } from './env.js';
5
+ import { postgresTestSetup } from '../../src/utils/test-utils.js';
5
6
 
6
7
  const __filename = fileURLToPath(import.meta.url);
7
8
  const __dirname = path.dirname(__filename);
@@ -1 +0,0 @@
1
- {"version":3,"file":"PostgresTestStorageFactoryGenerator.js","sourceRoot":"","sources":["../../src/storage/PostgresTestStorageFactoryGenerator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAE,SAAS,EAAiE,MAAM,yBAAyB,CAAC;AACnH,OAAO,EAAE,sBAAsB,EAAE,MAAM,yCAAyC,CAAC;AACjF,OAAO,EAAE,8BAA8B,EAAgC,MAAM,mBAAmB,CAAC;AACjG,OAAO,EAAE,4BAA4B,EAAE,MAAM,mCAAmC,CAAC;AACjF,OAAO,EAAE,4BAA4B,EAAE,MAAM,mCAAmC,CAAC;AAWjF,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,cAA0C,EAAE,EAAE;IAC9E,MAAM,WAAW,GAAG;QAClB,IAAI,EAAE,YAAqB;QAC3B,GAAG,EAAE,cAAc,CAAC,GAAG;QACvB,OAAO,EAAE,SAAkB;KAC5B,CAAC;IAEF,MAAM,uBAAuB,GAAG,8BAA8B,CAAC,WAAW,CAAC,CAAC;IAE5E,MAAM,OAAO,GAAG,KAAK,EAAE,SAAyC,EAAE,EAAE;;;YAClE,MAAY,gBA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