@socialgouv/matomo-postgres 1.5.0 → 1.5.2-beta.1
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/README.md +13 -12
- package/bin/index.js +1 -1
- package/package.json +24 -12
- package/.github/workflows/release.yml +0 -33
- package/.github/workflows/test.yml +0 -27
- package/docker/Dockerfile +0 -43
- package/docker/initdb.sh +0 -13
- package/docker-compose.yml +0 -18
- package/header.png +0 -0
- package/initial.sql +0 -73
- package/jsconfig.json +0 -10
- package/renovate.json +0 -6
- package/src/__tests__/__snapshots__/importDate.test.js.snap +0 -389
- package/src/__tests__/__snapshots__/importEvent.test.js.snap +0 -359
- package/src/__tests__/__snapshots__/index.test.js.snap +0 -56
- package/src/__tests__/importDate.test.js +0 -133
- package/src/__tests__/importEvent.test.js +0 -22
- package/src/__tests__/index.test.js +0 -194
- package/src/__tests__/visit.json +0 -103
- package/src/config.js +0 -9
- package/src/createTable.js +0 -83
- package/src/importDate.js +0 -105
- package/src/importEvent.js +0 -108
- package/src/index.js +0 -79
- package/types/index.d.ts +0 -31
- package/types/matomo.d.ts +0 -214
|
@@ -1,359 +0,0 @@
|
|
|
1
|
-
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
-
|
|
3
|
-
exports[`importEvent: should extract events from matomo visit actionsDetails and create insert queries 1`] = `
|
|
4
|
-
Array [
|
|
5
|
-
Object {
|
|
6
|
-
"action_eventaction": "Cart change",
|
|
7
|
-
"action_eventcategory": "Ecommerce",
|
|
8
|
-
"action_eventname": "added - Basic Wetsuit",
|
|
9
|
-
"action_eventvalue": 1,
|
|
10
|
-
"action_id": "124_0",
|
|
11
|
-
"action_timespent": 48,
|
|
12
|
-
"action_timestamp": "2021-08-20T21:35:18.000Z",
|
|
13
|
-
"action_title": "Evènement",
|
|
14
|
-
"action_type": "event",
|
|
15
|
-
"action_url": "https://dive-shop.net/products/basic-wetsuit/",
|
|
16
|
-
"actions": "2",
|
|
17
|
-
"city": "Buenos Aires",
|
|
18
|
-
"country": "Argentine",
|
|
19
|
-
"dayssincefirstvisit": "23",
|
|
20
|
-
"devicebrand": "Inconnu",
|
|
21
|
-
"devicemodel": "Générique Bureau",
|
|
22
|
-
"dimension1": "guest",
|
|
23
|
-
"dimension10": "36",
|
|
24
|
-
"dimension2": "julien",
|
|
25
|
-
"dimension3": "page",
|
|
26
|
-
"dimension4": "indonesia",
|
|
27
|
-
"dimension5": "diving",
|
|
28
|
-
"dimension6": "shop",
|
|
29
|
-
"dimension7": "v1.2.3",
|
|
30
|
-
"dimension8": "fr",
|
|
31
|
-
"dimension9": "light",
|
|
32
|
-
"idsite": "42",
|
|
33
|
-
"idvisit": "124",
|
|
34
|
-
"operatingsystemname": "Mac",
|
|
35
|
-
"referrername": "referrerName",
|
|
36
|
-
"referrertype": "referrerType",
|
|
37
|
-
"region": "Buenos Aires",
|
|
38
|
-
"serverdateprettyfirstaction": "2021-08-20T21:55:12.000Z",
|
|
39
|
-
"siteSearchKeyword": undefined,
|
|
40
|
-
"sitename": "tests",
|
|
41
|
-
"usercustomdimensions": Object {
|
|
42
|
-
"dimension1": "guest",
|
|
43
|
-
"dimension10": "36",
|
|
44
|
-
"dimension2": "julien",
|
|
45
|
-
"dimension3": "page",
|
|
46
|
-
"dimension4": "indonesia",
|
|
47
|
-
"dimension5": "diving",
|
|
48
|
-
"dimension6": "shop",
|
|
49
|
-
"dimension7": "v1.2.3",
|
|
50
|
-
"dimension8": "fr",
|
|
51
|
-
"dimension9": "light",
|
|
52
|
-
},
|
|
53
|
-
"usercustomproperties": Object {
|
|
54
|
-
"page-author": "Julien",
|
|
55
|
-
"post-age": "-430 days",
|
|
56
|
-
},
|
|
57
|
-
"userid": "24",
|
|
58
|
-
"visitduration": "300",
|
|
59
|
-
"visitorid": "visitorId",
|
|
60
|
-
"visitortype": "returningCustomer",
|
|
61
|
-
},
|
|
62
|
-
Object {
|
|
63
|
-
"action_eventaction": undefined,
|
|
64
|
-
"action_eventcategory": undefined,
|
|
65
|
-
"action_eventname": undefined,
|
|
66
|
-
"action_eventvalue": undefined,
|
|
67
|
-
"action_id": "124_1",
|
|
68
|
-
"action_timespent": "2",
|
|
69
|
-
"action_timestamp": "2021-08-20T21:30:25.000Z",
|
|
70
|
-
"action_title": "Divezone Brand Diving Boots - Divezone Store",
|
|
71
|
-
"action_type": "action",
|
|
72
|
-
"action_url": "https://dive-shop.net/products/diving-boots/",
|
|
73
|
-
"actions": "2",
|
|
74
|
-
"city": "Buenos Aires",
|
|
75
|
-
"country": "Argentine",
|
|
76
|
-
"dayssincefirstvisit": "23",
|
|
77
|
-
"devicebrand": "Inconnu",
|
|
78
|
-
"devicemodel": "Générique Bureau",
|
|
79
|
-
"dimension1": "guest",
|
|
80
|
-
"dimension10": "36",
|
|
81
|
-
"dimension2": "julien",
|
|
82
|
-
"dimension3": "page",
|
|
83
|
-
"dimension4": "indonesia",
|
|
84
|
-
"dimension5": "diving",
|
|
85
|
-
"dimension6": "shop",
|
|
86
|
-
"dimension7": "v1.2.3",
|
|
87
|
-
"dimension8": "fr",
|
|
88
|
-
"dimension9": "light",
|
|
89
|
-
"idsite": "42",
|
|
90
|
-
"idvisit": "124",
|
|
91
|
-
"operatingsystemname": "Mac",
|
|
92
|
-
"referrername": "referrerName",
|
|
93
|
-
"referrertype": "referrerType",
|
|
94
|
-
"region": "Buenos Aires",
|
|
95
|
-
"serverdateprettyfirstaction": "2021-08-20T21:55:12.000Z",
|
|
96
|
-
"siteSearchKeyword": undefined,
|
|
97
|
-
"sitename": "tests",
|
|
98
|
-
"usercustomdimensions": Object {
|
|
99
|
-
"dimension1": "guest",
|
|
100
|
-
"dimension10": "36",
|
|
101
|
-
"dimension2": "julien",
|
|
102
|
-
"dimension3": "page",
|
|
103
|
-
"dimension4": "indonesia",
|
|
104
|
-
"dimension5": "diving",
|
|
105
|
-
"dimension6": "shop",
|
|
106
|
-
"dimension7": "v1.2.3",
|
|
107
|
-
"dimension8": "fr",
|
|
108
|
-
"dimension9": "light",
|
|
109
|
-
},
|
|
110
|
-
"usercustomproperties": Object {},
|
|
111
|
-
"userid": "24",
|
|
112
|
-
"visitduration": "300",
|
|
113
|
-
"visitorid": "visitorId",
|
|
114
|
-
"visitortype": "returningCustomer",
|
|
115
|
-
},
|
|
116
|
-
Object {
|
|
117
|
-
"action_eventaction": undefined,
|
|
118
|
-
"action_eventcategory": undefined,
|
|
119
|
-
"action_eventname": undefined,
|
|
120
|
-
"action_eventvalue": undefined,
|
|
121
|
-
"action_id": "124_2",
|
|
122
|
-
"action_timespent": "2",
|
|
123
|
-
"action_timestamp": "2021-08-20T21:30:22.000Z",
|
|
124
|
-
"action_title": "Divezone Brand Diving Boots - Divezone Store",
|
|
125
|
-
"action_type": "search",
|
|
126
|
-
"action_url": "https://dive-shop.net/products/diving-boots/",
|
|
127
|
-
"actions": "2",
|
|
128
|
-
"city": "Buenos Aires",
|
|
129
|
-
"country": "Argentine",
|
|
130
|
-
"dayssincefirstvisit": "23",
|
|
131
|
-
"devicebrand": "Inconnu",
|
|
132
|
-
"devicemodel": "Générique Bureau",
|
|
133
|
-
"dimension1": "guest",
|
|
134
|
-
"dimension10": "36",
|
|
135
|
-
"dimension2": "julien",
|
|
136
|
-
"dimension3": "page",
|
|
137
|
-
"dimension4": "indonesia",
|
|
138
|
-
"dimension5": "diving",
|
|
139
|
-
"dimension6": "shop",
|
|
140
|
-
"dimension7": "v1.2.3",
|
|
141
|
-
"dimension8": "fr",
|
|
142
|
-
"dimension9": "light",
|
|
143
|
-
"idsite": "42",
|
|
144
|
-
"idvisit": "124",
|
|
145
|
-
"operatingsystemname": "Mac",
|
|
146
|
-
"referrername": "referrerName",
|
|
147
|
-
"referrertype": "referrerType",
|
|
148
|
-
"region": "Buenos Aires",
|
|
149
|
-
"serverdateprettyfirstaction": "2021-08-20T21:55:12.000Z",
|
|
150
|
-
"siteSearchKeyword": "scuba",
|
|
151
|
-
"sitename": "tests",
|
|
152
|
-
"usercustomdimensions": Object {
|
|
153
|
-
"dimension1": "guest",
|
|
154
|
-
"dimension10": "36",
|
|
155
|
-
"dimension2": "julien",
|
|
156
|
-
"dimension3": "page",
|
|
157
|
-
"dimension4": "indonesia",
|
|
158
|
-
"dimension5": "diving",
|
|
159
|
-
"dimension6": "shop",
|
|
160
|
-
"dimension7": "v1.2.3",
|
|
161
|
-
"dimension8": "fr",
|
|
162
|
-
"dimension9": "light",
|
|
163
|
-
},
|
|
164
|
-
"usercustomproperties": Object {},
|
|
165
|
-
"userid": "24",
|
|
166
|
-
"visitduration": "300",
|
|
167
|
-
"visitorid": "visitorId",
|
|
168
|
-
"visitortype": "returningCustomer",
|
|
169
|
-
},
|
|
170
|
-
]
|
|
171
|
-
`;
|
|
172
|
-
|
|
173
|
-
exports[`importEvent: should extract events from matomo visit actionsDetails and create insert queries 2`] = `
|
|
174
|
-
Array [
|
|
175
|
-
Array [
|
|
176
|
-
"insert into matomo
|
|
177
|
-
(idsite, idvisit, actions, country, region, city, operatingsystemname, devicemodel, devicebrand, visitduration, dayssincefirstvisit, visitortype, visitorid, referrertype, referrername, sitename, userid, serverdateprettyfirstaction, action_id, action_type, action_title, action_eventcategory, action_eventaction, action_eventname, action_eventvalue, action_timespent, action_timestamp, action_url, siteSearchKeyword, usercustomproperties, usercustomdimensions, dimension1, dimension2, dimension3, dimension4, dimension5, dimension6, dimension7, dimension8, dimension9, dimension10)
|
|
178
|
-
values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26, $27, $28, $29, $30, $31, $32, $33, $34, $35, $36, $37, $38, $39, $40, $41)
|
|
179
|
-
ON CONFLICT DO NOTHING",
|
|
180
|
-
Array [
|
|
181
|
-
"42",
|
|
182
|
-
"124",
|
|
183
|
-
"2",
|
|
184
|
-
"Argentine",
|
|
185
|
-
"Buenos Aires",
|
|
186
|
-
"Buenos Aires",
|
|
187
|
-
"Mac",
|
|
188
|
-
"Générique Bureau",
|
|
189
|
-
"Inconnu",
|
|
190
|
-
"300",
|
|
191
|
-
"23",
|
|
192
|
-
"returningCustomer",
|
|
193
|
-
"visitorId",
|
|
194
|
-
"referrerType",
|
|
195
|
-
"referrerName",
|
|
196
|
-
"tests",
|
|
197
|
-
"24",
|
|
198
|
-
"2021-08-20T21:55:12.000Z",
|
|
199
|
-
"124_0",
|
|
200
|
-
"event",
|
|
201
|
-
"Evènement",
|
|
202
|
-
"Ecommerce",
|
|
203
|
-
"Cart change",
|
|
204
|
-
"added - Basic Wetsuit",
|
|
205
|
-
1,
|
|
206
|
-
48,
|
|
207
|
-
"2021-08-20T21:35:18.000Z",
|
|
208
|
-
"https://dive-shop.net/products/basic-wetsuit/",
|
|
209
|
-
undefined,
|
|
210
|
-
Object {
|
|
211
|
-
"page-author": "Julien",
|
|
212
|
-
"post-age": "-430 days",
|
|
213
|
-
},
|
|
214
|
-
Object {
|
|
215
|
-
"dimension1": "guest",
|
|
216
|
-
"dimension10": "36",
|
|
217
|
-
"dimension2": "julien",
|
|
218
|
-
"dimension3": "page",
|
|
219
|
-
"dimension4": "indonesia",
|
|
220
|
-
"dimension5": "diving",
|
|
221
|
-
"dimension6": "shop",
|
|
222
|
-
"dimension7": "v1.2.3",
|
|
223
|
-
"dimension8": "fr",
|
|
224
|
-
"dimension9": "light",
|
|
225
|
-
},
|
|
226
|
-
"guest",
|
|
227
|
-
"julien",
|
|
228
|
-
"page",
|
|
229
|
-
"indonesia",
|
|
230
|
-
"diving",
|
|
231
|
-
"shop",
|
|
232
|
-
"v1.2.3",
|
|
233
|
-
"fr",
|
|
234
|
-
"light",
|
|
235
|
-
"36",
|
|
236
|
-
],
|
|
237
|
-
],
|
|
238
|
-
Array [
|
|
239
|
-
"insert into matomo
|
|
240
|
-
(idsite, idvisit, actions, country, region, city, operatingsystemname, devicemodel, devicebrand, visitduration, dayssincefirstvisit, visitortype, visitorid, referrertype, referrername, sitename, userid, serverdateprettyfirstaction, action_id, action_type, action_title, action_eventcategory, action_eventaction, action_eventname, action_eventvalue, action_timespent, action_timestamp, action_url, siteSearchKeyword, usercustomproperties, usercustomdimensions, dimension1, dimension2, dimension3, dimension4, dimension5, dimension6, dimension7, dimension8, dimension9, dimension10)
|
|
241
|
-
values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26, $27, $28, $29, $30, $31, $32, $33, $34, $35, $36, $37, $38, $39, $40, $41)
|
|
242
|
-
ON CONFLICT DO NOTHING",
|
|
243
|
-
Array [
|
|
244
|
-
"42",
|
|
245
|
-
"124",
|
|
246
|
-
"2",
|
|
247
|
-
"Argentine",
|
|
248
|
-
"Buenos Aires",
|
|
249
|
-
"Buenos Aires",
|
|
250
|
-
"Mac",
|
|
251
|
-
"Générique Bureau",
|
|
252
|
-
"Inconnu",
|
|
253
|
-
"300",
|
|
254
|
-
"23",
|
|
255
|
-
"returningCustomer",
|
|
256
|
-
"visitorId",
|
|
257
|
-
"referrerType",
|
|
258
|
-
"referrerName",
|
|
259
|
-
"tests",
|
|
260
|
-
"24",
|
|
261
|
-
"2021-08-20T21:55:12.000Z",
|
|
262
|
-
"124_1",
|
|
263
|
-
"action",
|
|
264
|
-
"Divezone Brand Diving Boots - Divezone Store",
|
|
265
|
-
undefined,
|
|
266
|
-
undefined,
|
|
267
|
-
undefined,
|
|
268
|
-
undefined,
|
|
269
|
-
"2",
|
|
270
|
-
"2021-08-20T21:30:25.000Z",
|
|
271
|
-
"https://dive-shop.net/products/diving-boots/",
|
|
272
|
-
undefined,
|
|
273
|
-
Object {},
|
|
274
|
-
Object {
|
|
275
|
-
"dimension1": "guest",
|
|
276
|
-
"dimension10": "36",
|
|
277
|
-
"dimension2": "julien",
|
|
278
|
-
"dimension3": "page",
|
|
279
|
-
"dimension4": "indonesia",
|
|
280
|
-
"dimension5": "diving",
|
|
281
|
-
"dimension6": "shop",
|
|
282
|
-
"dimension7": "v1.2.3",
|
|
283
|
-
"dimension8": "fr",
|
|
284
|
-
"dimension9": "light",
|
|
285
|
-
},
|
|
286
|
-
"guest",
|
|
287
|
-
"julien",
|
|
288
|
-
"page",
|
|
289
|
-
"indonesia",
|
|
290
|
-
"diving",
|
|
291
|
-
"shop",
|
|
292
|
-
"v1.2.3",
|
|
293
|
-
"fr",
|
|
294
|
-
"light",
|
|
295
|
-
"36",
|
|
296
|
-
],
|
|
297
|
-
],
|
|
298
|
-
Array [
|
|
299
|
-
"insert into matomo
|
|
300
|
-
(idsite, idvisit, actions, country, region, city, operatingsystemname, devicemodel, devicebrand, visitduration, dayssincefirstvisit, visitortype, visitorid, referrertype, referrername, sitename, userid, serverdateprettyfirstaction, action_id, action_type, action_title, action_eventcategory, action_eventaction, action_eventname, action_eventvalue, action_timespent, action_timestamp, action_url, siteSearchKeyword, usercustomproperties, usercustomdimensions, dimension1, dimension2, dimension3, dimension4, dimension5, dimension6, dimension7, dimension8, dimension9, dimension10)
|
|
301
|
-
values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26, $27, $28, $29, $30, $31, $32, $33, $34, $35, $36, $37, $38, $39, $40, $41)
|
|
302
|
-
ON CONFLICT DO NOTHING",
|
|
303
|
-
Array [
|
|
304
|
-
"42",
|
|
305
|
-
"124",
|
|
306
|
-
"2",
|
|
307
|
-
"Argentine",
|
|
308
|
-
"Buenos Aires",
|
|
309
|
-
"Buenos Aires",
|
|
310
|
-
"Mac",
|
|
311
|
-
"Générique Bureau",
|
|
312
|
-
"Inconnu",
|
|
313
|
-
"300",
|
|
314
|
-
"23",
|
|
315
|
-
"returningCustomer",
|
|
316
|
-
"visitorId",
|
|
317
|
-
"referrerType",
|
|
318
|
-
"referrerName",
|
|
319
|
-
"tests",
|
|
320
|
-
"24",
|
|
321
|
-
"2021-08-20T21:55:12.000Z",
|
|
322
|
-
"124_2",
|
|
323
|
-
"search",
|
|
324
|
-
"Divezone Brand Diving Boots - Divezone Store",
|
|
325
|
-
undefined,
|
|
326
|
-
undefined,
|
|
327
|
-
undefined,
|
|
328
|
-
undefined,
|
|
329
|
-
"2",
|
|
330
|
-
"2021-08-20T21:30:22.000Z",
|
|
331
|
-
"https://dive-shop.net/products/diving-boots/",
|
|
332
|
-
"scuba",
|
|
333
|
-
Object {},
|
|
334
|
-
Object {
|
|
335
|
-
"dimension1": "guest",
|
|
336
|
-
"dimension10": "36",
|
|
337
|
-
"dimension2": "julien",
|
|
338
|
-
"dimension3": "page",
|
|
339
|
-
"dimension4": "indonesia",
|
|
340
|
-
"dimension5": "diving",
|
|
341
|
-
"dimension6": "shop",
|
|
342
|
-
"dimension7": "v1.2.3",
|
|
343
|
-
"dimension8": "fr",
|
|
344
|
-
"dimension9": "light",
|
|
345
|
-
},
|
|
346
|
-
"guest",
|
|
347
|
-
"julien",
|
|
348
|
-
"page",
|
|
349
|
-
"indonesia",
|
|
350
|
-
"diving",
|
|
351
|
-
"shop",
|
|
352
|
-
"v1.2.3",
|
|
353
|
-
"fr",
|
|
354
|
-
"light",
|
|
355
|
-
"36",
|
|
356
|
-
],
|
|
357
|
-
],
|
|
358
|
-
]
|
|
359
|
-
`;
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
-
|
|
3
|
-
exports[`run: should create table 1`] = `
|
|
4
|
-
Array [
|
|
5
|
-
"
|
|
6
|
-
|
|
7
|
-
CREATE SCHEMA IF NOT EXISTS partman;
|
|
8
|
-
CREATE EXTENSION IF NOT EXISTS pg_partman SCHEMA partman;
|
|
9
|
-
CREATE TABLE IF NOT EXISTS matomo
|
|
10
|
-
(
|
|
11
|
-
idsite text,
|
|
12
|
-
idvisit text,
|
|
13
|
-
actions text,
|
|
14
|
-
country text,
|
|
15
|
-
region text,
|
|
16
|
-
city text,
|
|
17
|
-
operatingsystemname text,
|
|
18
|
-
devicemodel text,
|
|
19
|
-
devicebrand text,
|
|
20
|
-
visitduration text,
|
|
21
|
-
dayssincefirstvisit text,
|
|
22
|
-
visitortype text,
|
|
23
|
-
sitename text,
|
|
24
|
-
userid text,
|
|
25
|
-
serverdateprettyfirstaction date,
|
|
26
|
-
action_id text,
|
|
27
|
-
action_type text,
|
|
28
|
-
action_eventcategory text,
|
|
29
|
-
action_eventaction text,
|
|
30
|
-
action_eventname text,
|
|
31
|
-
action_eventvalue decimal,
|
|
32
|
-
action_timespent text,
|
|
33
|
-
action_timestamp timestamp with time zone DEFAULT now(),
|
|
34
|
-
usercustomproperties json,
|
|
35
|
-
usercustomdimensions json,
|
|
36
|
-
dimension1 text,
|
|
37
|
-
dimension2 text,
|
|
38
|
-
dimension3 text,
|
|
39
|
-
dimension4 text,
|
|
40
|
-
dimension5 text,
|
|
41
|
-
dimension6 text,
|
|
42
|
-
dimension7 text,
|
|
43
|
-
dimension8 text,
|
|
44
|
-
dimension9 text,
|
|
45
|
-
dimension10 text,
|
|
46
|
-
action_url text,
|
|
47
|
-
sitesearchkeyword text,
|
|
48
|
-
action_title text,
|
|
49
|
-
visitorid text,
|
|
50
|
-
referrertype text,
|
|
51
|
-
referrername text
|
|
52
|
-
) PARTITION BY RANGE (action_timestamp);
|
|
53
|
-
",
|
|
54
|
-
Array [],
|
|
55
|
-
]
|
|
56
|
-
`;
|
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
const { importDate } = require("../importDate");
|
|
2
|
-
|
|
3
|
-
const mock_pgQuery = jest.fn();
|
|
4
|
-
const mock_matomoApi = jest.fn();
|
|
5
|
-
|
|
6
|
-
process.env.MATOMO_SITE = "42";
|
|
7
|
-
process.env.PROJECT_NAME = "some-project";
|
|
8
|
-
|
|
9
|
-
const matomoVisit = require("./visit.json");
|
|
10
|
-
|
|
11
|
-
jest.mock("pg", () => {
|
|
12
|
-
class Client {
|
|
13
|
-
escapeIdentifier(name) {
|
|
14
|
-
return name;
|
|
15
|
-
}
|
|
16
|
-
end() {}
|
|
17
|
-
connect() {
|
|
18
|
-
return Promise.resolve();
|
|
19
|
-
}
|
|
20
|
-
query(...args) {
|
|
21
|
-
return mock_pgQuery(...args);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
return {
|
|
25
|
-
Client,
|
|
26
|
-
};
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
jest.mock("piwik-client", () => {
|
|
30
|
-
class MatomoClient {
|
|
31
|
-
api(...args) {
|
|
32
|
-
return mock_matomoApi(...args);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
return MatomoClient;
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
beforeEach(() => {
|
|
39
|
-
jest.resetAllMocks();
|
|
40
|
-
jest.resetModules();
|
|
41
|
-
process.env.STARTDATE = "";
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
test("importDate: should import all events for a given date", async () => {
|
|
45
|
-
const pgSpy = jest.fn().mockResolvedValue();
|
|
46
|
-
const matomoSpy = jest.fn().mockImplementation((options, cb) => {
|
|
47
|
-
return cb(null, [
|
|
48
|
-
{
|
|
49
|
-
...matomoVisit,
|
|
50
|
-
idVisit: 123,
|
|
51
|
-
},
|
|
52
|
-
{
|
|
53
|
-
...matomoVisit,
|
|
54
|
-
idVisit: 124,
|
|
55
|
-
},
|
|
56
|
-
]);
|
|
57
|
-
});
|
|
58
|
-
const fakeClient = {
|
|
59
|
-
escapeIdentifier(name) {
|
|
60
|
-
return name;
|
|
61
|
-
},
|
|
62
|
-
query: pgSpy,
|
|
63
|
-
};
|
|
64
|
-
//@ts-expect-error
|
|
65
|
-
await importDate(fakeClient, matomoSpy, new Date("2021-08-02"));
|
|
66
|
-
expect(matomoSpy.mock.calls.map((c) => c[0])).toMatchSnapshot();
|
|
67
|
-
expect(pgSpy.mock.calls).toMatchSnapshot();
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
test("importDate: should import when new results", async () => {
|
|
71
|
-
const pgResult = { rows: [] };
|
|
72
|
-
const pgSpy = jest.fn().mockResolvedValue(pgResult);
|
|
73
|
-
const matomoSpy = jest.fn().mockImplementation((options, cb) => {
|
|
74
|
-
return cb(null, [
|
|
75
|
-
{
|
|
76
|
-
...matomoVisit,
|
|
77
|
-
idVisit: 123,
|
|
78
|
-
},
|
|
79
|
-
]);
|
|
80
|
-
});
|
|
81
|
-
const fakeClient = {
|
|
82
|
-
query: pgSpy,
|
|
83
|
-
escapeIdentifier(name) {
|
|
84
|
-
return name;
|
|
85
|
-
},
|
|
86
|
-
};
|
|
87
|
-
//@ts-expect-error
|
|
88
|
-
const imported = await importDate(fakeClient, matomoSpy, new Date("2021-08-03T00:00:00"));
|
|
89
|
-
expect(pgSpy.mock.calls.length).toEqual(4);
|
|
90
|
-
expect(imported.length).toEqual(3);
|
|
91
|
-
expect(matomoSpy.mock.calls[0][0].filter_offset).toEqual(0);
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
test("importDate: should offset matomo calls when results already exist", async () => {
|
|
95
|
-
const pgResult = { rows: [{ count: 42 }] };
|
|
96
|
-
const pgSpy = jest.fn().mockResolvedValue(pgResult);
|
|
97
|
-
const matomoSpy = jest.fn().mockImplementation((options, cb) => {
|
|
98
|
-
return cb(null, [
|
|
99
|
-
{
|
|
100
|
-
...matomoVisit,
|
|
101
|
-
idVisit: 123,
|
|
102
|
-
},
|
|
103
|
-
]);
|
|
104
|
-
});
|
|
105
|
-
const fakeClient = {
|
|
106
|
-
query: pgSpy,
|
|
107
|
-
escapeIdentifier(name) {
|
|
108
|
-
return name;
|
|
109
|
-
},
|
|
110
|
-
};
|
|
111
|
-
//@ts-expect-error
|
|
112
|
-
const imported = await importDate(fakeClient, matomoSpy, new Date("2021-08-03T00:00:00"));
|
|
113
|
-
expect(pgSpy.mock.calls.length).toEqual(4);
|
|
114
|
-
expect(imported.length).toEqual(3);
|
|
115
|
-
expect(matomoSpy.mock.calls[0][0].filter_offset).toEqual(42);
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
test("importDate: should NOT import when no matomo results", async () => {
|
|
119
|
-
const pgSpy = jest.fn().mockResolvedValue({ rows: [{ action_timestamp: 1627948800000 }] });
|
|
120
|
-
const matomoSpy = jest.fn().mockImplementation((options, cb) => {
|
|
121
|
-
return cb(null, []);
|
|
122
|
-
});
|
|
123
|
-
const fakeClient = {
|
|
124
|
-
query: pgSpy,
|
|
125
|
-
escapeIdentifier(name) {
|
|
126
|
-
return name;
|
|
127
|
-
},
|
|
128
|
-
};
|
|
129
|
-
//@ts-expect-error
|
|
130
|
-
const imported = await importDate(fakeClient, matomoSpy, new Date("2021-08-03"));
|
|
131
|
-
expect(pgSpy.mock.calls.length).toEqual(1);
|
|
132
|
-
expect(imported.length).toEqual(0);
|
|
133
|
-
});
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
process.env.MATOMO_SITE = "42";
|
|
2
|
-
process.env.PROJECT_NAME = "some-project";
|
|
3
|
-
|
|
4
|
-
const matomoVisit = require("./visit.json");
|
|
5
|
-
const { getEventsFromMatomoVisit, importEvent } = require("../importEvent");
|
|
6
|
-
|
|
7
|
-
test("importEvent: should extract events from matomo visit actionsDetails and create insert queries", () => {
|
|
8
|
-
//@ts-expect-error
|
|
9
|
-
const visits = getEventsFromMatomoVisit(matomoVisit);
|
|
10
|
-
expect(visits).toMatchSnapshot();
|
|
11
|
-
const spy = jest.fn();
|
|
12
|
-
spy.mockResolvedValue(Promise.resolve());
|
|
13
|
-
const fakeClient = {
|
|
14
|
-
escapeIdentifier(name) {
|
|
15
|
-
return name;
|
|
16
|
-
},
|
|
17
|
-
query: spy,
|
|
18
|
-
};
|
|
19
|
-
//@ts-expect-error
|
|
20
|
-
visits.map((visit) => importEvent(fakeClient, visit));
|
|
21
|
-
expect(spy.mock.calls).toMatchSnapshot();
|
|
22
|
-
});
|