|
| 1 | +import { createTestEvent, createTestIntegration } from '@segment/actions-core' |
| 2 | +import { generateTestData } from '../../../../lib/test-data' |
| 3 | +import destination from '../../index' |
| 4 | +import nock from 'nock' |
| 5 | + |
| 6 | +const testDestination = createTestIntegration(destination) |
| 7 | +const actionSlug = 'identifyCompany' |
| 8 | +const destinationSlug = 'Userpilot' |
| 9 | +const seedName = `${destinationSlug}#${actionSlug}` |
| 10 | + |
| 11 | +describe(`Testing snapshot for ${destinationSlug}'s ${actionSlug} destination action:`, () => { |
| 12 | + it('required fields', async () => { |
| 13 | + const action = destination.actions[actionSlug] |
| 14 | + const [eventData, settingsData] = generateTestData(seedName, destination, action, true) |
| 15 | + |
| 16 | + nock(/.*/).persist().get(/.*/).reply(200) |
| 17 | + nock(/.*/).persist().post(/.*/).reply(200) |
| 18 | + nock(/.*/).persist().put(/.*/).reply(200) |
| 19 | + |
| 20 | + const event = createTestEvent({ |
| 21 | + properties: eventData |
| 22 | + }) |
| 23 | + |
| 24 | + const responses = await testDestination.testAction(actionSlug, { |
| 25 | + event: event, |
| 26 | + mapping: event.properties, |
| 27 | + settings: settingsData, |
| 28 | + auth: undefined |
| 29 | + }) |
| 30 | + |
| 31 | + const request = responses[0].request |
| 32 | + const rawBody = await request.text() |
| 33 | + |
| 34 | + try { |
| 35 | + const json = JSON.parse(rawBody) |
| 36 | + expect(json).toMatchSnapshot() |
| 37 | + return |
| 38 | + } catch (err) { |
| 39 | + expect(rawBody).toMatchSnapshot() |
| 40 | + } |
| 41 | + |
| 42 | + expect(request.headers).toMatchSnapshot() |
| 43 | + }) |
| 44 | + |
| 45 | + it('all fields', async () => { |
| 46 | + const action = destination.actions[actionSlug] |
| 47 | + const [eventData, settingsData] = generateTestData(seedName, destination, action, false) |
| 48 | + |
| 49 | + nock(/.*/).persist().get(/.*/).reply(200) |
| 50 | + nock(/.*/).persist().post(/.*/).reply(200) |
| 51 | + nock(/.*/).persist().put(/.*/).reply(200) |
| 52 | + |
| 53 | + const event = createTestEvent({ |
| 54 | + properties: eventData |
| 55 | + }) |
| 56 | + |
| 57 | + const responses = await testDestination.testAction(actionSlug, { |
| 58 | + event: event, |
| 59 | + mapping: event.properties, |
| 60 | + settings: settingsData, |
| 61 | + auth: undefined |
| 62 | + }) |
| 63 | + |
| 64 | + const request = responses[0].request |
| 65 | + const rawBody = await request.text() |
| 66 | + |
| 67 | + try { |
| 68 | + const json = JSON.parse(rawBody) |
| 69 | + expect(json).toMatchSnapshot() |
| 70 | + return |
| 71 | + } catch (err) { |
| 72 | + expect(rawBody).toMatchSnapshot() |
| 73 | + } |
| 74 | + }) |
| 75 | +}) |
0 commit comments