@walkeros/collector 0.5.0 → 0.5.1-next.0
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/dist/dev.d.mts +4 -9
- package/dist/dev.d.ts +4 -9
- package/dist/dev.js +1 -1
- package/dist/dev.js.map +1 -1
- package/dist/dev.mjs +1 -1
- package/dist/dev.mjs.map +1 -1
- package/dist/index.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/dist/__tests__/auto-run.test.d.ts +0 -2
- package/dist/__tests__/auto-run.test.d.ts.map +0 -1
- package/dist/__tests__/auto-run.test.js +0 -102
- package/dist/__tests__/auto-run.test.js.map +0 -1
- package/dist/__tests__/consent.test.d.ts +0 -2
- package/dist/__tests__/consent.test.d.ts.map +0 -1
- package/dist/__tests__/consent.test.js +0 -21
- package/dist/__tests__/consent.test.js.map +0 -1
- package/dist/__tests__/create-flow.test.d.ts +0 -2
- package/dist/__tests__/create-flow.test.d.ts.map +0 -1
- package/dist/__tests__/create-flow.test.js +0 -69
- package/dist/__tests__/create-flow.test.js.map +0 -1
- package/dist/__tests__/destination-code.test.d.ts +0 -2
- package/dist/__tests__/destination-code.test.d.ts.map +0 -1
- package/dist/__tests__/destination-code.test.js +0 -323
- package/dist/__tests__/destination-code.test.js.map +0 -1
- package/dist/__tests__/destination.test.d.ts +0 -2
- package/dist/__tests__/destination.test.d.ts.map +0 -1
- package/dist/__tests__/destination.test.js +0 -320
- package/dist/__tests__/destination.test.js.map +0 -1
- package/dist/__tests__/handle.test.d.ts +0 -2
- package/dist/__tests__/handle.test.d.ts.map +0 -1
- package/dist/__tests__/handle.test.js +0 -78
- package/dist/__tests__/handle.test.js.map +0 -1
- package/dist/__tests__/mapping.test.d.ts +0 -2
- package/dist/__tests__/mapping.test.d.ts.map +0 -1
- package/dist/__tests__/mapping.test.js +0 -310
- package/dist/__tests__/mapping.test.js.map +0 -1
- package/dist/__tests__/source.test.d.ts +0 -2
- package/dist/__tests__/source.test.d.ts.map +0 -1
- package/dist/__tests__/source.test.js +0 -306
- package/dist/__tests__/source.test.js.map +0 -1
- package/dist/__tests__/start-flow.test.d.ts +0 -2
- package/dist/__tests__/start-flow.test.d.ts.map +0 -1
- package/dist/__tests__/start-flow.test.js +0 -167
- package/dist/__tests__/start-flow.test.js.map +0 -1
- package/dist/__tests__/walker-entity.test.d.ts +0 -2
- package/dist/__tests__/walker-entity.test.d.ts.map +0 -1
- package/dist/__tests__/walker-entity.test.js +0 -52
- package/dist/__tests__/walker-entity.test.js.map +0 -1
- package/dist/collector.d.ts +0 -3
- package/dist/collector.d.ts.map +0 -1
- package/dist/collector.js +0 -60
- package/dist/collector.js.map +0 -1
- package/dist/command.d.ts +0 -12
- package/dist/command.d.ts.map +0 -1
- package/dist/command.js +0 -20
- package/dist/command.js.map +0 -1
- package/dist/consent.d.ts +0 -10
- package/dist/consent.d.ts.map +0 -1
- package/dist/consent.js +0 -30
- package/dist/consent.js.map +0 -1
- package/dist/constants.d.ts +0 -13
- package/dist/constants.d.ts.map +0 -1
- package/dist/constants.js +0 -35
- package/dist/constants.js.map +0 -1
- package/dist/destination-code.d.ts +0 -4
- package/dist/destination-code.d.ts.map +0 -1
- package/dist/destination-code.js +0 -60
- package/dist/destination-code.js.map +0 -1
- package/dist/destination.d.ts +0 -61
- package/dist/destination.d.ts.map +0 -1
- package/dist/destination.js +0 -314
- package/dist/destination.js.map +0 -1
- package/dist/dev.d.ts.map +0 -1
- package/dist/elb.d.ts +0 -11
- package/dist/elb.d.ts.map +0 -1
- package/dist/elb.js +0 -60
- package/dist/elb.js.map +0 -1
- package/dist/flow.d.ts +0 -4
- package/dist/flow.d.ts.map +0 -1
- package/dist/flow.js +0 -44
- package/dist/flow.js.map +0 -1
- package/dist/handle.d.ts +0 -29
- package/dist/handle.d.ts.map +0 -1
- package/dist/handle.js +0 -161
- package/dist/handle.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/on.d.ts +0 -19
- package/dist/on.d.ts.map +0 -1
- package/dist/on.js +0 -127
- package/dist/on.js.map +0 -1
- package/dist/push.d.ts +0 -11
- package/dist/push.d.ts.map +0 -1
- package/dist/push.js +0 -43
- package/dist/push.js.map +0 -1
- package/dist/schemas.d.ts +0 -4
- package/dist/schemas.d.ts.map +0 -1
- package/dist/schemas.js +0 -35
- package/dist/schemas.js.map +0 -1
- package/dist/source.d.ts +0 -10
- package/dist/source.d.ts.map +0 -1
- package/dist/source.js +0 -47
- package/dist/source.js.map +0 -1
- package/dist/types/code.d.ts +0 -22
- package/dist/types/code.d.ts.map +0 -1
- package/dist/types/code.js +0 -2
- package/dist/types/code.js.map +0 -1
- package/dist/types/collector.d.ts +0 -19
- package/dist/types/collector.d.ts.map +0 -1
- package/dist/types/collector.js +0 -2
- package/dist/types/collector.js.map +0 -1
- package/dist/types/index.d.ts +0 -3
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/index.js +0 -4
- package/dist/types/index.js.map +0 -1
|
@@ -1,323 +0,0 @@
|
|
|
1
|
-
import { createEvent, createMockLogger } from '@walkeros/core';
|
|
2
|
-
import { destinationCode } from '../destination-code';
|
|
3
|
-
import { initDestinations } from '../destination';
|
|
4
|
-
describe('destinationCode', () => {
|
|
5
|
-
const createMockCollector = () => ({
|
|
6
|
-
consent: {},
|
|
7
|
-
destinations: {},
|
|
8
|
-
sources: {},
|
|
9
|
-
queue: [],
|
|
10
|
-
hooks: {},
|
|
11
|
-
on: {},
|
|
12
|
-
globals: {},
|
|
13
|
-
user: {},
|
|
14
|
-
allowed: true,
|
|
15
|
-
config: {},
|
|
16
|
-
count: 0,
|
|
17
|
-
logger: createMockLogger(),
|
|
18
|
-
push: jest.fn(),
|
|
19
|
-
});
|
|
20
|
-
beforeEach(() => {
|
|
21
|
-
jest.clearAllMocks();
|
|
22
|
-
});
|
|
23
|
-
describe('basic properties', () => {
|
|
24
|
-
it('should have correct type', () => {
|
|
25
|
-
expect(destinationCode.type).toBe('code');
|
|
26
|
-
});
|
|
27
|
-
it('should have empty default config', () => {
|
|
28
|
-
expect(destinationCode.config).toEqual({});
|
|
29
|
-
});
|
|
30
|
-
});
|
|
31
|
-
describe('init', () => {
|
|
32
|
-
it('executes init code string', () => {
|
|
33
|
-
const mockLogger = createMockLogger();
|
|
34
|
-
const context = {
|
|
35
|
-
collector: createMockCollector(),
|
|
36
|
-
config: {
|
|
37
|
-
settings: {
|
|
38
|
-
init: "context.logger.info('initialized')",
|
|
39
|
-
},
|
|
40
|
-
},
|
|
41
|
-
env: {},
|
|
42
|
-
logger: mockLogger,
|
|
43
|
-
};
|
|
44
|
-
destinationCode.init(context);
|
|
45
|
-
expect(mockLogger.info).toHaveBeenCalledWith('initialized');
|
|
46
|
-
});
|
|
47
|
-
it('handles missing init code gracefully', () => {
|
|
48
|
-
const context = {
|
|
49
|
-
collector: createMockCollector(),
|
|
50
|
-
config: { settings: {} },
|
|
51
|
-
env: {},
|
|
52
|
-
logger: createMockLogger(),
|
|
53
|
-
};
|
|
54
|
-
expect(() => destinationCode.init(context)).not.toThrow();
|
|
55
|
-
});
|
|
56
|
-
it('catches and logs errors in init code', () => {
|
|
57
|
-
const mockLogger = createMockLogger();
|
|
58
|
-
const context = {
|
|
59
|
-
collector: createMockCollector(),
|
|
60
|
-
config: {
|
|
61
|
-
settings: {
|
|
62
|
-
init: "throw new Error('test error')",
|
|
63
|
-
},
|
|
64
|
-
},
|
|
65
|
-
env: {},
|
|
66
|
-
logger: mockLogger,
|
|
67
|
-
};
|
|
68
|
-
destinationCode.init(context);
|
|
69
|
-
expect(mockLogger.error).toHaveBeenCalled();
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
describe('push', () => {
|
|
73
|
-
it('executes push code from mapping', () => {
|
|
74
|
-
const mockLogger = createMockLogger();
|
|
75
|
-
const context = {
|
|
76
|
-
collector: createMockCollector(),
|
|
77
|
-
config: {},
|
|
78
|
-
data: { transformed: true },
|
|
79
|
-
env: {},
|
|
80
|
-
logger: mockLogger,
|
|
81
|
-
mapping: {
|
|
82
|
-
push: 'context.logger.info(event.name, context.data)',
|
|
83
|
-
},
|
|
84
|
-
};
|
|
85
|
-
destinationCode.push(createEvent({ name: 'product view' }), context);
|
|
86
|
-
expect(mockLogger.info).toHaveBeenCalledWith('product view', {
|
|
87
|
-
transformed: true,
|
|
88
|
-
});
|
|
89
|
-
});
|
|
90
|
-
it('falls back to settings.push when mapping.push is missing', () => {
|
|
91
|
-
const mockLogger = createMockLogger();
|
|
92
|
-
const context = {
|
|
93
|
-
collector: createMockCollector(),
|
|
94
|
-
config: {
|
|
95
|
-
settings: {
|
|
96
|
-
push: "context.logger.info('settings fallback')",
|
|
97
|
-
},
|
|
98
|
-
},
|
|
99
|
-
data: {},
|
|
100
|
-
env: {},
|
|
101
|
-
logger: mockLogger,
|
|
102
|
-
mapping: {},
|
|
103
|
-
};
|
|
104
|
-
destinationCode.push(createEvent({ name: 'product view' }), context);
|
|
105
|
-
expect(mockLogger.info).toHaveBeenCalledWith('settings fallback');
|
|
106
|
-
});
|
|
107
|
-
it('prefers mapping.push over settings.push', () => {
|
|
108
|
-
const mockLogger = createMockLogger();
|
|
109
|
-
const context = {
|
|
110
|
-
collector: createMockCollector(),
|
|
111
|
-
config: {
|
|
112
|
-
settings: {
|
|
113
|
-
push: "context.logger.info('from settings')",
|
|
114
|
-
},
|
|
115
|
-
},
|
|
116
|
-
data: {},
|
|
117
|
-
env: {},
|
|
118
|
-
logger: mockLogger,
|
|
119
|
-
mapping: {
|
|
120
|
-
push: "context.logger.info('from mapping')",
|
|
121
|
-
},
|
|
122
|
-
};
|
|
123
|
-
destinationCode.push(createEvent({ name: 'product view' }), context);
|
|
124
|
-
expect(mockLogger.info).toHaveBeenCalledWith('from mapping');
|
|
125
|
-
expect(mockLogger.info).not.toHaveBeenCalledWith('from settings');
|
|
126
|
-
});
|
|
127
|
-
it('handles missing push code gracefully', () => {
|
|
128
|
-
const context = {
|
|
129
|
-
collector: createMockCollector(),
|
|
130
|
-
config: {},
|
|
131
|
-
env: {},
|
|
132
|
-
logger: createMockLogger(),
|
|
133
|
-
mapping: {},
|
|
134
|
-
data: {},
|
|
135
|
-
};
|
|
136
|
-
expect(() => destinationCode.push(createEvent({ name: 'product view' }), context)).not.toThrow();
|
|
137
|
-
});
|
|
138
|
-
it('catches and logs errors in push code', () => {
|
|
139
|
-
const mockLogger = createMockLogger();
|
|
140
|
-
const context = {
|
|
141
|
-
collector: createMockCollector(),
|
|
142
|
-
config: {},
|
|
143
|
-
env: {},
|
|
144
|
-
logger: mockLogger,
|
|
145
|
-
mapping: {
|
|
146
|
-
push: "throw new Error('test error')",
|
|
147
|
-
},
|
|
148
|
-
data: {},
|
|
149
|
-
};
|
|
150
|
-
destinationCode.push(createEvent({ name: 'product view' }), context);
|
|
151
|
-
expect(mockLogger.error).toHaveBeenCalled();
|
|
152
|
-
});
|
|
153
|
-
});
|
|
154
|
-
describe('pushBatch', () => {
|
|
155
|
-
it('executes pushBatch code from mapping', () => {
|
|
156
|
-
const mockLogger = createMockLogger();
|
|
157
|
-
const batch = {
|
|
158
|
-
key: 'product view',
|
|
159
|
-
events: [
|
|
160
|
-
createEvent({ name: 'product view', id: '1' }),
|
|
161
|
-
createEvent({ name: 'product view', id: '2' }),
|
|
162
|
-
],
|
|
163
|
-
data: [{ id: '1' }, { id: '2' }],
|
|
164
|
-
};
|
|
165
|
-
const context = {
|
|
166
|
-
collector: createMockCollector(),
|
|
167
|
-
config: {},
|
|
168
|
-
env: {},
|
|
169
|
-
logger: mockLogger,
|
|
170
|
-
mapping: {
|
|
171
|
-
pushBatch: "context.logger.info('batch size:', batch.events.length)",
|
|
172
|
-
},
|
|
173
|
-
};
|
|
174
|
-
destinationCode.pushBatch(batch, context);
|
|
175
|
-
expect(mockLogger.info).toHaveBeenCalledWith('batch size:', 2);
|
|
176
|
-
});
|
|
177
|
-
it('falls back to settings.pushBatch when mapping.pushBatch is missing', () => {
|
|
178
|
-
const mockLogger = createMockLogger();
|
|
179
|
-
const batch = {
|
|
180
|
-
key: 'test',
|
|
181
|
-
events: [],
|
|
182
|
-
data: [],
|
|
183
|
-
};
|
|
184
|
-
const context = {
|
|
185
|
-
collector: createMockCollector(),
|
|
186
|
-
config: {
|
|
187
|
-
settings: {
|
|
188
|
-
pushBatch: "context.logger.info('batch settings fallback')",
|
|
189
|
-
},
|
|
190
|
-
},
|
|
191
|
-
env: {},
|
|
192
|
-
logger: mockLogger,
|
|
193
|
-
mapping: {},
|
|
194
|
-
};
|
|
195
|
-
destinationCode.pushBatch(batch, context);
|
|
196
|
-
expect(mockLogger.info).toHaveBeenCalledWith('batch settings fallback');
|
|
197
|
-
});
|
|
198
|
-
it('handles missing pushBatch code gracefully', () => {
|
|
199
|
-
const batch = {
|
|
200
|
-
key: 'test',
|
|
201
|
-
events: [],
|
|
202
|
-
data: [],
|
|
203
|
-
};
|
|
204
|
-
const context = {
|
|
205
|
-
collector: createMockCollector(),
|
|
206
|
-
config: {},
|
|
207
|
-
env: {},
|
|
208
|
-
logger: createMockLogger(),
|
|
209
|
-
mapping: {},
|
|
210
|
-
};
|
|
211
|
-
expect(() => destinationCode.pushBatch(batch, context)).not.toThrow();
|
|
212
|
-
});
|
|
213
|
-
it('catches and logs errors in pushBatch code', () => {
|
|
214
|
-
const mockLogger = createMockLogger();
|
|
215
|
-
const batch = {
|
|
216
|
-
key: 'test',
|
|
217
|
-
events: [],
|
|
218
|
-
data: [],
|
|
219
|
-
};
|
|
220
|
-
const context = {
|
|
221
|
-
collector: createMockCollector(),
|
|
222
|
-
config: {},
|
|
223
|
-
env: {},
|
|
224
|
-
logger: mockLogger,
|
|
225
|
-
mapping: {
|
|
226
|
-
pushBatch: "throw new Error('test error')",
|
|
227
|
-
},
|
|
228
|
-
};
|
|
229
|
-
destinationCode.pushBatch(batch, context);
|
|
230
|
-
expect(mockLogger.error).toHaveBeenCalled();
|
|
231
|
-
});
|
|
232
|
-
});
|
|
233
|
-
describe('on', () => {
|
|
234
|
-
it('executes on code string', () => {
|
|
235
|
-
const mockLogger = createMockLogger();
|
|
236
|
-
const context = {
|
|
237
|
-
collector: createMockCollector(),
|
|
238
|
-
config: {
|
|
239
|
-
settings: {
|
|
240
|
-
on: "if (type === 'consent') context.logger.info('consent:', context.data)",
|
|
241
|
-
},
|
|
242
|
-
},
|
|
243
|
-
data: { marketing: true },
|
|
244
|
-
env: {},
|
|
245
|
-
logger: mockLogger,
|
|
246
|
-
};
|
|
247
|
-
destinationCode.on('consent', context);
|
|
248
|
-
expect(mockLogger.info).toHaveBeenCalledWith('consent:', {
|
|
249
|
-
marketing: true,
|
|
250
|
-
});
|
|
251
|
-
});
|
|
252
|
-
it('handles missing on code gracefully', () => {
|
|
253
|
-
const context = {
|
|
254
|
-
collector: createMockCollector(),
|
|
255
|
-
config: { settings: {} },
|
|
256
|
-
env: {},
|
|
257
|
-
logger: createMockLogger(),
|
|
258
|
-
};
|
|
259
|
-
expect(() => destinationCode.on('consent', context)).not.toThrow();
|
|
260
|
-
});
|
|
261
|
-
it('catches and logs errors in on code', () => {
|
|
262
|
-
const mockLogger = createMockLogger();
|
|
263
|
-
const context = {
|
|
264
|
-
collector: createMockCollector(),
|
|
265
|
-
config: {
|
|
266
|
-
settings: {
|
|
267
|
-
on: "throw new Error('test error')",
|
|
268
|
-
},
|
|
269
|
-
},
|
|
270
|
-
env: {},
|
|
271
|
-
logger: mockLogger,
|
|
272
|
-
};
|
|
273
|
-
destinationCode.on('consent', context);
|
|
274
|
-
expect(mockLogger.error).toHaveBeenCalled();
|
|
275
|
-
});
|
|
276
|
-
});
|
|
277
|
-
});
|
|
278
|
-
describe('code: true initialization', () => {
|
|
279
|
-
it('uses built-in destinationCode when code is true', async () => {
|
|
280
|
-
const collector = {
|
|
281
|
-
logger: createMockLogger(),
|
|
282
|
-
};
|
|
283
|
-
const destinations = await initDestinations(collector, {
|
|
284
|
-
myCodeDest: {
|
|
285
|
-
code: true,
|
|
286
|
-
config: {
|
|
287
|
-
settings: {
|
|
288
|
-
init: "context.logger.info('ready')",
|
|
289
|
-
},
|
|
290
|
-
},
|
|
291
|
-
},
|
|
292
|
-
});
|
|
293
|
-
expect(destinations.myCodeDest).toBeDefined();
|
|
294
|
-
expect(destinations.myCodeDest.type).toBe('code');
|
|
295
|
-
expect(destinations.myCodeDest.init).toBeDefined();
|
|
296
|
-
expect(destinations.myCodeDest.push).toBeDefined();
|
|
297
|
-
});
|
|
298
|
-
it('preserves provided config with code: true', async () => {
|
|
299
|
-
const collector = {
|
|
300
|
-
logger: createMockLogger(),
|
|
301
|
-
};
|
|
302
|
-
const destinations = await initDestinations(collector, {
|
|
303
|
-
myCodeDest: {
|
|
304
|
-
code: true,
|
|
305
|
-
config: {
|
|
306
|
-
settings: {
|
|
307
|
-
init: "context.logger.info('custom init')",
|
|
308
|
-
push: "context.logger.info('custom push')",
|
|
309
|
-
},
|
|
310
|
-
consent: { functional: true },
|
|
311
|
-
},
|
|
312
|
-
},
|
|
313
|
-
});
|
|
314
|
-
expect(destinations.myCodeDest.config.settings).toEqual({
|
|
315
|
-
init: "context.logger.info('custom init')",
|
|
316
|
-
push: "context.logger.info('custom push')",
|
|
317
|
-
});
|
|
318
|
-
expect(destinations.myCodeDest.config.consent).toEqual({
|
|
319
|
-
functional: true,
|
|
320
|
-
});
|
|
321
|
-
});
|
|
322
|
-
});
|
|
323
|
-
//# sourceMappingURL=destination-code.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"destination-code.test.js","sourceRoot":"","sources":["../../src/__tests__/destination-code.test.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAC/D,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAUlD,QAAQ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E;gBACV,IAAI,EAAE,IAAuC;gBAC7C,MAAM,EAAE;oBACN,QAAQ,EAAE;wBACR,IAAI,EAAE,oCAAoC;wBAC1C,IAAI,EAAE,oCAAoC;qBAC3C;oBACD,OAAO,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE;iBAC9B;aACF;SACF,CAAC,CAAC;QAEH,MAAM,CAAC,YAAY,CAAC,UAAU,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC;YACtD,IAAI,EAAE,oCAAoC;YAC1C,IAAI,EAAE,oCAAoC;SAC3C,CAAC,CAAC;QACH,MAAM,CAAC,YAAY,CAAC,UAAU,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC;YACrD,UAAU,EAAE,IAAI;SACjB,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"destination.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/destination.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,320 +0,0 @@
|
|
|
1
|
-
import { clone, createEvent, createMockLogger } from '@walkeros/core';
|
|
2
|
-
import { pushToDestinations, startFlow } from '..';
|
|
3
|
-
describe('Destination', () => {
|
|
4
|
-
let event;
|
|
5
|
-
let destination;
|
|
6
|
-
let config;
|
|
7
|
-
let mockInit;
|
|
8
|
-
let mockPush;
|
|
9
|
-
function createDestination(args) {
|
|
10
|
-
return {
|
|
11
|
-
init: mockInit,
|
|
12
|
-
push: mockPush,
|
|
13
|
-
config: {},
|
|
14
|
-
...args,
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
function createTestConfig(overrides = {}) {
|
|
18
|
-
return {
|
|
19
|
-
tagging: 1,
|
|
20
|
-
globalsStatic: {},
|
|
21
|
-
sessionStatic: {},
|
|
22
|
-
...overrides,
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
function createWalkerjs(args) {
|
|
26
|
-
const defaultConfig = createTestConfig();
|
|
27
|
-
// Create mock logger with proper scope chaining
|
|
28
|
-
const mockLogger = createMockLogger();
|
|
29
|
-
const scopedMockLogger = createMockLogger();
|
|
30
|
-
mockLogger.scope = jest.fn().mockReturnValue(scopedMockLogger);
|
|
31
|
-
return {
|
|
32
|
-
allowed: true,
|
|
33
|
-
destinations: { foo: destination },
|
|
34
|
-
globals: {},
|
|
35
|
-
hooks: {},
|
|
36
|
-
logger: mockLogger,
|
|
37
|
-
user: {},
|
|
38
|
-
consent: {},
|
|
39
|
-
queue: [],
|
|
40
|
-
...args,
|
|
41
|
-
config: args?.config ? createTestConfig(args.config) : defaultConfig,
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
beforeEach(() => {
|
|
45
|
-
event = createEvent();
|
|
46
|
-
mockInit = jest.fn(); //.mockImplementation(console.log);
|
|
47
|
-
mockPush = jest.fn(); //.mockImplementation(console.log);
|
|
48
|
-
config = { init: false };
|
|
49
|
-
destination = {
|
|
50
|
-
init: mockInit,
|
|
51
|
-
push: mockPush,
|
|
52
|
-
config,
|
|
53
|
-
};
|
|
54
|
-
});
|
|
55
|
-
test('allowed', async () => {
|
|
56
|
-
const collector = createWalkerjs({ allowed: false });
|
|
57
|
-
let result = await pushToDestinations(collector, event);
|
|
58
|
-
expect(result.ok).toBeFalsy();
|
|
59
|
-
collector.allowed = true;
|
|
60
|
-
result = await pushToDestinations(collector, event);
|
|
61
|
-
expect(result.ok).toBeTruthy();
|
|
62
|
-
});
|
|
63
|
-
test('preventing data manipulation', async () => {
|
|
64
|
-
const clonedEvent = clone(event);
|
|
65
|
-
const mockPushUpdate = jest.fn().mockImplementation((event) => {
|
|
66
|
-
event.data.foo = 'bar';
|
|
67
|
-
});
|
|
68
|
-
const destinationUpdate = {
|
|
69
|
-
init: mockInit,
|
|
70
|
-
push: mockPushUpdate,
|
|
71
|
-
config: {},
|
|
72
|
-
};
|
|
73
|
-
await pushToDestinations(createWalkerjs(), event, {
|
|
74
|
-
destinationUpdate,
|
|
75
|
-
destination,
|
|
76
|
-
});
|
|
77
|
-
expect(mockPushUpdate).toHaveBeenCalledTimes(1);
|
|
78
|
-
expect(mockPush).toHaveBeenCalledTimes(1);
|
|
79
|
-
expect(mockPush).toHaveBeenCalledWith(clonedEvent, expect.objectContaining({
|
|
80
|
-
config: { init: true },
|
|
81
|
-
}));
|
|
82
|
-
});
|
|
83
|
-
test('failing init', async () => {
|
|
84
|
-
// Simulate a failed init
|
|
85
|
-
mockInit.mockImplementation(() => false);
|
|
86
|
-
await pushToDestinations(createWalkerjs(), event);
|
|
87
|
-
expect(mockInit).toHaveBeenCalledTimes(1);
|
|
88
|
-
expect(mockPush).toHaveBeenCalledTimes(0);
|
|
89
|
-
expect(destination.config.init).toBeFalsy();
|
|
90
|
-
});
|
|
91
|
-
test('logs init lifecycle', async () => {
|
|
92
|
-
const collector = createWalkerjs();
|
|
93
|
-
await pushToDestinations(collector, event);
|
|
94
|
-
expect(mockInit).toHaveBeenCalledTimes(1);
|
|
95
|
-
expect(mockPush).toHaveBeenCalledTimes(1);
|
|
96
|
-
// Verify logger.scope was called with destination type
|
|
97
|
-
expect(collector.logger.scope).toHaveBeenCalledWith('unknown');
|
|
98
|
-
// Get the scoped logger instance
|
|
99
|
-
const scopedLogger = collector.logger.scope.mock.results[0]
|
|
100
|
-
.value;
|
|
101
|
-
// Verify init lifecycle logs
|
|
102
|
-
expect(scopedLogger.debug).toHaveBeenCalledWith('init');
|
|
103
|
-
expect(scopedLogger.debug).toHaveBeenCalledWith('init done');
|
|
104
|
-
});
|
|
105
|
-
test('logs push lifecycle', async () => {
|
|
106
|
-
const collector = createWalkerjs();
|
|
107
|
-
destination.config.init = true; // Skip init for this test
|
|
108
|
-
await pushToDestinations(collector, event);
|
|
109
|
-
expect(mockPush).toHaveBeenCalledTimes(1);
|
|
110
|
-
// Verify logger.scope was called with destination type
|
|
111
|
-
expect(collector.logger.scope).toHaveBeenCalledWith('unknown');
|
|
112
|
-
// Get the scoped logger instance
|
|
113
|
-
const scopedLogger = collector.logger.scope.mock.results[0]
|
|
114
|
-
.value;
|
|
115
|
-
// Verify push lifecycle logs
|
|
116
|
-
expect(scopedLogger.debug).toHaveBeenCalledWith('push', {
|
|
117
|
-
event: event.name,
|
|
118
|
-
});
|
|
119
|
-
expect(scopedLogger.debug).toHaveBeenCalledWith('push done');
|
|
120
|
-
});
|
|
121
|
-
test('DLQ', async () => {
|
|
122
|
-
const event = createEvent();
|
|
123
|
-
// Simulate a failing push
|
|
124
|
-
mockPush.mockImplementation(() => {
|
|
125
|
-
throw new Error('kaputt');
|
|
126
|
-
});
|
|
127
|
-
const destination = createDestination();
|
|
128
|
-
const result = await pushToDestinations(createWalkerjs(), event, {
|
|
129
|
-
destination,
|
|
130
|
-
});
|
|
131
|
-
expect(result.failed).toHaveLength(1);
|
|
132
|
-
expect(result.ok).toBeFalsy();
|
|
133
|
-
expect(mockPush).toHaveBeenCalledTimes(1);
|
|
134
|
-
expect(destination.dlq).toContainEqual([event, new Error('kaputt')]);
|
|
135
|
-
});
|
|
136
|
-
test('skip on denied consent', async () => { });
|
|
137
|
-
describe('destination on method', () => {
|
|
138
|
-
let mockOnMethod;
|
|
139
|
-
beforeEach(() => {
|
|
140
|
-
mockOnMethod = jest.fn();
|
|
141
|
-
});
|
|
142
|
-
it('should call destination on method when consent event is triggered', async () => {
|
|
143
|
-
const destinationWithOn = createDestination({
|
|
144
|
-
on: mockOnMethod,
|
|
145
|
-
config: { init: true },
|
|
146
|
-
});
|
|
147
|
-
const { collector, elb } = await startFlow({
|
|
148
|
-
destinations: { testDestination: { code: destinationWithOn } },
|
|
149
|
-
});
|
|
150
|
-
// Trigger consent event
|
|
151
|
-
await elb('walker consent', { marketing: true });
|
|
152
|
-
// Verify the destination's on method was called with consent context
|
|
153
|
-
expect(mockOnMethod).toHaveBeenCalledWith('consent', expect.objectContaining({
|
|
154
|
-
data: { marketing: true },
|
|
155
|
-
collector: expect.any(Object),
|
|
156
|
-
config: expect.any(Object),
|
|
157
|
-
env: expect.any(Object),
|
|
158
|
-
logger: expect.any(Object),
|
|
159
|
-
}));
|
|
160
|
-
});
|
|
161
|
-
it('should call destination on method when session event is triggered', async () => {
|
|
162
|
-
const destinationWithOn = createDestination({
|
|
163
|
-
on: mockOnMethod,
|
|
164
|
-
config: { init: true },
|
|
165
|
-
});
|
|
166
|
-
const { collector, elb } = await startFlow({
|
|
167
|
-
destinations: { testDestination: { code: destinationWithOn } },
|
|
168
|
-
});
|
|
169
|
-
// Set session data and trigger session event
|
|
170
|
-
collector.session = {
|
|
171
|
-
id: 'test-session',
|
|
172
|
-
isStart: true,
|
|
173
|
-
storage: false,
|
|
174
|
-
device: 'test',
|
|
175
|
-
};
|
|
176
|
-
await elb('walker session');
|
|
177
|
-
// Verify the destination's on method was called with session context
|
|
178
|
-
expect(mockOnMethod).toHaveBeenCalledWith('session', expect.objectContaining({
|
|
179
|
-
data: collector.session,
|
|
180
|
-
collector: expect.any(Object),
|
|
181
|
-
config: expect.any(Object),
|
|
182
|
-
env: expect.any(Object),
|
|
183
|
-
logger: expect.any(Object),
|
|
184
|
-
}));
|
|
185
|
-
});
|
|
186
|
-
it('should call destination on method when ready event is triggered', async () => {
|
|
187
|
-
const destinationWithOn = createDestination({
|
|
188
|
-
on: mockOnMethod,
|
|
189
|
-
config: { init: true },
|
|
190
|
-
});
|
|
191
|
-
const { collector, elb } = await startFlow({
|
|
192
|
-
destinations: { testDestination: { code: destinationWithOn } },
|
|
193
|
-
});
|
|
194
|
-
// Trigger ready event
|
|
195
|
-
await elb('walker ready');
|
|
196
|
-
// Verify the destination's on method was called
|
|
197
|
-
expect(mockOnMethod).toHaveBeenCalledWith('ready', expect.objectContaining({
|
|
198
|
-
data: undefined,
|
|
199
|
-
collector: expect.any(Object),
|
|
200
|
-
config: expect.any(Object),
|
|
201
|
-
env: expect.any(Object),
|
|
202
|
-
logger: expect.any(Object),
|
|
203
|
-
}));
|
|
204
|
-
});
|
|
205
|
-
it('should call destination on method when run event is triggered', async () => {
|
|
206
|
-
const destinationWithOn = createDestination({
|
|
207
|
-
on: mockOnMethod,
|
|
208
|
-
config: { init: true },
|
|
209
|
-
});
|
|
210
|
-
const { collector, elb } = await startFlow({
|
|
211
|
-
destinations: { testDestination: { code: destinationWithOn } },
|
|
212
|
-
});
|
|
213
|
-
// Trigger run event
|
|
214
|
-
await elb('walker run');
|
|
215
|
-
// Verify the destination's on method was called
|
|
216
|
-
expect(mockOnMethod).toHaveBeenCalledWith('run', expect.objectContaining({
|
|
217
|
-
data: undefined,
|
|
218
|
-
collector: expect.any(Object),
|
|
219
|
-
config: expect.any(Object),
|
|
220
|
-
env: expect.any(Object),
|
|
221
|
-
logger: expect.any(Object),
|
|
222
|
-
}));
|
|
223
|
-
});
|
|
224
|
-
it('should not fail if destination does not have on method', async () => {
|
|
225
|
-
const destinationWithoutOn = createDestination({
|
|
226
|
-
config: { init: true },
|
|
227
|
-
});
|
|
228
|
-
const { collector, elb } = await startFlow({
|
|
229
|
-
destinations: { testDestination: { code: destinationWithoutOn } },
|
|
230
|
-
});
|
|
231
|
-
// Should not throw when destination has no on method
|
|
232
|
-
expect(async () => {
|
|
233
|
-
await elb('walker consent', { marketing: true });
|
|
234
|
-
await elb('walker session');
|
|
235
|
-
await elb('walker ready');
|
|
236
|
-
await elb('walker run');
|
|
237
|
-
}).not.toThrow();
|
|
238
|
-
});
|
|
239
|
-
it('should handle async on method', async () => {
|
|
240
|
-
const asyncOnMethod = jest.fn().mockResolvedValue(undefined);
|
|
241
|
-
const destinationWithAsyncOn = createDestination({
|
|
242
|
-
on: asyncOnMethod,
|
|
243
|
-
config: { init: true },
|
|
244
|
-
});
|
|
245
|
-
const { collector, elb } = await startFlow({
|
|
246
|
-
destinations: { testDestination: { code: destinationWithAsyncOn } },
|
|
247
|
-
});
|
|
248
|
-
// Trigger consent event
|
|
249
|
-
await elb('walker consent', { marketing: true });
|
|
250
|
-
// Verify the async destination's on method was called
|
|
251
|
-
expect(asyncOnMethod).toHaveBeenCalledWith('consent', expect.objectContaining({
|
|
252
|
-
data: { marketing: true },
|
|
253
|
-
collector: expect.any(Object),
|
|
254
|
-
config: expect.any(Object),
|
|
255
|
-
env: expect.any(Object),
|
|
256
|
-
logger: expect.any(Object),
|
|
257
|
-
}));
|
|
258
|
-
});
|
|
259
|
-
it('should call on method for multiple destinations', async () => {
|
|
260
|
-
const mockOn1 = jest.fn();
|
|
261
|
-
const mockOn2 = jest.fn();
|
|
262
|
-
const destination1 = createDestination({
|
|
263
|
-
on: mockOn1,
|
|
264
|
-
config: { init: true },
|
|
265
|
-
});
|
|
266
|
-
const destination2 = createDestination({
|
|
267
|
-
on: mockOn2,
|
|
268
|
-
config: { init: true },
|
|
269
|
-
});
|
|
270
|
-
const { collector, elb } = await startFlow({
|
|
271
|
-
destinations: {
|
|
272
|
-
dest1: { code: destination1 },
|
|
273
|
-
dest2: { code: destination2 },
|
|
274
|
-
},
|
|
275
|
-
});
|
|
276
|
-
// Trigger consent event
|
|
277
|
-
await elb('walker consent', { marketing: true });
|
|
278
|
-
// Both destinations should receive the event
|
|
279
|
-
expect(mockOn1).toHaveBeenCalledWith('consent', expect.objectContaining({
|
|
280
|
-
data: { marketing: true },
|
|
281
|
-
collector: expect.any(Object),
|
|
282
|
-
config: expect.any(Object),
|
|
283
|
-
env: expect.any(Object),
|
|
284
|
-
logger: expect.any(Object),
|
|
285
|
-
}));
|
|
286
|
-
expect(mockOn2).toHaveBeenCalledWith('consent', expect.objectContaining({
|
|
287
|
-
data: { marketing: true },
|
|
288
|
-
collector: expect.any(Object),
|
|
289
|
-
config: expect.any(Object),
|
|
290
|
-
env: expect.any(Object),
|
|
291
|
-
logger: expect.any(Object),
|
|
292
|
-
}));
|
|
293
|
-
});
|
|
294
|
-
it('should handle on method errors gracefully', async () => {
|
|
295
|
-
const errorOnMethod = jest.fn().mockImplementation(() => {
|
|
296
|
-
throw new Error('On method error');
|
|
297
|
-
});
|
|
298
|
-
const destinationWithErrorOn = createDestination({
|
|
299
|
-
on: errorOnMethod,
|
|
300
|
-
config: { init: true },
|
|
301
|
-
});
|
|
302
|
-
const { collector, elb } = await startFlow({
|
|
303
|
-
destinations: { testDestination: { code: destinationWithErrorOn } },
|
|
304
|
-
});
|
|
305
|
-
// Should not throw even if on method throws an error
|
|
306
|
-
expect(async () => {
|
|
307
|
-
await elb('walker consent', { marketing: true });
|
|
308
|
-
}).not.toThrow();
|
|
309
|
-
// On method should still have been called
|
|
310
|
-
expect(errorOnMethod).toHaveBeenCalledWith('consent', expect.objectContaining({
|
|
311
|
-
data: { marketing: true },
|
|
312
|
-
collector: expect.any(Object),
|
|
313
|
-
config: expect.any(Object),
|
|
314
|
-
env: expect.any(Object),
|
|
315
|
-
logger: expect.any(Object),
|
|
316
|
-
}));
|
|
317
|
-
});
|
|
318
|
-
});
|
|
319
|
-
});
|
|
320
|
-
//# sourceMappingURL=destination.test.js.map
|