forked from segmentio/action-destinations
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Talon.One new destination and new actions (segmentio#503)
* add create audience action * try enable CI * try fix * return ci how it was * add updateAudience, deleteAudience, trackEvent * check workflow * fix tests * fix tests * fix description * improve test * fix labels and descriptions * generate types * return workflows how it was before * change destination name Talon One -> Talon.One * review
- Loading branch information
Showing
25 changed files
with
1,062 additions
and
0 deletions.
There are no files selected for viewing
66 changes: 66 additions & 0 deletions
66
...tination-actions/src/destinations/talon-one/__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,66 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Testing snapshot for talon-one destination: createAudience action - all fields 1`] = ` | ||
Object { | ||
"audience_id": "Xunf2QoIA0MWf)kFQ", | ||
"audience_name": "Xunf2QoIA0MWf)kFQ", | ||
} | ||
`; | ||
|
||
exports[`Testing snapshot for talon-one destination: createAudience action - required fields 1`] = ` | ||
Object { | ||
"audience_id": "Xunf2QoIA0MWf)kFQ", | ||
"audience_name": "Xunf2QoIA0MWf)kFQ", | ||
} | ||
`; | ||
|
||
exports[`Testing snapshot for talon-one destination: deleteAudience action - all fields 1`] = `""`; | ||
|
||
exports[`Testing snapshot for talon-one destination: deleteAudience action - required fields 1`] = `""`; | ||
|
||
exports[`Testing snapshot for talon-one destination: deleteAudience action - required fields 2`] = ` | ||
Headers { | ||
Symbol(map): Object { | ||
"authorization": Array [ | ||
"ApiKey-v1 some_api_key", | ||
], | ||
"destination-hostname": Array [ | ||
"YJSS]PGSZ&%5", | ||
], | ||
"user-agent": Array [ | ||
"Segment (Actions)", | ||
], | ||
}, | ||
} | ||
`; | ||
|
||
exports[`Testing snapshot for talon-one destination: trackEvent action - all fields 1`] = ` | ||
Object { | ||
"customer_profile_id": "TePOjI", | ||
"event_attributes": Object { | ||
"testType": "TePOjI", | ||
}, | ||
"event_type": "TePOjI", | ||
"type": "TePOjI", | ||
} | ||
`; | ||
|
||
exports[`Testing snapshot for talon-one destination: trackEvent action - required fields 1`] = ` | ||
Object { | ||
"customer_profile_id": "TePOjI", | ||
"event_type": "TePOjI", | ||
"type": "TePOjI", | ||
} | ||
`; | ||
|
||
exports[`Testing snapshot for talon-one destination: updateAudience action - all fields 1`] = ` | ||
Object { | ||
"audience_name": "XE[HNHsL(", | ||
} | ||
`; | ||
|
||
exports[`Testing snapshot for talon-one destination: updateAudience action - required fields 1`] = ` | ||
Object { | ||
"audience_name": "XE[HNHsL(", | ||
} | ||
`; |
38 changes: 38 additions & 0 deletions
38
packages/destination-actions/src/destinations/talon-one/__tests__/index.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,38 @@ | ||
import { createTestIntegration } from '@segment/actions-core' | ||
import Definition from '../index' | ||
import type { Settings } from '../generated-types' | ||
import nock from 'nock' | ||
|
||
const testDestination = createTestIntegration(Definition) | ||
|
||
describe('Talon One', () => { | ||
describe('testAuthentication', () => { | ||
it('valid auth token', async () => { | ||
nock('https://something.europe-west1.talon.one') | ||
.get('/v2/authping') | ||
.matchHeader('Authorization', 'ApiKey-v1 some_api_key') | ||
.reply(204, {}) | ||
|
||
const settings: Settings = { | ||
api_key: 'some_api_key', | ||
deployment: 'https://something.europe-west1.talon.one' | ||
} | ||
|
||
await expect(testDestination.testAuthentication(settings)).resolves.not.toThrowError() | ||
}) | ||
|
||
it('invalidate auth token', async () => { | ||
nock('https://something.europe-west1.talon.one') | ||
.get('/v2/authping') | ||
.matchHeader('Authorization', 'ApiKey-v1 some_api_key') | ||
.reply(401, {}) | ||
|
||
const settings: Settings = { | ||
api_key: 'some_api_key', | ||
deployment: 'https://something.europe-west1.talon.one' | ||
} | ||
|
||
await expect(testDestination.testAuthentication(settings)).rejects.toThrowError() | ||
}) | ||
}) | ||
}) |
85 changes: 85 additions & 0 deletions
85
packages/destination-actions/src/destinations/talon-one/__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,85 @@ | ||
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 = 'talon-one' | ||
|
||
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) | ||
nock(/.*/).persist().delete(/.*/).reply(200) | ||
|
||
const event = createTestEvent({ | ||
properties: eventData | ||
}) | ||
|
||
const responses = await testDestination.testAction(actionSlug, { | ||
event: event, | ||
mapping: event.properties, | ||
settings: { | ||
api_key: 'some_api_key', | ||
deployment: settingsData.deployment | ||
}, | ||
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) | ||
nock(/.*/).persist().delete(/.*/).reply(200) | ||
|
||
const event = createTestEvent({ | ||
properties: eventData | ||
}) | ||
|
||
const responses = await testDestination.testAction(actionSlug, { | ||
event: event, | ||
mapping: event.properties, | ||
settings: { | ||
api_key: 'some_api_key', | ||
deployment: settingsData.deployment | ||
}, | ||
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() | ||
} | ||
}) | ||
} | ||
}) |
15 changes: 15 additions & 0 deletions
15
...s/src/destinations/talon-one/createAudience/__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,15 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Testing snapshot for TalonOne's createAudience destination action: all fields 1`] = ` | ||
Object { | ||
"audience_id": "my[JK", | ||
"audience_name": "my[JK", | ||
} | ||
`; | ||
|
||
exports[`Testing snapshot for TalonOne's createAudience destination action: required fields 1`] = ` | ||
Object { | ||
"audience_id": "my[JK", | ||
"audience_name": "my[JK", | ||
} | ||
`; |
58 changes: 58 additions & 0 deletions
58
...ges/destination-actions/src/destinations/talon-one/createAudience/__tests__/index.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,58 @@ | ||
import { createTestIntegration } from '@segment/actions-core' | ||
import Destination from '../../index' | ||
import nock from 'nock' | ||
|
||
const testDestination = createTestIntegration(Destination) | ||
|
||
describe('TalonOne.createAudience', () => { | ||
it('audience_id is missing', async () => { | ||
try { | ||
await testDestination.testAction('createAudience', { | ||
settings: { | ||
api_key: 'some_api_key', | ||
deployment: 'https://internal.europe-west1.talon.one' | ||
} | ||
}) | ||
} catch (err) { | ||
expect(err.message).toContain("missing the required field 'audience_id'.") | ||
} | ||
}) | ||
|
||
it('audience_name is missing', async () => { | ||
try { | ||
await testDestination.testAction('createAudience', { | ||
settings: { | ||
api_key: 'some_api_key', | ||
deployment: 'https://something.europe-west1.talon.one' | ||
}, | ||
mapping: { | ||
audience_id: 'some_audience_id' | ||
} | ||
}) | ||
} catch (err) { | ||
expect(err.message).toContain("missing the required field 'audience_name'.") | ||
} | ||
}) | ||
|
||
it('should work', async () => { | ||
nock('https://integration.talon.one') | ||
.post('/segment/audiences', { | ||
audience_id: 'some_audience_id', | ||
audience_name: 'some_audience_name' | ||
}) | ||
.matchHeader('Authorization', 'ApiKey-v1 some_api_key') | ||
.matchHeader('destination-hostname', 'https://something.europe-west1.talon.one') | ||
.reply(201) | ||
|
||
await testDestination.testAction('createAudience', { | ||
settings: { | ||
api_key: 'some_api_key', | ||
deployment: 'https://something.europe-west1.talon.one' | ||
}, | ||
mapping: { | ||
audience_id: 'some_audience_id', | ||
audience_name: 'some_audience_name' | ||
} | ||
}) | ||
}) | ||
}) |
75 changes: 75 additions & 0 deletions
75
.../destination-actions/src/destinations/talon-one/createAudience/__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,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 = 'createAudience' | ||
const destinationSlug = 'TalonOne' | ||
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() | ||
} | ||
}) | ||
}) |
12 changes: 12 additions & 0 deletions
12
packages/destination-actions/src/destinations/talon-one/createAudience/generated-types.ts
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
34 changes: 34 additions & 0 deletions
34
packages/destination-actions/src/destinations/talon-one/createAudience/index.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,34 @@ | ||
import type { ActionDefinition } from '@segment/actions-core' | ||
import type { Settings } from '../generated-types' | ||
import type { Payload } from './generated-types' | ||
|
||
const action: ActionDefinition<Settings, Payload> = { | ||
title: 'Create Audience', | ||
description: 'This creates a new audience entity in Talon.One.', | ||
fields: { | ||
audience_id: { | ||
label: 'audience_id', | ||
description: 'You should get this audience ID from Segment.', | ||
type: 'string', | ||
required: true | ||
}, | ||
audience_name: { | ||
label: 'audience_name', | ||
description: 'You should get this audience name from Segment.', | ||
type: 'string', | ||
required: true | ||
} | ||
}, | ||
perform: (request, { payload }) => { | ||
// Make your partner api request here! | ||
return request(`https://integration.talon.one/segment/audiences`, { | ||
method: 'post', | ||
json: { | ||
audience_id: payload.audience_id, | ||
audience_name: payload.audience_name | ||
} | ||
}) | ||
} | ||
} | ||
|
||
export default action |
Oops, something went wrong.