Skip to content

Commit

Permalink
[Antavo ] New Antavo Destination (#2619)
Browse files Browse the repository at this point in the history
* antavo action destination

* fixed extension name + destination name

* ran yarn types command

* updated default mappings

* updated field descriptions

* added unit tests

* wording update
  • Loading branch information
bbantavo authored Jan 20, 2025
1 parent e108adf commit c80d11e
Show file tree
Hide file tree
Showing 14 changed files with 1,061 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Testing snapshot for actions-antavo destination: event action - all fields 1`] = `
Object {
"account": "YOUfi0^J9NW]3LPm",
"action": "YOUfi0^J9NW]3LPm",
"api_key": "YOUfi0^J9NW]3LPm",
"customer": "YOUfi0^J9NW]3LPm",
"data": Object {
"testType": "YOUfi0^J9NW]3LPm",
},
}
`;

exports[`Testing snapshot for actions-antavo destination: event action - required fields 1`] = `
Object {
"action": "YOUfi0^J9NW]3LPm",
"api_key": "YOUfi0^J9NW]3LPm",
"customer": "YOUfi0^J9NW]3LPm",
}
`;

exports[`Testing snapshot for actions-antavo destination: profile action - all fields 1`] = `
Object {
"account": "0$ZK&EN",
"action": "profile",
"api_key": "0$ZK&EN",
"customer": "0$ZK&EN",
"data": Object {
"birth_date": "0$ZK&EN",
"email": "[email protected]",
"first_name": "0$ZK&EN",
"gender": "0$ZK&EN",
"language": "0$ZK&EN",
"last_name": "0$ZK&EN",
"mobile_phone": "0$ZK&EN",
"phone": "0$ZK&EN",
},
}
`;

exports[`Testing snapshot for actions-antavo destination: profile action - required fields 1`] = `
Object {
"action": "profile",
"api_key": "0$ZK&EN",
"customer": "0$ZK&EN",
"data": Object {},
}
`;
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-antavo'

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()
}
})
}
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Testing snapshot for Antavo's event destination action: all fields 1`] = `
Object {
"account": "IB60PM0Tc",
"action": "IB60PM0Tc",
"api_key": "IB60PM0Tc",
"customer": "IB60PM0Tc",
"data": Object {
"testType": "IB60PM0Tc",
},
}
`;

exports[`Testing snapshot for Antavo's event destination action: required fields 1`] = `
Object {
"action": "IB60PM0Tc",
"api_key": "IB60PM0Tc",
"customer": "IB60PM0Tc",
}
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
import nock from 'nock'
import { createTestEvent, createTestIntegration } from '@segment/actions-core'
import destination from '../../index'

const testDestination = createTestIntegration(destination)
const settings = {
stack: 'test-stack',
api_key: 'testApiKey'
}

describe('Antavo (Actions)', () => {
beforeEach((done) => {
nock.cleanAll()
nock.abortPendingRequests()
done()
})

describe('event', () => {
it('Handle request with default mappings', async () => {
nock(`https://api.${settings.stack}.antavo.com`)
.post('/v1/webhook/segment')
.reply(202, {})

const event = createTestEvent({
type: 'track',
userId: 'testUser',
properties: {
antavoAction: 'testAction',
antavoAccount: 'testAccount',
points: 1234
}
})

const responses = await testDestination.testAction(
'event', {
event,
settings,
mapping: {
customer: { '@path': '$.userId' },
action: { '@path': '$.properties.antavoAction' },
account: { '@path': '$.properties.antavoAccount' },
data: {
points: { '@path': '$.properties.points' }
}
}
})

expect(responses.length).toBe(1)
expect(responses[0].status).toBe(202)
expect(responses[0].options.json).toMatchObject({
customer: 'testUser',
action: 'testAction',
account: 'testAccount',
data: {
points: 1234
},
api_key: 'testApiKey'
})
})
it('Handle request without default mappings', async () => {
nock(`https://api.${settings.stack}.antavo.com`)
.post('/v1/webhook/segment')
.reply(202, {})

const event = createTestEvent({
type: 'track',
properties: {
antavoUserId: 'testUser',
antavoAction: 'testAction',
antavoAccount: 'testAccount',
points: 1234
}
})

const responses = await testDestination.testAction(
'event', {
event,
settings,
mapping: {
customer: { '@path': '$.properties.antavoUserId' },
action: { '@path': '$.properties.antavoAction' },
account: { '@path': '$.properties.antavoAccount' },
data: {
points: { '@path': '$.properties.points' }
}
}
})

expect(responses.length).toBe(1)
expect(responses[0].status).toBe(202)
expect(responses[0].options.json).toMatchObject({
customer: 'testUser',
action: 'testAction',
account: 'testAccount',
data: {
points: 1234
},
api_key: 'testApiKey'
})
})
it('Handle request without optional fields', async () => {
nock(`https://api.${settings.stack}.antavo.com`)
.post('/v1/webhook/segment')
.reply(202, {})

const event = createTestEvent({
type: 'track',
userId: 'testUser',
properties: {
antavoAction: 'testAction'
}
})

const responses = await testDestination.testAction(
'event', {
event,
settings,
mapping: {
customer: { '@path': '$.userId' },
action: { '@path': '$.properties.antavoAction' }
}
})

expect(responses.length).toBe(1)
expect(responses[0].status).toBe(202)
expect(responses[0].options.json).toMatchObject({
customer: 'testUser',
action: 'testAction',
api_key: 'testApiKey'
})
})
it('Throw error for missing required field: customer', async () => {
nock(`https://api.${settings.stack}.antavo.com`)
.post('/v1/webhook/segment')
.reply(202, {})

const event = createTestEvent({
type: 'track',
userId: 'testUser',
properties: {
antavoAction: 'testAction',
antavoAccount: 'testAccount',
points: 1234
}
})

await expect(testDestination.testAction(
'event', {
event,
settings,
mapping: {
customer: '',
action: { '@path': '$.properties.antavoAction' },
account: { '@path': '$.properties.antavoAccount' },
data: {
points: { '@path': '$.properties.points' }
}
}
})
).rejects.toThrowError('The root value is missing the required field \'customer\'.')
})
it('Throw error for missing required field: action', async () => {
nock(`https://api.${settings.stack}.antavo.com`)
.post('/v1/webhook/segment')
.reply(202, {})

const event = createTestEvent({
type: 'track',
userId: 'testUser',
properties: {
antavoAction: 'testAction',
antavoAccount: 'testAccount',
points: 1234
}
})

await expect(testDestination.testAction(
'event', {
event,
settings,
mapping: {
customer: { '@path': '$.userId' },
action: '',
account: { '@path': '$.properties.antavoAccount' },
data: {
points: { '@path': '$.properties.points' }
}
}
})
).rejects.toThrowError('The root value is missing the required field \'action\'.')
})
})
})
Loading

0 comments on commit c80d11e

Please sign in to comment.