-
Notifications
You must be signed in to change notification settings - Fork 256
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Antavo ] New Antavo Destination (#2619)
* 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
Showing
14 changed files
with
1,061 additions
and
0 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
...destination-actions/src/destinations/antavo/__tests__/__snapshots__/snapshot.test.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 {}, | ||
} | ||
`; |
77 changes: 77 additions & 0 deletions
77
packages/destination-actions/src/destinations/antavo/__tests__/snapshot.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
}) | ||
} | ||
}) |
21 changes: 21 additions & 0 deletions
21
...ation-actions/src/destinations/antavo/event/__tests__/__snapshots__/snapshot.test.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
} | ||
`; |
193 changes: 193 additions & 0 deletions
193
packages/destination-actions/src/destinations/antavo/event/__tests__/event.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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\'.') | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.