Skip to content

Commit bfd7efc

Browse files
[Taguchi] - new Destination
1 parent babe6bc commit bfd7efc

File tree

10 files changed

+635
-0
lines changed

10 files changed

+635
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import nock from 'nock'
2+
import { createTestEvent, createTestIntegration } from '@segment/actions-core'
3+
import Definition from '../index'
4+
5+
const testDestination = createTestIntegration(Definition)
6+
7+
describe('Taguchi', () => {
8+
describe('testAuthentication', () => {
9+
it('should validate authentication inputs', async () => {
10+
nock('https://your.destination.endpoint').get('*').reply(200, {})
11+
12+
// This should match your authentication.fields
13+
const authData = {}
14+
15+
await expect(testDestination.testAuthentication(authData)).resolves.not.toThrowError()
16+
})
17+
})
18+
})
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import { createTestEvent, createTestIntegration } from '@segment/actions-core'
2+
import { generateTestData } from '../../../lib/test-data'
3+
import destination from '../index'
4+
import nock from 'nock'
5+
6+
const testDestination = createTestIntegration(destination)
7+
const destinationSlug = 'actions-taguchi'
8+
9+
describe(`Testing snapshot for ${destinationSlug} destination:`, () => {
10+
for (const actionSlug in destination.actions) {
11+
it(`${actionSlug} action - required fields`, async () => {
12+
const seedName = `${destinationSlug}#${actionSlug}`
13+
const action = destination.actions[actionSlug]
14+
const [eventData, settingsData] = generateTestData(seedName, destination, action, true)
15+
16+
nock(/.*/).persist().get(/.*/).reply(200)
17+
nock(/.*/).persist().post(/.*/).reply(200)
18+
nock(/.*/).persist().put(/.*/).reply(200)
19+
20+
const event = createTestEvent({
21+
properties: eventData
22+
})
23+
24+
const responses = await testDestination.testAction(actionSlug, {
25+
event: event,
26+
mapping: event.properties,
27+
settings: settingsData,
28+
auth: undefined
29+
})
30+
31+
const request = responses[0].request
32+
const rawBody = await request.text()
33+
34+
try {
35+
const json = JSON.parse(rawBody)
36+
expect(json).toMatchSnapshot()
37+
return
38+
} catch (err) {
39+
expect(rawBody).toMatchSnapshot()
40+
}
41+
42+
expect(request.headers).toMatchSnapshot()
43+
})
44+
45+
it(`${actionSlug} action - all fields`, async () => {
46+
const seedName = `${destinationSlug}#${actionSlug}`
47+
const action = destination.actions[actionSlug]
48+
const [eventData, settingsData] = generateTestData(seedName, destination, action, false)
49+
50+
nock(/.*/).persist().get(/.*/).reply(200)
51+
nock(/.*/).persist().post(/.*/).reply(200)
52+
nock(/.*/).persist().put(/.*/).reply(200)
53+
54+
const event = createTestEvent({
55+
properties: eventData
56+
})
57+
58+
const responses = await testDestination.testAction(actionSlug, {
59+
event: event,
60+
mapping: event.properties,
61+
settings: settingsData,
62+
auth: undefined
63+
})
64+
65+
const request = responses[0].request
66+
const rawBody = await request.text()
67+
68+
try {
69+
const json = JSON.parse(rawBody)
70+
expect(json).toMatchSnapshot()
71+
return
72+
} catch (err) {
73+
expect(rawBody).toMatchSnapshot()
74+
}
75+
})
76+
}
77+
})

