-
Notifications
You must be signed in to change notification settings - Fork 10
/
index.test.js
61 lines (54 loc) · 1.83 KB
/
index.test.js
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
const { createEvent, createIdentify, getMeta, resetMeta, clone } = require("@posthog/plugin-scaffold/test/utils");
const { processEvent } = require("./index");
beforeEach(() => {
// Making sure plugin meta has our custom test config
resetMeta({
config: {
greeting: "Dzień dobry!",
},
});
});
test("processEvent adds properties", async () => {
// Create a random event
const event0 = createEvent({ event: "booking completed", properties: { amount: "20", currency: "USD" } });
// Must clone the event since `processEvent` will mutate it
const event1 = await processEvent(clone(event0), getMeta());
expect(event1).toEqual({
...event0,
properties: {
...event0.properties,
greeting: "Dzień dobry!",
greeting_counter: 0,
random_number: 4,
},
});
const event2 = await processEvent(clone(event0), getMeta());
expect(event2).toEqual({
...event1,
properties: {
...event1.properties,
greeting_counter: 1,
},
});
const event3 = await processEvent(clone(event0), getMeta());
expect(event3).toEqual({
...event2,
properties: {
...event2.properties,
greeting_counter: 2,
},
});
});
test("processEvent does not crash with identify", async () => {
const defaultHelloWorldProperties = Object.freeze({
greeting: "Dzień dobry!",
greeting_counter: 0,
random_number: 4,
});
// Create a random event
const event0 = createIdentify();
// Must clone the event since `processEvent` will mutate it
const { properties, ...restOfEvent1 } = await processEvent(clone(event0), getMeta());
expect(restOfEvent1).toEqual(event0);
expect(properties).toEqual(defaultHelloWorldProperties);
});