forked from snowplow/snowplow-javascript-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp_context.test.ts
More file actions
76 lines (64 loc) · 2.3 KB
/
app_context.test.ts
File metadata and controls
76 lines (64 loc) · 2.3 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import { APPLICATION_CONTEXT_SCHEMA, MOBILE_APPLICATION_CONTEXT_SCHEMA } from '../../src/constants';
import { newAppContextPlugin } from '../../src/plugins/app_context';
import { buildPageView, Payload, trackerCore } from '@snowplow/tracker-core';
describe('Application context plugin', () => {
it('attaches mobile application context to events if both version and build passed', async () => {
const appContext = await newAppContextPlugin({
appBuild: '19',
appVersion: '1.0.1',
});
const payloads: Payload[] = [];
const tracker = trackerCore({
corePlugins: [appContext.plugin],
callback: (pb) => payloads.push(pb.build()),
base64: false,
});
tracker.track(buildPageView({ pageUrl: 'http://localhost' }));
expect(payloads.length).toBe(1);
expect(JSON.parse(payloads[0]?.co as string).data).toEqual([
{
schema: MOBILE_APPLICATION_CONTEXT_SCHEMA,
data: {
version: '1.0.1',
build: '19',
},
},
]);
});
it('attaches application context to events if only version passed', async () => {
const appContext = await newAppContextPlugin({
appVersion: '1.0.1',
});
const payloads: Payload[] = [];
const tracker = trackerCore({
corePlugins: [appContext.plugin],
callback: (pb) => payloads.push(pb.build()),
base64: false,
});
tracker.track(buildPageView({ pageUrl: 'http://localhost' }));
expect(payloads.length).toBe(1);
expect(JSON.parse(payloads[0]?.co as string).data).toEqual([
{
schema: APPLICATION_CONTEXT_SCHEMA,
data: {
version: '1.0.1',
},
},
]);
});
it('doesnt attach any application context to events if version not passed', async () => {
const appContext = await newAppContextPlugin({
appBuild: '19',
});
const payloads: Payload[] = [];
const tracker = trackerCore({
corePlugins: [appContext.plugin],
callback: (pb) => payloads.push(pb.build()),
base64: false,
});
tracker.track(buildPageView({ pageUrl: 'http://localhost' }));
expect(payloads.length).toBe(1);
expect((payloads[0]?.co as string) ?? '').not.toContain(MOBILE_APPLICATION_CONTEXT_SCHEMA);
expect((payloads[0]?.co as string) ?? '').not.toContain(APPLICATION_CONTEXT_SCHEMA);
});
});