packages/destination-actions/src/destinations/taguchi/generated-types.ts

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { DestinationDefinition } from '@segment/actions-core'
2+
import type { Settings } from './generated-types'
3+
import syncAudience from './syncAudience'
4+
5+
const destination: DestinationDefinition<Settings> = {
6+
name: 'Taguchi',
7+
slug: 'actions-taguchi',
8+
mode: 'cloud',
9+
description: 'Sync user profile details, including Audience and Computed Trait details to Taguchi.',
10+
authentication: {
11+
scheme: 'custom',
12+
fields: {
13+
apiKey: {
14+
label: 'API Key',
15+
description: 'Taguchi API Key used to authenticate requests to the Taguchi API.',
16+
type: 'string',
17+
required: true
18+
},
19+
integrationURL: {
20+
label: 'Integration URL',
21+
description: "The Taguchi URL Segment will send data to. This should be created in the Taguchi User Interface by navigating to 'Taguchi Integrations' then 'Integrations Setup.'",
22+
type: 'string',
23+
required: true
24+
},
25+
organizationId: {
26+
label: 'Organization ID',
27+
description: 'The Taguchi ID of the organization to which this Subscriber belongs.',
28+
type: 'string',
29+
required: true
30+
}
31+
},
32+
testAuthentication: (request) => {
33+
// Return a request that tests/validates the user's credentials.
34+
// If you do not have a way to validate the authentication fields safely,
35+
// you can remove the `testAuthentication` function, though discouraged.
36+
}
37+
},
38+
onDelete: async (request, { settings, payload }) => {
39+
// Return a request that performs a GDPR delete for the provided Segment userId or anonymousId
40+
// provided in the payload. If your destination does not support GDPR deletion you should not
41+
// implement this function and should remove it completely.
42+
},
43+
actions: {
44+
syncAudience
45+
}
46+
}
47+
48+
export default destination
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import nock from 'nock'
2+
import { createTestEvent, createTestIntegration } from '@segment/actions-core'
3+
import Destination from '../../index'
4+
5+
const testDestination = createTestIntegration(Destination)
6+
7+
describe('Taguchi.syncAudience', () => {
8+
// TODO: Test your action
9+
})
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import { createTestEvent, createTestIntegration } from '@segment/actions-core'
2+
import { generateTestData } from '../../../../lib/test-data'
3+
import destination from '../../index'
4+
import nock from 'nock'
5+
6+
const testDestination = createTestIntegration(destination)
7+
const actionSlug = 'syncAudience'
8+
const destinationSlug = 'Taguchi'
9+
const seedName = `${destinationSlug}#${actionSlug}`
10+
11+
describe(`Testing snapshot for ${destinationSlug}'s ${actionSlug} destination action:`, () => {
12+
it('required fields', async () => {
13+
const action = destination.actions[actionSlug]
14+
const [eventData, settingsData] = generateTestData(seedName, destination, action, true)
15+
16+
nock(/.*/).persist().get(/.*/).reply(200)
17+
nock(/.*/).persist().post(/.*/).reply(200)
18+
nock(/.*/).persist().put(/.*/).reply(200)
19+
20+
const event = createTestEvent({
21+
properties: eventData
22+
})
23+
24+
const responses = await testDestination.testAction(actionSlug, {
25+
event: event,
26+
mapping: event.properties,
27+
settings: settingsData,
28+
auth: undefined
29+
})
30+
31+
const request = responses[0].request
32+
const rawBody = await request.text()
33+
34+
try {
35+
const json = JSON.parse(rawBody)
36+
expect(json).toMatchSnapshot()
37+
return
38+
} catch (err) {
39+
expect(rawBody).toMatchSnapshot()
40+
}
41+
42+
expect(request.headers).toMatchSnapshot()
43+
})
44+
45+
it('all fields', async () => {
46+
const action = destination.actions[actionSlug]
47+
const [eventData, settingsData] = generateTestData(seedName, destination, action, false)
48+
49+
nock(/.*/).persist().get(/.*/).reply(200)
50+
nock(/.*/).persist().post(/.*/).reply(200)
51+
nock(/.*/).persist().put(/.*/).reply(200)
52+
53+
const event = createTestEvent({
54+
properties: eventData
55+
})
56+
57+
const responses = await testDestination.testAction(actionSlug, {
58+
event: event,
59+
mapping: event.properties,
60+
settings: settingsData,
61+
auth: undefined
62+
})
63+
64+
const request = responses[0].request
65+
const rawBody = await request.text()
66+
67+
try {
68+
const json = JSON.parse(rawBody)
69+
expect(json).toMatchSnapshot()
70+
return
71+
} catch (err) {
72+
expect(rawBody).toMatchSnapshot()
73+
}
74+
})
75+
})

packages/destination-actions/src/destinations/taguchi/syncAudience/generated-types.ts

Lines changed: 89 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)