Skip to content

Commit

Permalink
Talon.One new destination and new actions (segmentio#503)
Browse files Browse the repository at this point in the history
* 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
kkupreeva authored Mar 15, 2022
1 parent add2559 commit 6871863
Show file tree
Hide file tree
Showing 25 changed files with 1,062 additions and 0 deletions.
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(",
}
`;
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()
})
})
})
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()
}
})
}
})
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",
}
`;
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'
}
})
})
})
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()
}
})
})

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,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
Loading

0 comments on commit 6871863

Please sign in to comment.