@walkeros/collector 0.5.1-next.0 → 0.6.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/__tests__/auto-run.test.d.ts +2 -0
- package/dist/__tests__/auto-run.test.d.ts.map +1 -0
- package/dist/__tests__/auto-run.test.js +102 -0
- package/dist/__tests__/auto-run.test.js.map +1 -0
- package/dist/__tests__/consent.test.d.ts +2 -0
- package/dist/__tests__/consent.test.d.ts.map +1 -0
- package/dist/__tests__/consent.test.js +21 -0
- package/dist/__tests__/consent.test.js.map +1 -0
- package/dist/__tests__/create-flow.test.d.ts +2 -0
- package/dist/__tests__/create-flow.test.d.ts.map +1 -0
- package/dist/__tests__/create-flow.test.js +69 -0
- package/dist/__tests__/create-flow.test.js.map +1 -0
- package/dist/__tests__/destination-code.test.d.ts +2 -0
- package/dist/__tests__/destination-code.test.d.ts.map +1 -0
- package/dist/__tests__/destination-code.test.js +396 -0
- package/dist/__tests__/destination-code.test.js.map +1 -0
- package/dist/__tests__/destination.test.d.ts +2 -0
- package/dist/__tests__/destination.test.d.ts.map +1 -0
- package/dist/__tests__/destination.test.js +471 -0
- package/dist/__tests__/destination.test.js.map +1 -0
- package/dist/__tests__/handle.test.d.ts +2 -0
- package/dist/__tests__/handle.test.d.ts.map +1 -0
- package/dist/__tests__/handle.test.js +78 -0
- package/dist/__tests__/handle.test.js.map +1 -0
- package/dist/__tests__/mapping.test.d.ts +2 -0
- package/dist/__tests__/mapping.test.d.ts.map +1 -0
- package/dist/__tests__/mapping.test.js +310 -0
- package/dist/__tests__/mapping.test.js.map +1 -0
- package/dist/__tests__/source.test.d.ts +2 -0
- package/dist/__tests__/source.test.d.ts.map +1 -0
- package/dist/__tests__/source.test.js +306 -0
- package/dist/__tests__/source.test.js.map +1 -0
- package/dist/__tests__/start-flow.test.d.ts +2 -0
- package/dist/__tests__/start-flow.test.d.ts.map +1 -0
- package/dist/__tests__/start-flow.test.js +167 -0
- package/dist/__tests__/start-flow.test.js.map +1 -0
- package/dist/__tests__/walker-entity.test.d.ts +2 -0
- package/dist/__tests__/walker-entity.test.d.ts.map +1 -0
- package/dist/__tests__/walker-entity.test.js +52 -0
- package/dist/__tests__/walker-entity.test.js.map +1 -0
- package/dist/collector.d.ts +3 -0
- package/dist/collector.d.ts.map +1 -0
- package/dist/collector.js +60 -0
- package/dist/collector.js.map +1 -0
- package/dist/command.d.ts +12 -0
- package/dist/command.d.ts.map +1 -0
- package/dist/command.js +20 -0
- package/dist/command.js.map +1 -0
- package/dist/consent.d.ts +10 -0
- package/dist/consent.d.ts.map +1 -0
- package/dist/consent.js +30 -0
- package/dist/consent.js.map +1 -0
- package/dist/constants.d.ts +13 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +35 -0
- package/dist/constants.js.map +1 -0
- package/dist/destination-code.d.ts +4 -0
- package/dist/destination-code.d.ts.map +1 -0
- package/dist/destination-code.js +72 -0
- package/dist/destination-code.js.map +1 -0
- package/dist/destination.d.ts +61 -0
- package/dist/destination.d.ts.map +1 -0
- package/dist/destination.js +325 -0
- package/dist/destination.js.map +1 -0
- package/dist/dev.d.ts.map +1 -0
- package/dist/elb.d.ts +11 -0
- package/dist/elb.d.ts.map +1 -0
- package/dist/elb.js +60 -0
- package/dist/elb.js.map +1 -0
- package/dist/flow.d.ts +4 -0
- package/dist/flow.d.ts.map +1 -0
- package/dist/flow.js +44 -0
- package/dist/flow.js.map +1 -0
- package/dist/handle.d.ts +29 -0
- package/dist/handle.d.ts.map +1 -0
- package/dist/handle.js +161 -0
- package/dist/handle.js.map +1 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/dist/on.d.ts +19 -0
- package/dist/on.d.ts.map +1 -0
- package/dist/on.js +127 -0
- package/dist/on.js.map +1 -0
- package/dist/push.d.ts +11 -0
- package/dist/push.d.ts.map +1 -0
- package/dist/push.js +43 -0
- package/dist/push.js.map +1 -0
- package/dist/source.d.ts +10 -0
- package/dist/source.d.ts.map +1 -0
- package/dist/source.js +47 -0
- package/dist/source.js.map +1 -0
- package/dist/types/code.d.ts +23 -0
- package/dist/types/code.d.ts.map +1 -0
- package/dist/types/code.js +2 -0
- package/dist/types/code.js.map +1 -0
- package/dist/types/collector.d.ts +19 -0
- package/dist/types/collector.d.ts.map +1 -0
- package/dist/types/collector.js +2 -0
- package/dist/types/collector.js.map +1 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +4 -0
- package/dist/types/index.js.map +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auto-run.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/auto-run.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { startFlow } from '..';
|
|
2
|
+
describe('Auto-run functionality', () => {
|
|
3
|
+
describe('startFlow auto-run behavior', () => {
|
|
4
|
+
test('auto-runs by default (collector.allowed should be true)', async () => {
|
|
5
|
+
const { collector } = await startFlow();
|
|
6
|
+
// Default behavior should auto-run and set allowed to true
|
|
7
|
+
expect(collector.allowed).toBe(true);
|
|
8
|
+
expect(collector.config.run).toBe(true);
|
|
9
|
+
});
|
|
10
|
+
test('auto-runs when explicitly set to true (collector.allowed should be true)', async () => {
|
|
11
|
+
const { collector } = await startFlow({ run: true });
|
|
12
|
+
// Explicitly setting run: true should auto-run and set allowed to true
|
|
13
|
+
expect(collector.allowed).toBe(true);
|
|
14
|
+
expect(collector.config.run).toBe(true);
|
|
15
|
+
});
|
|
16
|
+
test('does not auto-run when set to false (collector.allowed should be false)', async () => {
|
|
17
|
+
const { collector } = await startFlow({ run: false });
|
|
18
|
+
// Setting run: false should NOT auto-run and allowed should stay false
|
|
19
|
+
expect(collector.allowed).toBe(false);
|
|
20
|
+
expect(collector.config.run).toBe(false);
|
|
21
|
+
});
|
|
22
|
+
test('manual run after initialization with run: false should set allowed to true', async () => {
|
|
23
|
+
const { collector, elb } = await startFlow({ run: false });
|
|
24
|
+
// Initially should not be allowed
|
|
25
|
+
expect(collector.allowed).toBe(false);
|
|
26
|
+
// Manual run should set allowed to true
|
|
27
|
+
await elb('walker run');
|
|
28
|
+
expect(collector.allowed).toBe(true);
|
|
29
|
+
});
|
|
30
|
+
test('config state is preserved correctly for different run values', async () => {
|
|
31
|
+
// Test with run: true
|
|
32
|
+
const collectorTrue = await startFlow({ run: true });
|
|
33
|
+
expect(collectorTrue.collector.config.run).toBe(true);
|
|
34
|
+
expect(collectorTrue.collector.allowed).toBe(true);
|
|
35
|
+
// Test with run: false
|
|
36
|
+
const collectorFalse = await startFlow({
|
|
37
|
+
run: false,
|
|
38
|
+
});
|
|
39
|
+
expect(collectorFalse.collector.config.run).toBe(false);
|
|
40
|
+
expect(collectorFalse.collector.allowed).toBe(false);
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
describe('auto-run with additional configuration', () => {
|
|
44
|
+
test('applies consent during auto-run', async () => {
|
|
45
|
+
const testConsent = { functional: true, marketing: false };
|
|
46
|
+
const { collector } = await startFlow({
|
|
47
|
+
run: true,
|
|
48
|
+
consent: testConsent,
|
|
49
|
+
});
|
|
50
|
+
expect(collector.allowed).toBe(true);
|
|
51
|
+
expect(collector.consent).toEqual(testConsent);
|
|
52
|
+
});
|
|
53
|
+
test('applies user data during auto-run', async () => {
|
|
54
|
+
const testUser = { id: 'test-user-123', custom: { type: 'premium' } };
|
|
55
|
+
const { collector } = await startFlow({
|
|
56
|
+
run: true,
|
|
57
|
+
user: testUser,
|
|
58
|
+
});
|
|
59
|
+
expect(collector.allowed).toBe(true);
|
|
60
|
+
expect(collector.user).toEqual(testUser);
|
|
61
|
+
});
|
|
62
|
+
test('applies globals during auto-run', async () => {
|
|
63
|
+
const testGlobals = { page_title: 'Test Page', environment: 'test' };
|
|
64
|
+
const { collector } = await startFlow({
|
|
65
|
+
run: true,
|
|
66
|
+
globals: testGlobals,
|
|
67
|
+
});
|
|
68
|
+
expect(collector.allowed).toBe(true);
|
|
69
|
+
expect(collector.globals).toEqual(expect.objectContaining(testGlobals));
|
|
70
|
+
});
|
|
71
|
+
test('applies custom data during auto-run', async () => {
|
|
72
|
+
const testCustom = { tracking_id: 'GTM-12345', debug: true };
|
|
73
|
+
const { collector } = await startFlow({
|
|
74
|
+
run: true,
|
|
75
|
+
custom: testCustom,
|
|
76
|
+
});
|
|
77
|
+
expect(collector.allowed).toBe(true);
|
|
78
|
+
expect(collector.custom).toEqual(testCustom);
|
|
79
|
+
});
|
|
80
|
+
test('does not apply additional config when run: false', async () => {
|
|
81
|
+
const testConsent = { functional: true, marketing: false };
|
|
82
|
+
const testUser = { id: 'test-user-123' };
|
|
83
|
+
const testGlobals = { page_title: 'Test Page' };
|
|
84
|
+
const testCustom = { tracking_id: 'GTM-12345' };
|
|
85
|
+
const { collector } = await startFlow({
|
|
86
|
+
run: false,
|
|
87
|
+
consent: testConsent,
|
|
88
|
+
user: testUser,
|
|
89
|
+
globals: testGlobals,
|
|
90
|
+
custom: testCustom,
|
|
91
|
+
});
|
|
92
|
+
// Should not be allowed since we didn't run
|
|
93
|
+
expect(collector.allowed).toBe(false);
|
|
94
|
+
// But the config should still be stored for potential later use
|
|
95
|
+
expect(collector.consent).toEqual(testConsent);
|
|
96
|
+
expect(collector.user).toEqual(testUser);
|
|
97
|
+
expect(collector.globals).toEqual(expect.objectContaining(testGlobals));
|
|
98
|
+
expect(collector.custom).toEqual(testCustom);
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
//# sourceMappingURL=auto-run.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auto-run.test.js","sourceRoot":"","sources":["../../src/__tests__/auto-run.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAE/B,QAAQ,CAAC,wBAAwB,EAAE,GAAG,EAAE;IACtC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MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;QAC/C,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consent.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/consent.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { getGrantedConsent } from '@walkeros/core';
|
|
2
|
+
describe('consent', () => {
|
|
3
|
+
test('nothing required', () => {
|
|
4
|
+
expect(getGrantedConsent(undefined, { foo: true })).toStrictEqual({
|
|
5
|
+
foo: true,
|
|
6
|
+
});
|
|
7
|
+
});
|
|
8
|
+
test('denied', () => {
|
|
9
|
+
expect(getGrantedConsent({ marketing: true }, { functional: true, marketing: false })).toBeFalsy();
|
|
10
|
+
});
|
|
11
|
+
test('granted by destination', () => {
|
|
12
|
+
expect(getGrantedConsent({ functional: true }, { functional: true })).toStrictEqual({ functional: true });
|
|
13
|
+
});
|
|
14
|
+
test('granted individually', () => {
|
|
15
|
+
expect(getGrantedConsent({ marketing: true }, { marketing: false }, { marketing: true })).toStrictEqual({ marketing: true });
|
|
16
|
+
});
|
|
17
|
+
test('granted states', () => {
|
|
18
|
+
expect(getGrantedConsent({ foo: true }, { foo: true }, { bar: true })).toStrictEqual({ foo: true, bar: true });
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
//# sourceMappingURL=consent.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consent.test.js","sourceRoot":"","sources":["../../src/__tests__/consent.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAEnD,QAAQ,CAAC,SAAS,EAAE,GAAG,EAAE;IACvB,IAAI,CAAC,kBAAkB,EAAE,GAAG,EAAE;QAC5B,MAAM,CAAC,iBAAiB,CA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|
1
|
+
{"version":3,"file":"create-flow.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/create-flow.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { startFlow } from '../flow';
|
|
2
|
+
describe('Source Create Flow Integration', () => {
|
|
3
|
+
it('should initialize complete setup from flow config', async () => {
|
|
4
|
+
const mockPushCalls = [];
|
|
5
|
+
const mockSource = async (config, env) => {
|
|
6
|
+
expect(config).toEqual({
|
|
7
|
+
settings: {
|
|
8
|
+
test: 'value',
|
|
9
|
+
},
|
|
10
|
+
});
|
|
11
|
+
expect(env).toMatchObject({
|
|
12
|
+
push: expect.any(Function),
|
|
13
|
+
command: expect.any(Function),
|
|
14
|
+
sources: expect.any(Object),
|
|
15
|
+
elb: expect.any(Function),
|
|
16
|
+
foo: 'bar',
|
|
17
|
+
});
|
|
18
|
+
return {
|
|
19
|
+
type: 'mock',
|
|
20
|
+
config: {
|
|
21
|
+
settings: config.settings || {},
|
|
22
|
+
},
|
|
23
|
+
push: env.push, // Required push method
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
const { collector, elb } = await startFlow({
|
|
27
|
+
sources: {
|
|
28
|
+
mockSource: {
|
|
29
|
+
code: mockSource,
|
|
30
|
+
config: {
|
|
31
|
+
settings: {
|
|
32
|
+
test: 'value',
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
env: {
|
|
36
|
+
foo: 'bar',
|
|
37
|
+
// elb will be injected by collector
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
destinations: {
|
|
42
|
+
test: {
|
|
43
|
+
code: {
|
|
44
|
+
type: 'test',
|
|
45
|
+
config: {},
|
|
46
|
+
push: (event) => {
|
|
47
|
+
mockPushCalls.push(event);
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
expect(collector.sources.mockSource).toEqual({
|
|
54
|
+
type: 'mock',
|
|
55
|
+
config: {
|
|
56
|
+
settings: { test: 'value' },
|
|
57
|
+
},
|
|
58
|
+
push: expect.any(Function),
|
|
59
|
+
});
|
|
60
|
+
expect(collector.sources.elb).toBeDefined();
|
|
61
|
+
await elb({ name: 'manual event', data: { test: 'data' } });
|
|
62
|
+
expect(mockPushCalls).toHaveLength(1);
|
|
63
|
+
expect(mockPushCalls[0]).toMatchObject({
|
|
64
|
+
name: 'manual event',
|
|
65
|
+
data: { test: 'data' },
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
//# sourceMappingURL=create-flow.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-flow.test.js","sourceRoot":"","sources":["../../src/__tests__/create-flow.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAGpC,QAAQ,CAAC,gCAAgC,EAAE,GAAG,EAAE;IAC9C,EAAE,CAAC,mDAAmD,EAAE,KAAK,IAAI,EAAE;QACjE,MAAM,aAAa,GAAqB,EAAE,CAAC;QAE3C,MAAM,UAAU,GAAgB,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,EAAE;YACpD,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC;gBACrB,QAAQ,EAAE;oBACR,IAAI,EAAE,OAAO;iBACd;aACF,CAAC,CAAC;YAEH,MAAM,CAAC,GAAG,CAAC,CAAC,aAAa,CAAC;gBACxB,IAAI,EAAE,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;gBAC1B,OAAO,EAAE,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;gBAC7B,OAAO,EAAE,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC;gBAC3B,GAAG,EAAE,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;gBACzB,GAAG,EAAE,KAAK;aACX,CAAC,CAAC;YAEH,OAAO;gBACL,IAAI,EAAE,MAAM;gBACZ,MA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AAa,CAAC;YACrC,IAAI,EAAE,cAAc;YACpB,IAAI,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE;SACvB,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"destination-code.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/destination-code.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,396 @@
|
|
|
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('accepts scripts array in settings', () => {
|
|
33
|
+
const settings = {
|
|
34
|
+
scripts: [
|
|
35
|
+
'https://example.com/analytics.js',
|
|
36
|
+
'https://example.com/pixel.js',
|
|
37
|
+
],
|
|
38
|
+
init: "console.log('ready')",
|
|
39
|
+
};
|
|
40
|
+
expect(settings.scripts).toHaveLength(2);
|
|
41
|
+
});
|
|
42
|
+
it('injects script tags for each URL in scripts array', () => {
|
|
43
|
+
const initialScriptCount = document.head.querySelectorAll('script').length;
|
|
44
|
+
const context = {
|
|
45
|
+
collector: createMockCollector(),
|
|
46
|
+
config: {
|
|
47
|
+
settings: {
|
|
48
|
+
scripts: ['https://example.com/a.js', 'https://example.com/b.js'],
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
env: {},
|
|
52
|
+
logger: createMockLogger(),
|
|
53
|
+
};
|
|
54
|
+
destinationCode.init(context);
|
|
55
|
+
const scripts = document.head.querySelectorAll('script');
|
|
56
|
+
expect(scripts.length).toBe(initialScriptCount + 2);
|
|
57
|
+
const addedScripts = Array.from(scripts).slice(-2);
|
|
58
|
+
expect(addedScripts[0].src).toBe('https://example.com/a.js');
|
|
59
|
+
expect(addedScripts[0].async).toBe(true);
|
|
60
|
+
expect(addedScripts[1].src).toBe('https://example.com/b.js');
|
|
61
|
+
expect(addedScripts[1].async).toBe(true);
|
|
62
|
+
});
|
|
63
|
+
it('injects scripts before running init code', () => {
|
|
64
|
+
const initialScriptCount = document.head.querySelectorAll('script').length;
|
|
65
|
+
const mockLogger = createMockLogger();
|
|
66
|
+
const context = {
|
|
67
|
+
collector: createMockCollector(),
|
|
68
|
+
config: {
|
|
69
|
+
settings: {
|
|
70
|
+
scripts: ['https://example.com/lib.js'],
|
|
71
|
+
init: "context.logger.info('init ran')",
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
env: {},
|
|
75
|
+
logger: mockLogger,
|
|
76
|
+
};
|
|
77
|
+
destinationCode.init(context);
|
|
78
|
+
// Scripts should be injected
|
|
79
|
+
const scripts = document.head.querySelectorAll('script');
|
|
80
|
+
expect(scripts.length).toBe(initialScriptCount + 1);
|
|
81
|
+
expect(Array.from(scripts).pop()?.src).toBe('https://example.com/lib.js');
|
|
82
|
+
// Init code should also run
|
|
83
|
+
expect(mockLogger.info).toHaveBeenCalledWith('init ran');
|
|
84
|
+
});
|
|
85
|
+
it('executes init code string', () => {
|
|
86
|
+
const mockLogger = createMockLogger();
|
|
87
|
+
const context = {
|
|
88
|
+
collector: createMockCollector(),
|
|
89
|
+
config: {
|
|
90
|
+
settings: {
|
|
91
|
+
init: "context.logger.info('initialized')",
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
env: {},
|
|
95
|
+
logger: mockLogger,
|
|
96
|
+
};
|
|
97
|
+
destinationCode.init(context);
|
|
98
|
+
expect(mockLogger.info).toHaveBeenCalledWith('initialized');
|
|
99
|
+
});
|
|
100
|
+
it('handles empty scripts array gracefully', () => {
|
|
101
|
+
const initialScriptCount = document.head.querySelectorAll('script').length;
|
|
102
|
+
const mockLogger = createMockLogger();
|
|
103
|
+
const context = {
|
|
104
|
+
collector: createMockCollector(),
|
|
105
|
+
config: {
|
|
106
|
+
settings: {
|
|
107
|
+
scripts: [],
|
|
108
|
+
init: "context.logger.info('init ran')",
|
|
109
|
+
},
|
|
110
|
+
},
|
|
111
|
+
env: {},
|
|
112
|
+
logger: mockLogger,
|
|
113
|
+
};
|
|
114
|
+
expect(() => destinationCode.init(context)).not.toThrow();
|
|
115
|
+
// No scripts should be added
|
|
116
|
+
expect(document.head.querySelectorAll('script').length).toBe(initialScriptCount);
|
|
117
|
+
// Init code should still run
|
|
118
|
+
expect(mockLogger.info).toHaveBeenCalledWith('init ran');
|
|
119
|
+
});
|
|
120
|
+
it('handles missing init code gracefully', () => {
|
|
121
|
+
const context = {
|
|
122
|
+
collector: createMockCollector(),
|
|
123
|
+
config: { settings: {} },
|
|
124
|
+
env: {},
|
|
125
|
+
logger: createMockLogger(),
|
|
126
|
+
};
|
|
127
|
+
expect(() => destinationCode.init(context)).not.toThrow();
|
|
128
|
+
});
|
|
129
|
+
it('catches and logs errors in init code', () => {
|
|
130
|
+
const mockLogger = createMockLogger();
|
|
131
|
+
const context = {
|
|
132
|
+
collector: createMockCollector(),
|
|
133
|
+
config: {
|
|
134
|
+
settings: {
|
|
135
|
+
init: "throw new Error('test error')",
|
|
136
|
+
},
|
|
137
|
+
},
|
|
138
|
+
env: {},
|
|
139
|
+
logger: mockLogger,
|
|
140
|
+
};
|
|
141
|
+
destinationCode.init(context);
|
|
142
|
+
expect(mockLogger.error).toHaveBeenCalled();
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
describe('push', () => {
|
|
146
|
+
it('executes push code from mapping', () => {
|
|
147
|
+
const mockLogger = createMockLogger();
|
|
148
|
+
const context = {
|
|
149
|
+
collector: createMockCollector(),
|
|
150
|
+
config: {},
|
|
151
|
+
data: { transformed: true },
|
|
152
|
+
env: {},
|
|
153
|
+
logger: mockLogger,
|
|
154
|
+
mapping: {
|
|
155
|
+
push: 'context.logger.info(event.name, context.data)',
|
|
156
|
+
},
|
|
157
|
+
};
|
|
158
|
+
destinationCode.push(createEvent({ name: 'product view' }), context);
|
|
159
|
+
expect(mockLogger.info).toHaveBeenCalledWith('product view', {
|
|
160
|
+
transformed: true,
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
it('falls back to settings.push when mapping.push is missing', () => {
|
|
164
|
+
const mockLogger = createMockLogger();
|
|
165
|
+
const context = {
|
|
166
|
+
collector: createMockCollector(),
|
|
167
|
+
config: {
|
|
168
|
+
settings: {
|
|
169
|
+
push: "context.logger.info('settings fallback')",
|
|
170
|
+
},
|
|
171
|
+
},
|
|
172
|
+
data: {},
|
|
173
|
+
env: {},
|
|
174
|
+
logger: mockLogger,
|
|
175
|
+
mapping: {},
|
|
176
|
+
};
|
|
177
|
+
destinationCode.push(createEvent({ name: 'product view' }), context);
|
|
178
|
+
expect(mockLogger.info).toHaveBeenCalledWith('settings fallback');
|
|
179
|
+
});
|
|
180
|
+
it('prefers mapping.push over settings.push', () => {
|
|
181
|
+
const mockLogger = createMockLogger();
|
|
182
|
+
const context = {
|
|
183
|
+
collector: createMockCollector(),
|
|
184
|
+
config: {
|
|
185
|
+
settings: {
|
|
186
|
+
push: "context.logger.info('from settings')",
|
|
187
|
+
},
|
|
188
|
+
},
|
|
189
|
+
data: {},
|
|
190
|
+
env: {},
|
|
191
|
+
logger: mockLogger,
|
|
192
|
+
mapping: {
|
|
193
|
+
push: "context.logger.info('from mapping')",
|
|
194
|
+
},
|
|
195
|
+
};
|
|
196
|
+
destinationCode.push(createEvent({ name: 'product view' }), context);
|
|
197
|
+
expect(mockLogger.info).toHaveBeenCalledWith('from mapping');
|
|
198
|
+
expect(mockLogger.info).not.toHaveBeenCalledWith('from settings');
|
|
199
|
+
});
|
|
200
|
+
it('handles missing push code gracefully', () => {
|
|
201
|
+
const context = {
|
|
202
|
+
collector: createMockCollector(),
|
|
203
|
+
config: {},
|
|
204
|
+
env: {},
|
|
205
|
+
logger: createMockLogger(),
|
|
206
|
+
mapping: {},
|
|
207
|
+
data: {},
|
|
208
|
+
};
|
|
209
|
+
expect(() => destinationCode.push(createEvent({ name: 'product view' }), context)).not.toThrow();
|
|
210
|
+
});
|
|
211
|
+
it('catches and logs errors in push code', () => {
|
|
212
|
+
const mockLogger = createMockLogger();
|
|
213
|
+
const context = {
|
|
214
|
+
collector: createMockCollector(),
|
|
215
|
+
config: {},
|
|
216
|
+
env: {},
|
|
217
|
+
logger: mockLogger,
|
|
218
|
+
mapping: {
|
|
219
|
+
push: "throw new Error('test error')",
|
|
220
|
+
},
|
|
221
|
+
data: {},
|
|
222
|
+
};
|
|
223
|
+
destinationCode.push(createEvent({ name: 'product view' }), context);
|
|
224
|
+
expect(mockLogger.error).toHaveBeenCalled();
|
|
225
|
+
});
|
|
226
|
+
});
|
|
227
|
+
describe('pushBatch', () => {
|
|
228
|
+
it('executes pushBatch code from mapping', () => {
|
|
229
|
+
const mockLogger = createMockLogger();
|
|
230
|
+
const batch = {
|
|
231
|
+
key: 'product view',
|
|
232
|
+
events: [
|
|
233
|
+
createEvent({ name: 'product view', id: '1' }),
|
|
234
|
+
createEvent({ name: 'product view', id: '2' }),
|
|
235
|
+
],
|
|
236
|
+
data: [{ id: '1' }, { id: '2' }],
|
|
237
|
+
};
|
|
238
|
+
const context = {
|
|
239
|
+
collector: createMockCollector(),
|
|
240
|
+
config: {},
|
|
241
|
+
env: {},
|
|
242
|
+
logger: mockLogger,
|
|
243
|
+
mapping: {
|
|
244
|
+
pushBatch: "context.logger.info('batch size:', batch.events.length)",
|
|
245
|
+
},
|
|
246
|
+
};
|
|
247
|
+
destinationCode.pushBatch(batch, context);
|
|
248
|
+
expect(mockLogger.info).toHaveBeenCalledWith('batch size:', 2);
|
|
249
|
+
});
|
|
250
|
+
it('falls back to settings.pushBatch when mapping.pushBatch is missing', () => {
|
|
251
|
+
const mockLogger = createMockLogger();
|
|
252
|
+
const batch = {
|
|
253
|
+
key: 'test',
|
|
254
|
+
events: [],
|
|
255
|
+
data: [],
|
|
256
|
+
};
|
|
257
|
+
const context = {
|
|
258
|
+
collector: createMockCollector(),
|
|
259
|
+
config: {
|
|
260
|
+
settings: {
|
|
261
|
+
pushBatch: "context.logger.info('batch settings fallback')",
|
|
262
|
+
},
|
|
263
|
+
},
|
|
264
|
+
env: {},
|
|
265
|
+
logger: mockLogger,
|
|
266
|
+
mapping: {},
|
|
267
|
+
};
|
|
268
|
+
destinationCode.pushBatch(batch, context);
|
|
269
|
+
expect(mockLogger.info).toHaveBeenCalledWith('batch settings fallback');
|
|
270
|
+
});
|
|
271
|
+
it('handles missing pushBatch code gracefully', () => {
|
|
272
|
+
const batch = {
|
|
273
|
+
key: 'test',
|
|
274
|
+
events: [],
|
|
275
|
+
data: [],
|
|
276
|
+
};
|
|
277
|
+
const context = {
|
|
278
|
+
collector: createMockCollector(),
|
|
279
|
+
config: {},
|
|
280
|
+
env: {},
|
|
281
|
+
logger: createMockLogger(),
|
|
282
|
+
mapping: {},
|
|
283
|
+
};
|
|
284
|
+
expect(() => destinationCode.pushBatch(batch, context)).not.toThrow();
|
|
285
|
+
});
|
|
286
|
+
it('catches and logs errors in pushBatch code', () => {
|
|
287
|
+
const mockLogger = createMockLogger();
|
|
288
|
+
const batch = {
|
|
289
|
+
key: 'test',
|
|
290
|
+
events: [],
|
|
291
|
+
data: [],
|
|
292
|
+
};
|
|
293
|
+
const context = {
|
|
294
|
+
collector: createMockCollector(),
|
|
295
|
+
config: {},
|
|
296
|
+
env: {},
|
|
297
|
+
logger: mockLogger,
|
|
298
|
+
mapping: {
|
|
299
|
+
pushBatch: "throw new Error('test error')",
|
|
300
|
+
},
|
|
301
|
+
};
|
|
302
|
+
destinationCode.pushBatch(batch, context);
|
|
303
|
+
expect(mockLogger.error).toHaveBeenCalled();
|
|
304
|
+
});
|
|
305
|
+
});
|
|
306
|
+
describe('on', () => {
|
|
307
|
+
it('executes on code string', () => {
|
|
308
|
+
const mockLogger = createMockLogger();
|
|
309
|
+
const context = {
|
|
310
|
+
collector: createMockCollector(),
|
|
311
|
+
config: {
|
|
312
|
+
settings: {
|
|
313
|
+
on: "if (type === 'consent') context.logger.info('consent:', context.data)",
|
|
314
|
+
},
|
|
315
|
+
},
|
|
316
|
+
data: { marketing: true },
|
|
317
|
+
env: {},
|
|
318
|
+
logger: mockLogger,
|
|
319
|
+
};
|
|
320
|
+
destinationCode.on('consent', context);
|
|
321
|
+
expect(mockLogger.info).toHaveBeenCalledWith('consent:', {
|
|
322
|
+
marketing: true,
|
|
323
|
+
});
|
|
324
|
+
});
|
|
325
|
+
it('handles missing on code gracefully', () => {
|
|
326
|
+
const context = {
|
|
327
|
+
collector: createMockCollector(),
|
|
328
|
+
config: { settings: {} },
|
|
329
|
+
env: {},
|
|
330
|
+
logger: createMockLogger(),
|
|
331
|
+
};
|
|
332
|
+
expect(() => destinationCode.on('consent', context)).not.toThrow();
|
|
333
|
+
});
|
|
334
|
+
it('catches and logs errors in on code', () => {
|
|
335
|
+
const mockLogger = createMockLogger();
|
|
336
|
+
const context = {
|
|
337
|
+
collector: createMockCollector(),
|
|
338
|
+
config: {
|
|
339
|
+
settings: {
|
|
340
|
+
on: "throw new Error('test error')",
|
|
341
|
+
},
|
|
342
|
+
},
|
|
343
|
+
env: {},
|
|
344
|
+
logger: mockLogger,
|
|
345
|
+
};
|
|
346
|
+
destinationCode.on('consent', context);
|
|
347
|
+
expect(mockLogger.error).toHaveBeenCalled();
|
|
348
|
+
});
|
|
349
|
+
});
|
|
350
|
+
});
|
|
351
|
+
describe('code: true initialization', () => {
|
|
352
|
+
it('uses built-in destinationCode when code is true', async () => {
|
|
353
|
+
const collector = {
|
|
354
|
+
logger: createMockLogger(),
|
|
355
|
+
};
|
|
356
|
+
const destinations = await initDestinations(collector, {
|
|
357
|
+
myCodeDest: {
|
|
358
|
+
code: true,
|
|
359
|
+
config: {
|
|
360
|
+
settings: {
|
|
361
|
+
init: "context.logger.info('ready')",
|
|
362
|
+
},
|
|
363
|
+
},
|
|
364
|
+
},
|
|
365
|
+
});
|
|
366
|
+
expect(destinations.myCodeDest).toBeDefined();
|
|
367
|
+
expect(destinations.myCodeDest.type).toBe('code');
|
|
368
|
+
expect(destinations.myCodeDest.init).toBeDefined();
|
|
369
|
+
expect(destinations.myCodeDest.push).toBeDefined();
|
|
370
|
+
});
|
|
371
|
+
it('preserves provided config with code: true', async () => {
|
|
372
|
+
const collector = {
|
|
373
|
+
logger: createMockLogger(),
|
|
374
|
+
};
|
|
375
|
+
const destinations = await initDestinations(collector, {
|
|
376
|
+
myCodeDest: {
|
|
377
|
+
code: true,
|
|
378
|
+
config: {
|
|
379
|
+
settings: {
|
|
380
|
+
init: "context.logger.info('custom init')",
|
|
381
|
+
push: "context.logger.info('custom push')",
|
|
382
|
+
},
|
|
383
|
+
consent: { functional: true },
|
|
384
|
+
},
|
|
385
|
+
},
|
|
386
|
+
});
|
|
387
|
+
expect(destinations.myCodeDest.config.settings).toEqual({
|
|
388
|
+
init: "context.logger.info('custom init')",
|
|
389
|
+
push: "context.logger.info('custom push')",
|
|
390
|
+
});
|
|
391
|
+
expect(destinations.myCodeDest.config.consent).toEqual({
|
|
392
|
+
functional: true,
|
|
393
|
+
});
|
|
394
|
+
});
|
|
395
|
+
});
|
|
396
|
+
//# sourceMappingURL=destination-code.test.js.map
|