|
| 1 | +import nock from 'nock' |
1 | 2 | import { createTestEvent, createTestIntegration } from '@segment/actions-core'
|
2 |
| -import { generateTestData } from '../../../lib/test-data' |
3 | 3 | import destination from '../index'
|
4 |
| -import nock from 'nock' |
5 | 4 |
|
6 | 5 | const testDestination = createTestIntegration(destination)
|
7 |
| -const destinationSlug = 'actions-taguchi' |
8 | 6 |
|
9 |
| -describe(`Testing snapshot for ${destinationSlug} destination:`, () => { |
10 |
| - for (const actionSlug in destination.actions) { |
11 |
| - it(`${actionSlug} action - required fields`, async () => { |
12 |
| - const seedName = `${destinationSlug}#${actionSlug}` |
13 |
| - const action = destination.actions[actionSlug] |
14 |
| - const [eventData, settingsData] = generateTestData(seedName, destination, action, true) |
| 7 | +describe('Taguchi Destination Snapshots', () => { |
| 8 | + beforeEach(() => { |
| 9 | + nock.cleanAll() |
| 10 | + }) |
15 | 11 |
|
16 |
| - nock(/.*/).persist().get(/.*/).reply(200) |
17 |
| - nock(/.*/).persist().post(/.*/).reply(200) |
18 |
| - nock(/.*/).persist().put(/.*/).reply(200) |
| 12 | + describe('syncAudience action', () => { |
| 13 | + it('should match snapshot with required fields', async () => { |
| 14 | + nock('https://api.taguchi.com.au') |
| 15 | + .post('/subscriber') |
| 16 | + .reply(200, [{ code: 200, name: 'Success', description: 'Subscriber processed' }]) |
19 | 17 |
|
20 | 18 | const event = createTestEvent({
|
21 |
| - properties: eventData |
| 19 | + type: 'identify', |
| 20 | + userId: 'test-user-123', |
| 21 | + traits: { |
| 22 | + |
| 23 | + first_name: 'John', |
| 24 | + last_name: 'Doe' |
| 25 | + } |
22 | 26 | })
|
23 | 27 |
|
24 |
| - const responses = await testDestination.testAction(actionSlug, { |
25 |
| - event: event, |
26 |
| - mapping: event.properties, |
27 |
| - settings: settingsData, |
28 |
| - auth: undefined |
| 28 | + const { data } = await testDestination.testAction('syncAudience', { |
| 29 | + event, |
| 30 | + settings: { |
| 31 | + apiKey: 'test-api-key', |
| 32 | + integrationURL: 'https://api.taguchi.com.au', |
| 33 | + organizationId: '123' |
| 34 | + }, |
| 35 | + mapping: { |
| 36 | + identifiers: { |
| 37 | + ref: event.userId, |
| 38 | + email: event.traits?.email |
| 39 | + }, |
| 40 | + traits: { |
| 41 | + firstname: event.traits?.first_name, |
| 42 | + lastname: event.traits?.last_name |
| 43 | + }, |
| 44 | + timestamp: event.timestamp |
| 45 | + } |
29 | 46 | })
|
30 | 47 |
|
31 |
| - const request = responses[0].request |
32 |
| - const rawBody = await request.text() |
| 48 | + expect(data).toMatchSnapshot() |
| 49 | + }) |
33 | 50 |
|
34 |
| - try { |
35 |
| - const json = JSON.parse(rawBody) |
36 |
| - expect(json).toMatchSnapshot() |
37 |
| - return |
38 |
| - } catch (err) { |
39 |
| - expect(rawBody).toMatchSnapshot() |
40 |
| - } |
| 51 | + it('should match snapshot with all fields', async () => { |
| 52 | + nock('https://api.taguchi.com.au') |
| 53 | + .post('/subscriber') |
| 54 | + .reply(200, [{ code: 200, name: 'Success', description: 'Subscriber processed' }]) |
41 | 55 |
|
42 |
| - expect(request.headers).toMatchSnapshot() |
43 |
| - }) |
| 56 | + const event = createTestEvent({ |
| 57 | + type: 'identify', |
| 58 | + userId: 'test-user-123', |
| 59 | + traits: { |
| 60 | + |
| 61 | + first_name: 'John', |
| 62 | + last_name: 'Doe', |
| 63 | + title: 'Mr', |
| 64 | + birthday: '1990-01-01T00:00:00.000Z', |
| 65 | + street: '123 Main St', |
| 66 | + city: 'Test City', |
| 67 | + state: 'Test State', |
| 68 | + country: 'Test Country', |
| 69 | + postal_code: '12345', |
| 70 | + phone: '555-1234', |
| 71 | + gender: 'Male' |
| 72 | + } |
| 73 | + }) |
| 74 | + |
| 75 | + const { data } = await testDestination.testAction('syncAudience', { |
| 76 | + event, |
| 77 | + settings: { |
| 78 | + apiKey: 'test-api-key', |
| 79 | + integrationURL: 'https://api.taguchi.com.au', |
| 80 | + organizationId: '123' |
| 81 | + }, |
| 82 | + mapping: { |
| 83 | + identifiers: { |
| 84 | + ref: event.userId, |
| 85 | + email: event.traits?.email |
| 86 | + }, |
| 87 | + traits: { |
| 88 | + title: event.traits?.title, |
| 89 | + firstname: event.traits?.first_name, |
| 90 | + lastname: event.traits?.last_name, |
| 91 | + dob: event.traits?.birthday, |
| 92 | + address: event.traits?.street, |
| 93 | + suburb: event.traits?.city, |
| 94 | + state: event.traits?.state, |
| 95 | + country: event.traits?.country, |
| 96 | + postcode: event.traits?.postal_code, |
| 97 | + phone: event.traits?.phone, |
| 98 | + gender: event.traits?.gender |
| 99 | + }, |
| 100 | + subscribeLists: ['123', '456'], |
| 101 | + unsubscribeLists: ['789'], |
| 102 | + timestamp: event.timestamp |
| 103 | + } |
| 104 | + }) |
44 | 105 |
|
45 |
| - it(`${actionSlug} action - all fields`, async () => { |
46 |
| - const seedName = `${destinationSlug}#${actionSlug}` |
47 |
| - const action = destination.actions[actionSlug] |
48 |
| - const [eventData, settingsData] = generateTestData(seedName, destination, action, false) |
| 106 | + expect(data).toMatchSnapshot() |
| 107 | + }) |
| 108 | + }) |
49 | 109 |
|
50 |
| - nock(/.*/).persist().get(/.*/).reply(200) |
51 |
| - nock(/.*/).persist().post(/.*/).reply(200) |
52 |
| - nock(/.*/).persist().put(/.*/).reply(200) |
| 110 | + describe('syncEvent action', () => { |
| 111 | + it('should match snapshot with required fields', async () => { |
| 112 | + nock('https://api.taguchi.com.au') |
| 113 | + .post('/subscriber') |
| 114 | + .reply(200, [{ code: 200, name: 'Success', description: 'Event processed' }]) |
53 | 115 |
|
54 | 116 | const event = createTestEvent({
|
55 |
| - properties: eventData |
| 117 | + type: 'track', |
| 118 | + event: 'Order Completed', |
| 119 | + userId: 'test-user-123', |
| 120 | + properties: { |
| 121 | + total: 123.5, |
| 122 | + products: [{ sku: '1290W', price: 123.5 }], |
| 123 | + |
| 124 | + } |
| 125 | + }) |
| 126 | + |
| 127 | + const { data } = await testDestination.testAction('syncEvent', { |
| 128 | + event, |
| 129 | + settings: { |
| 130 | + apiKey: 'test-api-key', |
| 131 | + integrationURL: 'https://api.taguchi.com.au', |
| 132 | + organizationId: '123' |
| 133 | + }, |
| 134 | + mapping: { |
| 135 | + target: { |
| 136 | + ref: event.userId, |
| 137 | + email: event.properties?.email |
| 138 | + }, |
| 139 | + eventType: 'p', |
| 140 | + eventData: { |
| 141 | + total: event.properties?.total, |
| 142 | + products: event.properties?.products |
| 143 | + } |
| 144 | + } |
56 | 145 | })
|
57 | 146 |
|
58 |
| - const responses = await testDestination.testAction(actionSlug, { |
59 |
| - event: event, |
60 |
| - mapping: event.properties, |
61 |
| - settings: settingsData, |
62 |
| - auth: undefined |
| 147 | + expect(data).toMatchSnapshot() |
| 148 | + }) |
| 149 | + |
| 150 | + it('should match snapshot with all fields', async () => { |
| 151 | + nock('https://api.taguchi.com.au') |
| 152 | + .post('/subscriber') |
| 153 | + .reply(200, [{ code: 200, name: 'Success', description: 'Event processed' }]) |
| 154 | + |
| 155 | + const event = createTestEvent({ |
| 156 | + type: 'track', |
| 157 | + event: 'Order Completed', |
| 158 | + userId: 'test-user-123', |
| 159 | + properties: { |
| 160 | + total: 123.5, |
| 161 | + products: [ |
| 162 | + { |
| 163 | + sku: '1290W', |
| 164 | + price: 123.5, |
| 165 | + quantity: 1, |
| 166 | + name: 'Test Product', |
| 167 | + category: 'Electronics' |
| 168 | + } |
| 169 | + ], |
| 170 | + currency: 'USD', |
| 171 | + order_id: 'order-123', |
| 172 | + |
| 173 | + } |
63 | 174 | })
|
64 | 175 |
|
65 |
| - const request = responses[0].request |
66 |
| - const rawBody = await request.text() |
| 176 | + const { data } = await testDestination.testAction('syncEvent', { |
| 177 | + event, |
| 178 | + settings: { |
| 179 | + apiKey: 'test-api-key', |
| 180 | + integrationURL: 'https://api.taguchi.com.au', |
| 181 | + organizationId: '123' |
| 182 | + }, |
| 183 | + mapping: { |
| 184 | + target: { |
| 185 | + ref: event.userId, |
| 186 | + email: event.properties?.email |
| 187 | + }, |
| 188 | + isTest: false, |
| 189 | + eventType: 'p', |
| 190 | + eventData: { |
| 191 | + total: event.properties?.total, |
| 192 | + products: event.properties?.products, |
| 193 | + currency: event.properties?.currency, |
| 194 | + order_id: event.properties?.order_id |
| 195 | + } |
| 196 | + } |
| 197 | + }) |
67 | 198 |
|
68 |
| - try { |
69 |
| - const json = JSON.parse(rawBody) |
70 |
| - expect(json).toMatchSnapshot() |
71 |
| - return |
72 |
| - } catch (err) { |
73 |
| - expect(rawBody).toMatchSnapshot() |
74 |
| - } |
| 199 | + expect(data).toMatchSnapshot() |
75 | 200 | })
|
76 |
| - } |
| 201 | + }) |
77 | 202 | })
|
0 commit comments