@powersync/service-module-mongodb-storage 0.0.0-dev-20250825132649 → 0.0.0-dev-20250827091123
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 +9 -7
- package/dist/storage/MongoReportStorage.js +6 -7
- package/dist/storage/MongoReportStorage.js.map +1 -1
- package/package.json +8 -8
- package/src/storage/MongoReportStorage.ts +6 -7
- package/test/src/__snapshots__/connection-report-storage.test.ts.snap +44 -57
- package/test/src/connection-report-storage.test.ts +67 -178
- package/tsconfig.tsbuildinfo +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @powersync/service-module-mongodb-storage
|
|
2
2
|
|
|
3
|
-
## 0.0.0-dev-
|
|
3
|
+
## 0.0.0-dev-20250827091123
|
|
4
4
|
|
|
5
5
|
### Patch Changes
|
|
6
6
|
|
|
@@ -15,15 +15,17 @@
|
|
|
15
15
|
- Updated dependencies [29a368e]
|
|
16
16
|
- Updated dependencies [f1d187b]
|
|
17
17
|
- Updated dependencies [0fad466]
|
|
18
|
+
- Updated dependencies [5284fb5]
|
|
19
|
+
- Updated dependencies [5284fb5]
|
|
18
20
|
- Updated dependencies [a700ec9]
|
|
19
21
|
- Updated dependencies [060b829]
|
|
20
22
|
- Updated dependencies [d49bebe]
|
|
21
|
-
- @powersync/service-sync-rules@0.0.0-dev-
|
|
22
|
-
- @powersync/service-core@0.0.0-dev-
|
|
23
|
-
- @powersync/service-types@0.0.0-dev-
|
|
24
|
-
- @powersync/lib-services-framework@0.0.0-dev-
|
|
25
|
-
- @powersync/lib-service-mongodb@0.0.0-dev-
|
|
26
|
-
- @powersync/service-jsonbig@0.0.0-dev-
|
|
23
|
+
- @powersync/service-sync-rules@0.0.0-dev-20250827091123
|
|
24
|
+
- @powersync/service-core@0.0.0-dev-20250827091123
|
|
25
|
+
- @powersync/service-types@0.0.0-dev-20250827091123
|
|
26
|
+
- @powersync/lib-services-framework@0.0.0-dev-20250827091123
|
|
27
|
+
- @powersync/lib-service-mongodb@0.0.0-dev-20250827091123
|
|
28
|
+
- @powersync/service-jsonbig@0.0.0-dev-20250827091123
|
|
27
29
|
|
|
28
30
|
## 0.11.0
|
|
29
31
|
|
|
@@ -79,10 +79,10 @@ export class MongoReportStorage {
|
|
|
79
79
|
// No-op
|
|
80
80
|
}
|
|
81
81
|
parseJsDate(date) {
|
|
82
|
-
const year = date.
|
|
83
|
-
const month = date.
|
|
84
|
-
const today = date.
|
|
85
|
-
const day = date.
|
|
82
|
+
const year = date.getUTCFullYear();
|
|
83
|
+
const month = date.getUTCMonth();
|
|
84
|
+
const today = date.getUTCDate();
|
|
85
|
+
const day = date.getUTCDay();
|
|
86
86
|
return {
|
|
87
87
|
year,
|
|
88
88
|
month,
|
|
@@ -145,9 +145,8 @@ export class MongoReportStorage {
|
|
|
145
145
|
user_id: userId,
|
|
146
146
|
client_id: clientId,
|
|
147
147
|
connected_at: {
|
|
148
|
-
|
|
149
|
-
$
|
|
150
|
-
$lt: new Date(year, month, nextDay)
|
|
148
|
+
$gte: new Date(Date.UTC(year, month, today)),
|
|
149
|
+
$lt: new Date(Date.UTC(year, month, nextDay))
|
|
151
150
|
}
|
|
152
151
|
};
|
|
153
152
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MongoReportStorage.js","sourceRoot":"","sources":["../../src/storage/MongoReportStorage.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,MAAM,EAAE,MAAM,mCAAmC,CAAC;AAE3D,MAAM,OAAO,kBAAkB;IACZ,MAAM,CAAoB;IAC3B,EAAE,CAAiB;IAEnC,YAAY,EAAkB;QAC5B,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC,MAAM,CAAC;QACxB,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;IACf,CAAC;IACD,KAAK,CAAC,uBAAuB,CAAC,IAAyC;QACrE,MAAM,EAAE,IAAI,EAAE,GAAG,IAAI,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MAAM,EAAE;gBACN,eAAe,EAAE,EAAE;aACpB;SACF,EACD;YACE,MAAM,EAAE,IAAI;SACb,CACF,CAAC;IACJ,CAAC;IACD,KAAK,CAAC,yBAAyB,CAAC,IAA8C;QAC5E,MAAM,EAAE,YAAY,EAAE,OAAO,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC;QAClD,MAAM,IAAI,CAAC,EAAE,CAAC,wBAAwB,CAAC,gBAAgB,CACrD;YACE,SAAS;YACT,OAAO;YACP,YAAY;SACb,EACD;YACE,IAAI,EAAE;gBACJ,eAAe,EAAE,IAAI,CAAC,eAAe;aACtC;YACD,MAAM,EAAE;gBACN,OAAO,EAAE,EAAE;aACZ;SACF,CACF,CAAC;IACJ,CAAC;IACD,KAAK,CAAC,mBAAmB;QACvB,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,EAAE,CAAC,wBAAwB;aAClD,SAAS,CAA6C;YACrD;gBACE,MAAM,EAAE;oBACN,eAAe,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE;oBACnC,OAAO,EAAE,EAAE,GAAG,EAAE,IAAI,IAAI,EAAE,EAAE;iBAC7B;aACF;YACD,IAAI,CAAC,wBAAwB,EAAE;YAC/B,IAAI,CAAC,0BAA0B,EAAE;SAClC,CAAC;aACD,OAAO,EAAE,CAAC;QACb,OAAO,MAAM,CAAC,CAAC,CAAC,CAAC;IACnB,CAAC;IAED,KAAK,CAAC,CAAC,MAAM,CAAC,YAAY,CAAC;QACzB,QAAQ;IACV,CAAC;IAEO,WAAW,CAAC,IAAU;QAC5B,MAAM,IAAI,GAAG,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"MongoReportStorage.js","sourceRoot":"","sources":["../../src/storage/MongoReportStorage.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,MAAM,EAAE,MAAM,mCAAmC,CAAC;AAE3D,MAAM,OAAO,kBAAkB;IACZ,MAAM,CAAoB;IAC3B,EAAE,CAAiB;IAEnC,YAAY,EAAkB;QAC5B,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AAI,CAAC,WAAW,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC;QAC5D,MAAM,OAAO,GAAG,KAAK,GAAG,CAAC,CAAC;QAC1B,OAAO;YACL,OAAO,EAAE,MAAM;YACf,SAAS,EAAE,QAAQ;YACnB,YAAY,EAAE;gBACZ,IAAI,EAAE,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;gBAC5C,GAAG,EAAE,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;aAC9C;SACF,CAAC;IACJ,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@powersync/service-module-mongodb-storage",
|
|
3
3
|
"repository": "https://github.com/powersync-ja/powersync-service",
|
|
4
4
|
"types": "dist/index.d.ts",
|
|
5
|
-
"version": "0.0.0-dev-
|
|
5
|
+
"version": "0.0.0-dev-20250827091123",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"license": "FSL-1.1-ALv2",
|
|
8
8
|
"type": "module",
|
|
@@ -27,15 +27,15 @@
|
|
|
27
27
|
"lru-cache": "^10.2.2",
|
|
28
28
|
"ts-codec": "^1.3.0",
|
|
29
29
|
"uuid": "^11.1.0",
|
|
30
|
-
"@powersync/lib-service-mongodb": "0.0.0-dev-
|
|
31
|
-
"@powersync/lib-services-framework": "0.0.0-dev-
|
|
32
|
-
"@powersync/service-core": "0.0.0-dev-
|
|
33
|
-
"@powersync/service-types": "0.0.0-dev-
|
|
34
|
-
"@powersync/service-jsonbig": "0.0.0-dev-
|
|
35
|
-
"@powersync/service-sync-rules": "0.0.0-dev-
|
|
30
|
+
"@powersync/lib-service-mongodb": "0.0.0-dev-20250827091123",
|
|
31
|
+
"@powersync/lib-services-framework": "0.0.0-dev-20250827091123",
|
|
32
|
+
"@powersync/service-core": "0.0.0-dev-20250827091123",
|
|
33
|
+
"@powersync/service-types": "0.0.0-dev-20250827091123",
|
|
34
|
+
"@powersync/service-jsonbig": "0.0.0-dev-20250827091123",
|
|
35
|
+
"@powersync/service-sync-rules": "0.0.0-dev-20250827091123"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@powersync/service-core-tests": "0.0.0-dev-
|
|
38
|
+
"@powersync/service-core-tests": "0.0.0-dev-20250827091123"
|
|
39
39
|
},
|
|
40
40
|
"scripts": {
|
|
41
41
|
"build": "tsc -b",
|
|
@@ -100,10 +100,10 @@ export class MongoReportStorage implements storage.ReportStorage {
|
|
|
100
100
|
}
|
|
101
101
|
|
|
102
102
|
private parseJsDate(date: Date) {
|
|
103
|
-
const year = date.
|
|
104
|
-
const month = date.
|
|
105
|
-
const today = date.
|
|
106
|
-
const day = date.
|
|
103
|
+
const year = date.getUTCFullYear();
|
|
104
|
+
const month = date.getUTCMonth();
|
|
105
|
+
const today = date.getUTCDate();
|
|
106
|
+
const day = date.getUTCDay();
|
|
107
107
|
return {
|
|
108
108
|
year,
|
|
109
109
|
month,
|
|
@@ -169,9 +169,8 @@ export class MongoReportStorage implements storage.ReportStorage {
|
|
|
169
169
|
user_id: userId,
|
|
170
170
|
client_id: clientId,
|
|
171
171
|
connected_at: {
|
|
172
|
-
|
|
173
|
-
$
|
|
174
|
-
$lt: new Date(year, month, nextDay)
|
|
172
|
+
$gte: new Date(Date.UTC(year, month, today)),
|
|
173
|
+
$lt: new Date(Date.UTC(year, month, nextDay))
|
|
175
174
|
}
|
|
176
175
|
};
|
|
177
176
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
|
2
2
|
|
|
3
|
-
exports[`
|
|
3
|
+
exports[`Connection reporting storage > Should create a connection report if its after a day 1`] = `
|
|
4
4
|
[
|
|
5
5
|
{
|
|
6
6
|
"client_id": "client_week",
|
|
@@ -17,7 +17,7 @@ exports[`SDK reporting storage > Should create a connection report if its after
|
|
|
17
17
|
]
|
|
18
18
|
`;
|
|
19
19
|
|
|
20
|
-
exports[`
|
|
20
|
+
exports[`Connection reporting storage > Should delete rows older than specified range 1`] = `
|
|
21
21
|
{
|
|
22
22
|
"sdks": [
|
|
23
23
|
{
|
|
@@ -55,43 +55,29 @@ exports[`SDK reporting storage > Should delete rows older than specified range 1
|
|
|
55
55
|
}
|
|
56
56
|
`;
|
|
57
57
|
|
|
58
|
-
exports[`
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
"clients": 1,
|
|
68
|
-
"sdk": "powersync-js/1.21.1",
|
|
69
|
-
"users": 1,
|
|
70
|
-
},
|
|
71
|
-
{
|
|
72
|
-
"clients": 1,
|
|
73
|
-
"sdk": "unknown",
|
|
74
|
-
"users": 1,
|
|
75
|
-
},
|
|
76
|
-
],
|
|
77
|
-
"users": 2,
|
|
78
|
-
}
|
|
58
|
+
exports[`Connection reporting storage > Should update a connected connection report and make it disconnected 1`] = `
|
|
59
|
+
[
|
|
60
|
+
{
|
|
61
|
+
"client_id": "client_three",
|
|
62
|
+
"sdk": "powersync-js/1.21.2",
|
|
63
|
+
"user_agent": "powersync-js/1.21.0 powersync-web Firefox/141 linux",
|
|
64
|
+
"user_id": "user_three",
|
|
65
|
+
},
|
|
66
|
+
]
|
|
79
67
|
`;
|
|
80
68
|
|
|
81
|
-
exports[`
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
"users": 1,
|
|
91
|
-
}
|
|
69
|
+
exports[`Connection reporting storage > Should update a connection report if its within a day 1`] = `
|
|
70
|
+
[
|
|
71
|
+
{
|
|
72
|
+
"client_id": "client_one",
|
|
73
|
+
"sdk": "powersync-dart/1.6.4",
|
|
74
|
+
"user_agent": "powersync-dart/1.6.4 Dart (flutter-web) Chrome/128 android",
|
|
75
|
+
"user_id": "user_one",
|
|
76
|
+
},
|
|
77
|
+
]
|
|
92
78
|
`;
|
|
93
79
|
|
|
94
|
-
exports[`
|
|
80
|
+
exports[`Report storage tests > Should show connection report data for user over the past day 1`] = `
|
|
95
81
|
{
|
|
96
82
|
"sdks": [
|
|
97
83
|
{
|
|
@@ -119,7 +105,7 @@ exports[`SDK reporting storage > Should show connection report data for user ove
|
|
|
119
105
|
}
|
|
120
106
|
`;
|
|
121
107
|
|
|
122
|
-
exports[`
|
|
108
|
+
exports[`Report storage tests > Should show connection report data for user over the past month 1`] = `
|
|
123
109
|
{
|
|
124
110
|
"sdks": [
|
|
125
111
|
{
|
|
@@ -167,7 +153,7 @@ exports[`SDK reporting storage > Should show connection report data for user ove
|
|
|
167
153
|
}
|
|
168
154
|
`;
|
|
169
155
|
|
|
170
|
-
exports[`
|
|
156
|
+
exports[`Report storage tests > Should show connection report data for user over the past week 1`] = `
|
|
171
157
|
{
|
|
172
158
|
"sdks": [
|
|
173
159
|
{
|
|
@@ -205,24 +191,25 @@ exports[`SDK reporting storage > Should show connection report data for user ove
|
|
|
205
191
|
}
|
|
206
192
|
`;
|
|
207
193
|
|
|
208
|
-
exports[`
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
194
|
+
exports[`Report storage tests > Should show currently connected users 1`] = `
|
|
195
|
+
{
|
|
196
|
+
"sdks": [
|
|
197
|
+
{
|
|
198
|
+
"clients": 1,
|
|
199
|
+
"sdk": "powersync-dart/1.6.4",
|
|
200
|
+
"users": 1,
|
|
201
|
+
},
|
|
202
|
+
{
|
|
203
|
+
"clients": 1,
|
|
204
|
+
"sdk": "powersync-js/1.21.1",
|
|
205
|
+
"users": 1,
|
|
206
|
+
},
|
|
207
|
+
{
|
|
208
|
+
"clients": 1,
|
|
209
|
+
"sdk": "unknown",
|
|
210
|
+
"users": 1,
|
|
211
|
+
},
|
|
212
|
+
],
|
|
213
|
+
"users": 2,
|
|
214
|
+
}
|
|
228
215
|
`;
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
|
|
2
2
|
import { INITIALIZED_MONGO_REPORT_STORAGE_FACTORY } from './util.js';
|
|
3
|
+
import { register, ReportUserData } from '@powersync/service-core-tests';
|
|
3
4
|
import { event_types } from '@powersync/service-types';
|
|
5
|
+
import { MongoReportStorage } from '@module/storage/MongoReportStorage.js';
|
|
6
|
+
|
|
7
|
+
const userData = register.REPORT_TEST_USERS;
|
|
8
|
+
const dates = register.REPORT_TEST_DATES;
|
|
9
|
+
const factory = await INITIALIZED_MONGO_REPORT_STORAGE_FACTORY();
|
|
4
10
|
|
|
5
11
|
function removeVolatileFields(
|
|
6
12
|
sdks: event_types.ClientConnection[]
|
|
@@ -13,168 +19,70 @@ function removeVolatileFields(
|
|
|
13
19
|
});
|
|
14
20
|
}
|
|
15
21
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const nowAdd5minutes = new Date(
|
|
20
|
-
now.getFullYear(),
|
|
21
|
-
now.getMonth(),
|
|
22
|
-
now.getDate(),
|
|
23
|
-
now.getHours(),
|
|
24
|
-
now.getMinutes() + 5
|
|
25
|
-
);
|
|
26
|
-
const nowLess5minutes = new Date(
|
|
27
|
-
now.getFullYear(),
|
|
28
|
-
now.getMonth(),
|
|
29
|
-
now.getDate(),
|
|
30
|
-
now.getHours(),
|
|
31
|
-
now.getMinutes() - 5
|
|
32
|
-
);
|
|
33
|
-
const dayAgo = new Date(now.getFullYear(), now.getMonth(), now.getDate() - 1, now.getHours());
|
|
34
|
-
const yesterday = new Date(now.getFullYear(), now.getMonth(), now.getDate() - 1);
|
|
35
|
-
const weekAgo = new Date(now.getFullYear(), now.getMonth(), now.getDate() - 7);
|
|
36
|
-
const monthAgo = new Date(now.getFullYear(), now.getMonth() - 1, now.getDate());
|
|
37
|
-
const user_one = {
|
|
38
|
-
user_id: 'user_one',
|
|
39
|
-
client_id: 'client_one',
|
|
40
|
-
connected_at: now,
|
|
41
|
-
sdk: 'powersync-dart/1.6.4',
|
|
42
|
-
user_agent: 'powersync-dart/1.6.4 Dart (flutter-web) Chrome/128 android',
|
|
43
|
-
jwt_exp: nowAdd5minutes
|
|
44
|
-
};
|
|
45
|
-
const user_two = {
|
|
46
|
-
user_id: 'user_two',
|
|
47
|
-
client_id: 'client_two',
|
|
48
|
-
connected_at: nowLess5minutes,
|
|
49
|
-
sdk: 'powersync-js/1.21.1',
|
|
50
|
-
user_agent: 'powersync-js/1.21.0 powersync-web Chromium/138 linux',
|
|
51
|
-
jwt_exp: nowAdd5minutes
|
|
52
|
-
};
|
|
53
|
-
const user_three = {
|
|
54
|
-
user_id: 'user_three',
|
|
55
|
-
client_id: 'client_three',
|
|
56
|
-
connected_at: yesterday,
|
|
57
|
-
sdk: 'powersync-js/1.21.2',
|
|
58
|
-
user_agent: 'powersync-js/1.21.0 powersync-web Firefox/141 linux',
|
|
59
|
-
disconnected_at: yesterday
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
const user_four = {
|
|
63
|
-
user_id: 'user_four',
|
|
64
|
-
client_id: 'client_four',
|
|
65
|
-
connected_at: now,
|
|
66
|
-
sdk: 'powersync-js/1.21.4',
|
|
67
|
-
user_agent: 'powersync-js/1.21.0 powersync-web Firefox/141 linux',
|
|
68
|
-
jwt_exp: nowLess5minutes
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
const user_old = {
|
|
72
|
-
user_id: 'user_one',
|
|
73
|
-
client_id: '',
|
|
74
|
-
connected_at: now,
|
|
75
|
-
sdk: 'unknown',
|
|
76
|
-
user_agent: 'Dart (flutter-web) Chrome/128 android',
|
|
77
|
-
jwt_exp: nowAdd5minutes
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
const user_week = {
|
|
81
|
-
user_id: 'user_week',
|
|
82
|
-
client_id: 'client_week',
|
|
83
|
-
connected_at: weekAgo,
|
|
84
|
-
sdk: 'powersync-js/1.24.5',
|
|
85
|
-
user_agent: 'powersync-js/1.21.0 powersync-web Firefox/141 linux',
|
|
86
|
-
disconnected_at: weekAgo
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
const user_month = {
|
|
90
|
-
user_id: 'user_month',
|
|
91
|
-
client_id: 'client_month',
|
|
92
|
-
connected_at: monthAgo,
|
|
93
|
-
sdk: 'powersync-js/1.23.6',
|
|
94
|
-
user_agent: 'powersync-js/1.23.0 powersync-web Firefox/141 linux',
|
|
95
|
-
disconnected_at: monthAgo
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
const user_expired = {
|
|
99
|
-
user_id: 'user_expired',
|
|
100
|
-
client_id: 'client_expired',
|
|
101
|
-
connected_at: monthAgo,
|
|
102
|
-
sdk: 'powersync-js/1.23.7',
|
|
103
|
-
user_agent: 'powersync-js/1.23.0 powersync-web Firefox/141 linux',
|
|
104
|
-
jwt_exp: monthAgo
|
|
105
|
-
};
|
|
22
|
+
async function loadData(data: ReportUserData, factory: MongoReportStorage) {
|
|
23
|
+
await factory.db.connection_report_events.insertMany(Object.values(data));
|
|
24
|
+
}
|
|
106
25
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
user_two,
|
|
111
|
-
user_three,
|
|
112
|
-
user_four,
|
|
113
|
-
user_week,
|
|
114
|
-
user_month,
|
|
115
|
-
user_expired,
|
|
116
|
-
user_old
|
|
117
|
-
]);
|
|
118
|
-
}
|
|
26
|
+
async function deleteData(factory: MongoReportStorage) {
|
|
27
|
+
await factory.db.connection_report_events.deleteMany();
|
|
28
|
+
}
|
|
119
29
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
30
|
+
beforeAll(async () => {
|
|
31
|
+
await loadData(userData, factory);
|
|
32
|
+
});
|
|
33
|
+
afterAll(async () => {
|
|
34
|
+
await deleteData(factory);
|
|
35
|
+
});
|
|
123
36
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
37
|
+
describe('Report storage tests', async () => {
|
|
38
|
+
await register.registerReportTests(factory);
|
|
39
|
+
});
|
|
127
40
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
41
|
+
describe('Connection reporting storage', async () => {
|
|
42
|
+
it('Should create a connection report if its after a day', async () => {
|
|
43
|
+
const newConnectAt = new Date(
|
|
44
|
+
dates.now.getFullYear(),
|
|
45
|
+
dates.now.getMonth(),
|
|
46
|
+
dates.now.getDate() + 1,
|
|
47
|
+
dates.now.getHours()
|
|
48
|
+
);
|
|
49
|
+
const jwtExp = new Date(newConnectAt.getFullYear(), newConnectAt.getMonth(), newConnectAt.getDate() + 1);
|
|
135
50
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
it('Should show connection report data for user over the past week', async () => {
|
|
144
|
-
const sdk = await factory.getClientConnectionReports({
|
|
145
|
-
start: weekAgo,
|
|
146
|
-
end: now
|
|
147
|
-
});
|
|
148
|
-
expect(sdk).toMatchSnapshot();
|
|
149
|
-
});
|
|
150
|
-
it('Should show connection report data for user over the past day', async () => {
|
|
151
|
-
const sdk = await factory.getClientConnectionReports({
|
|
152
|
-
start: dayAgo,
|
|
153
|
-
end: now
|
|
51
|
+
await factory.reportClientConnection({
|
|
52
|
+
sdk: userData.user_week.sdk,
|
|
53
|
+
connected_at: newConnectAt,
|
|
54
|
+
jwt_exp: jwtExp,
|
|
55
|
+
client_id: userData.user_week.client_id,
|
|
56
|
+
user_id: userData.user_week.user_id,
|
|
57
|
+
user_agent: userData.user_week.user_agent
|
|
154
58
|
});
|
|
155
|
-
|
|
59
|
+
|
|
60
|
+
const sdk = await factory.db.connection_report_events.find({ user_id: userData.user_week.user_id }).toArray();
|
|
61
|
+
expect(sdk).toHaveLength(2);
|
|
62
|
+
const cleaned = removeVolatileFields(sdk);
|
|
63
|
+
expect(cleaned).toMatchSnapshot();
|
|
156
64
|
});
|
|
157
65
|
|
|
158
66
|
it('Should update a connection report if its within a day', async () => {
|
|
159
67
|
const newConnectAt = new Date(
|
|
160
|
-
now.getFullYear(),
|
|
161
|
-
now.getMonth(),
|
|
162
|
-
now.getDate(),
|
|
163
|
-
now.getHours(),
|
|
164
|
-
now.getMinutes() + 20
|
|
68
|
+
dates.now.getFullYear(),
|
|
69
|
+
dates.now.getMonth(),
|
|
70
|
+
dates.now.getDate(),
|
|
71
|
+
dates.now.getHours(),
|
|
72
|
+
dates.now.getMinutes() + 20
|
|
165
73
|
);
|
|
166
74
|
const jwtExp = new Date(newConnectAt.getFullYear(), newConnectAt.getMonth(), newConnectAt.getDate() + 1);
|
|
167
75
|
await factory.reportClientConnection({
|
|
168
|
-
sdk: user_one.sdk,
|
|
76
|
+
sdk: userData.user_one.sdk,
|
|
169
77
|
connected_at: newConnectAt,
|
|
170
78
|
jwt_exp: jwtExp,
|
|
171
|
-
client_id: user_one.client_id,
|
|
172
|
-
user_id: user_one.user_id,
|
|
173
|
-
user_agent: user_one.user_agent
|
|
79
|
+
client_id: userData.user_one.client_id,
|
|
80
|
+
user_id: userData.user_one.user_id,
|
|
81
|
+
user_agent: userData.user_one.user_agent
|
|
174
82
|
});
|
|
175
83
|
|
|
176
84
|
const sdk = await factory.db.connection_report_events
|
|
177
|
-
.find({ user_id: user_one.user_id, client_id: user_one.client_id })
|
|
85
|
+
.find({ user_id: userData.user_one.user_id, client_id: userData.user_one.client_id })
|
|
178
86
|
.toArray();
|
|
179
87
|
expect(sdk).toHaveLength(1);
|
|
180
88
|
expect(new Date(sdk[0].connected_at)).toEqual(newConnectAt);
|
|
@@ -186,58 +94,39 @@ describe('SDK reporting storage', async () => {
|
|
|
186
94
|
|
|
187
95
|
it('Should update a connected connection report and make it disconnected', async () => {
|
|
188
96
|
const disconnectAt = new Date(
|
|
189
|
-
now.getFullYear(),
|
|
190
|
-
now.getMonth(),
|
|
191
|
-
now.getDate(),
|
|
192
|
-
now.getHours(),
|
|
193
|
-
now.getMinutes() + 20
|
|
97
|
+
dates.now.getFullYear(),
|
|
98
|
+
dates.now.getMonth(),
|
|
99
|
+
dates.now.getDate(),
|
|
100
|
+
dates.now.getHours(),
|
|
101
|
+
dates.now.getMinutes() + 20
|
|
194
102
|
);
|
|
195
103
|
const jwtExp = new Date(disconnectAt.getFullYear(), disconnectAt.getMonth(), disconnectAt.getDate() + 1);
|
|
196
104
|
|
|
197
105
|
await factory.reportClientDisconnection({
|
|
198
106
|
disconnected_at: disconnectAt,
|
|
199
107
|
jwt_exp: jwtExp,
|
|
200
|
-
client_id: user_three.client_id,
|
|
201
|
-
user_id: user_three.user_id,
|
|
202
|
-
user_agent: user_three.user_agent,
|
|
203
|
-
connected_at: user_three.connected_at
|
|
108
|
+
client_id: userData.user_three.client_id,
|
|
109
|
+
user_id: userData.user_three.user_id,
|
|
110
|
+
user_agent: userData.user_three.user_agent,
|
|
111
|
+
connected_at: userData.user_three.connected_at
|
|
204
112
|
});
|
|
205
113
|
|
|
206
|
-
const sdk = await factory.db.connection_report_events.find({ user_id: user_three.user_id }).toArray();
|
|
114
|
+
const sdk = await factory.db.connection_report_events.find({ user_id: userData.user_three.user_id }).toArray();
|
|
207
115
|
expect(sdk).toHaveLength(1);
|
|
208
116
|
expect(new Date(sdk[0].disconnected_at!)).toEqual(disconnectAt);
|
|
209
117
|
const cleaned = removeVolatileFields(sdk);
|
|
210
118
|
expect(cleaned).toMatchSnapshot();
|
|
211
119
|
});
|
|
212
120
|
|
|
213
|
-
it('Should create a connection report if its after a day', async () => {
|
|
214
|
-
const newConnectAt = new Date(now.getFullYear(), now.getMonth(), now.getDate() + 1, now.getHours());
|
|
215
|
-
const jwtExp = new Date(newConnectAt.getFullYear(), newConnectAt.getMonth(), newConnectAt.getDate() + 1);
|
|
216
|
-
|
|
217
|
-
await factory.reportClientConnection({
|
|
218
|
-
sdk: user_week.sdk,
|
|
219
|
-
connected_at: newConnectAt,
|
|
220
|
-
jwt_exp: jwtExp,
|
|
221
|
-
client_id: user_week.client_id,
|
|
222
|
-
user_id: user_week.user_id,
|
|
223
|
-
user_agent: user_week.user_agent
|
|
224
|
-
});
|
|
225
|
-
|
|
226
|
-
const sdk = await factory.db.connection_report_events.find({ user_id: user_week.user_id }).toArray();
|
|
227
|
-
expect(sdk).toHaveLength(2);
|
|
228
|
-
const cleaned = removeVolatileFields(sdk);
|
|
229
|
-
expect(cleaned).toMatchSnapshot();
|
|
230
|
-
});
|
|
231
|
-
|
|
232
121
|
it('Should delete rows older than specified range', async () => {
|
|
233
|
-
await deleteData();
|
|
234
|
-
await loadData();
|
|
122
|
+
await deleteData(factory);
|
|
123
|
+
await loadData(userData, factory);
|
|
235
124
|
await factory.deleteOldConnectionData({
|
|
236
|
-
date: weekAgo
|
|
125
|
+
date: dates.weekAgo
|
|
237
126
|
});
|
|
238
127
|
const sdk = await factory.getClientConnectionReports({
|
|
239
|
-
start: monthAgo,
|
|
240
|
-
end: now
|
|
128
|
+
start: dates.monthAgo,
|
|
129
|
+
end: dates.now
|
|
241
130
|
});
|
|
242
131
|
expect(sdk).toMatchSnapshot();
|
|
243
132
|
});
|