Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sprig Action Destination #2555

Closed
wants to merge 13 commits into from
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Testing snapshot for actions-sprig destination: identifyUser action - all fields 1`] = `
Object {
"attributes": Object {
"testType": "8%Yljy$Bdi)ERgpbaQ",
},
"userId": "8%Yljy$Bdi)ERgpbaQ",
}
`;

exports[`Testing snapshot for actions-sprig destination: identifyUser action - required fields 1`] = `
Object {
"userId": "8%Yljy$Bdi)ERgpbaQ",
}
`;

exports[`Testing snapshot for actions-sprig destination: trackEvent action - all fields 1`] = `
Object {
"events": Array [
Object {
"event": "KaY8rX",
"timestamp": null,
},
],
"userId": "KaY8rX",
}
`;

exports[`Testing snapshot for actions-sprig destination: trackEvent action - required fields 1`] = `
Object {
"events": Array [
Object {
"event": "KaY8rX",
"timestamp": null,
},
],
"userId": "KaY8rX",
}
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
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-sprig'

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().post(/.*/).reply(200)
nock(/.*/).persist().put(/.*/).reply(200)

const event = createTestEvent({
properties: eventData
})

const responses = await testDestination.testAction(actionSlug, {
event: event,
mapping: event.properties,
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().post(/.*/).reply(200)
nock(/.*/).persist().put(/.*/).reply(200)

const event = createTestEvent({
properties: eventData
})

const responses = await testDestination.testAction(actionSlug, {
event: event,
mapping: event.properties,
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()
}
})
}
})

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Testing snapshot for Sprig's identifyUser destination action: all fields 1`] = `
Object {
"attributes": Object {
"testType": "hOFNL2ws[z[aEmV4l*6",
},
"userId": "hOFNL2ws[z[aEmV4l*6",
}
`;

exports[`Testing snapshot for Sprig's identifyUser destination action: required fields 1`] = `
Object {
"userId": "hOFNL2ws[z[aEmV4l*6",
}
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import nock from 'nock'
import { createTestEvent, createTestIntegration } from '@segment/actions-core'
import Sprig from '../../index'

const testDestination = createTestIntegration(Sprig)

describe('Sprig.identifyUsers', () => {
it('should flatten payload correctly', async () => {
const event = createTestEvent({
type: 'identify',
userId: '1234',
traits: {
firstName: "Bob",
lastName: "Smith",
enabledProducts: {
surveys: true,
heatmaps: false,
replays: true,
feedback: true
}
}
})
nock('https://api.sprig.com/v2').post('/users').reply(200, {})
const responses = await testDestination.testAction('identifyUser', {
event,
useDefaultMappings: true,
settings: {
apiKey: "TEST-API-KEY"
}
})

expect(responses.length).toBe(1)
expect(responses[0].status).toBe(200)
expect(responses[0].options.json).toMatchObject({
"userId": "1234",
"attributes": {
"firstName": "Bob",
"lastName": "Smith",
"enabledProducts.surveys": true,
"enabledProducts.heatmaps": false,
"enabledProducts.replays": true,
"enabledProducts.feedback": true
}
})
})
it('should flatten a double nested object correctly', async () => {
const event = createTestEvent({
type: 'identify',
userId: '1234',
traits: {
customerDetails: {
name: {
first: "Bob",
last: "Smith"
},
birthdate: "2002-02-03"
}
}
})
nock('https://api.sprig.com/v2').post('/users').reply(200, {})
const responses = await testDestination.testAction('identifyUser', {
event,
useDefaultMappings: true,
settings: {
apiKey: "TEST-API-KEY"
}
})

expect(responses.length).toBe(1)
expect(responses[0].status).toBe(200)
expect(responses[0].options.json).toMatchObject({
"userId": "1234",
"attributes": {
"customerDetails.name.first": "Bob",
"customerDetails.name.last": "Smith",
"customerDetails.birthdate": "2002-02-03",
}
})
})
it('should handle an empty traits object', async () => {
const event = createTestEvent({
type: 'identify',
userId: '1234'
})
nock('https://api.sprig.com/v2').post('/users').reply(200, {})
const responses = await testDestination.testAction('identifyUser', {
event,
useDefaultMappings: true,
settings: {
apiKey: "TEST-API-KEY"
}
})
expect(responses.length).toBe(1)
expect(responses[0].status).toBe(200)
expect(responses[0].options.json).toMatchObject({
"userId": "1234",
"attributes": {}
})
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
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 actionSlug = 'identifyUser'
const destinationSlug = 'Sprig'
const seedName = `${destinationSlug}#${actionSlug}`

describe(`Testing snapshot for ${destinationSlug}'s ${actionSlug} destination action:`, () => {
it('required fields', async () => {
const action = destination.actions[actionSlug]
const [eventData, settingsData] = generateTestData(seedName, destination, action, true)

nock(/.*/).persist().get(/.*/).reply(200)
nock(/.*/).persist().post(/.*/).reply(200)
nock(/.*/).persist().put(/.*/).reply(200)

const event = createTestEvent({
properties: eventData
})

const responses = await testDestination.testAction(actionSlug, {
event: event,
mapping: event.properties,
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('all fields', async () => {
const action = destination.actions[actionSlug]
const [eventData, settingsData] = generateTestData(seedName, destination, action, false)

nock(/.*/).persist().get(/.*/).reply(200)
nock(/.*/).persist().post(/.*/).reply(200)
nock(/.*/).persist().put(/.*/).reply(200)

const event = createTestEvent({
properties: eventData
})

const responses = await testDestination.testAction(actionSlug, {
event: event,
mapping: event.properties,
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()
}
})
})

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading