-
Notifications
You must be signed in to change notification settings - Fork 306
Expand file tree
/
Copy pathsnapshot.test.ts
More file actions
111 lines (93 loc) · 3.15 KB
/
snapshot.test.ts
File metadata and controls
111 lines (93 loc) · 3.15 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import { createTestEvent, createTestIntegration } from '@segment/actions-core'
import { generateTestData } from '../../../lib/test-data'
import destination from '../index'
import nock from 'nock'
const testDestination = createTestIntegration(destination)
const destinationSlug = 'actions-memora'
// Mock Date.now() to return a fixed timestamp for consistent snapshots
const FIXED_TIMESTAMP = 1700000000000
const originalDateNow = Date.now
beforeAll(() => {
Date.now = jest.fn(() => FIXED_TIMESTAMP)
})
afterAll(() => {
Date.now = originalDateNow
})
describe(`Testing snapshot for ${destinationSlug} destination:`, () => {
for (const actionSlug in destination.actions) {
it(`${actionSlug} action - required fields`, async () => {
const seedName = `${destinationSlug}#${actionSlug}`
const action = destination.actions[actionSlug]
const [eventData, settingsData] = generateTestData(seedName, destination, action, true)
nock(/.*/).persist().get(/.*/).reply(200)
nock(/.*/).persist().put(/.*/).reply(202)
const event = createTestEvent({
properties: eventData
})
// Add memora_store to mapping since it's required
const mapping = {
...event.properties,
memora_store: 'test-store-id',
profile_identifiers: {
'Contact.$.email': 'test@example.com'
},
profile_traits: {
'Contact.$.firstName': 'Test'
}
}
const responses = await testDestination.testAction(actionSlug, {
event: event,
mapping: mapping,
settings: settingsData,
auth: undefined
})
const request = responses[0].request
const rawBody = await request.text()
try {
const json = JSON.parse(rawBody)
expect(json).toMatchSnapshot()
return
} catch (err) {
expect(rawBody).toMatchSnapshot()
}
expect(request.headers).toMatchSnapshot()
})
it(`${actionSlug} action - all fields`, async () => {
const seedName = `${destinationSlug}#${actionSlug}`
const action = destination.actions[actionSlug]
const [eventData, settingsData] = generateTestData(seedName, destination, action, false)
nock(/.*/).persist().get(/.*/).reply(200)
nock(/.*/).persist().put(/.*/).reply(202)
const event = createTestEvent({
properties: eventData
})
// Add memora_store to mapping since it's required
const mapping = {
...event.properties,
memora_store: 'test-store-id',
profile_identifiers: {
'Contact.$.email': 'test@example.com'
},
profile_traits: {
'Contact.$.firstName': 'Test',
'Contact.$.lastName': 'User'
}
}
const responses = await testDestination.testAction(actionSlug, {
event: event,
mapping: mapping,
settings: settingsData,
auth: undefined
})
const request = responses[0].request
const rawBody = await request.text()
try {
const json = JSON.parse(rawBody)
expect(json).toMatchSnapshot()
return
} catch (err) {
expect(rawBody).toMatchSnapshot()
}
})
}
})