forked from snowplow/snowplow-javascript-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp_install.test.ts
More file actions
94 lines (81 loc) · 2.5 KB
/
app_install.test.ts
File metadata and controls
94 lines (81 loc) · 2.5 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import { Payload, trackerCore } from '@snowplow/tracker-core';
import { newAppInstallPlugin } from '../../src/plugins/app_install';
import AsyncStorage from '@react-native-async-storage/async-storage';
import { APPLICATION_INSTALL_EVENT_SCHEMA } from '../../src/constants';
describe('Application install plugin', () => {
beforeEach(async () => {
await AsyncStorage.clear();
});
it('tracks an app install event on first tracker init', async () => {
const tracker = trackerCore({
callback: (pb) => payloads.push(pb.build()),
base64: false,
});
const appInstallPlugin = newAppInstallPlugin(
{
asyncStorage: AsyncStorage,
namespace: 'test',
installAutotracking: true,
},
tracker
);
tracker.addPlugin(appInstallPlugin);
const payloads: Payload[] = [];
await new Promise((resolve) => setTimeout(resolve, 50));
expect(payloads.length).toBe(1);
const [{ ue_pr }] = payloads as any;
expect(ue_pr).toContain(APPLICATION_INSTALL_EVENT_SCHEMA);
});
it('does not track an app install event on subsequent tracker inits', async () => {
const tracker1 = trackerCore({
callback: (pb) => payloads.push(pb.build()),
base64: false,
});
tracker1.addPlugin(
newAppInstallPlugin(
{
asyncStorage: AsyncStorage,
namespace: 'test',
installAutotracking: true,
},
tracker1
)
);
const payloads: Payload[] = [];
await new Promise((resolve) => setTimeout(resolve, 50));
expect(payloads.length).toBe(1);
const tracker2 = trackerCore({
callback: (pb) => payloads.push(pb.build()),
base64: false,
});
tracker2.addPlugin(
newAppInstallPlugin(
{
asyncStorage: AsyncStorage,
namespace: 'test',
installAutotracking: true,
},
tracker2
)
);
await new Promise((resolve) => setTimeout(resolve, 50));
expect(payloads.length).toBe(1);
});
it('does not track an app install event when autotracking is disabled', async () => {
const tracker = trackerCore({
callback: (pb) => payloads.push(pb.build()),
base64: false,
});
const appInstallPlugin = newAppInstallPlugin(
{
asyncStorage: AsyncStorage,
namespace: 'test',
},
tracker
);
tracker.addPlugin(appInstallPlugin);
const payloads: Payload[] = [];
await new Promise((resolve) => setTimeout(resolve, 50));
expect(payloads.length).toBe(0);
});
});