Skip to content

Ortto audiences (Engage) #2927

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Testing snapshot for actions-ortto-audiences destination: syncAudience action - all fields 1`] = `
Array [
Object {
"anonymous_id": "rOxF$I97!M",
"audience": Object {
"id": "rOxF$I97!M",
"mode": "remove",
},
"ip": "81.60.139.81",
"location": Object {
"city": "rOxF$I97!M",
"country": "rOxF$I97!M",
"post_code": "rOxF$I97!M",
"state": "rOxF$I97!M",
},
"message_id": "rOxF$I97!M",
"traits": Object {
"testType": "rOxF$I97!M",
},
"user_id": "rOxF$I97!M",
},
]
`;

exports[`Testing snapshot for actions-ortto-audiences destination: syncAudience action - required fields 1`] = `
Array [
Object {
"anonymous_id": "rOxF$I97!M",
"audience": Object {
"id": "rOxF$I97!M",
"mode": "remove",
},
"message_id": "rOxF$I97!M",
"traits": Object {
"testType": "rOxF$I97!M",
},
"user_id": "rOxF$I97!M",
},
]
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import nock from 'nock'
import { createTestIntegration, InvalidAuthenticationError } from '@segment/actions-core'
import Definition from '../index'
import { API_VERSION } from '../ortto-client'
import { TEST_API_KEY } from '../types'

const testDestination = createTestIntegration(Definition)

describe('Ortto (audiences)', () => {
describe('authentication', () => {
it('should reject empty api keys', async () => {
try {
await testDestination.testAuthentication({ api_key: '' })
} catch (err) {
expect(err instanceof InvalidAuthenticationError)
}
})

it('should reject whitespace api keys', async () => {
try {
await testDestination.testAuthentication({ api_key: ' ' })
} catch (err) {
expect(err instanceof InvalidAuthenticationError)
}
})

it('should reject invalid api keys', async () => {
try {
await testDestination.testAuthentication({ api_key: 'invalid' })
} catch (err) {
expect(err instanceof InvalidAuthenticationError)
}
})

it('should accept valid api keys', async () => {
nock('https://segment-action-api-au.ortto.app')
.get(`/${API_VERSION}/me`)
.matchHeader('authorization', `Bearer ${TEST_API_KEY}`)
.reply(200, {})
await expect(testDestination.testAuthentication({ api_key: TEST_API_KEY })).resolves.not.toThrowError()
})
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import { createTestEvent, createTestIntegration } from '@segment/actions-core'
import { generateTestData } from '../../../lib/test-data'
import destination from '../index'
import nock from 'nock'
import { TEST_API_KEY } from '../types'

const testDestination = createTestIntegration(destination)
const destinationSlug = 'actions-ortto-audiences'

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] = 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: { api_key: TEST_API_KEY },
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] = 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: { api_key: TEST_API_KEY },
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,71 @@
import type { AudienceDestinationDefinition } from '@segment/actions-core'
import type { Settings, AudienceSettings } from './generated-types'
import OrttoClient from './ortto-client'

import syncAudience from './syncAudience'

const destination: AudienceDestinationDefinition<Settings, AudienceSettings> = {
name: 'Ortto (Audiences)',
slug: 'actions-ortto-audiences',
mode: 'cloud',

authentication: {
scheme: 'custom',
fields: {
api_key: {
label: 'API Key',
description: 'Ortto API key',
type: 'password',
required: true
}
},
testAuthentication: async (request, { settings }) => {
const client: OrttoClient = new OrttoClient(request)
return await client.testAuth(settings)
}
},
extendRequest({ settings }) {
if (process?.env?.ORTTO_API_KEY) {
settings.api_key = process?.env?.ORTTO_API_KEY
}
return {
headers: {
Authorization: `Bearer ${settings.api_key}`
}
}
},
audienceFields: {
audienceName: {
label: 'Audience Name',
description: 'The name of the Audience in Ortto',
type: 'string',
required: true
}
},
audienceConfig: {
mode: {
type: 'synced',
full_audience_sync: false
},
createAudience: async (request, { settings, audienceName }) => {
const client: OrttoClient = new OrttoClient(request)
const audience = await client.createAudience(settings, audienceName)
return {
// Segment will save this externalId for subsequent calls
externalId: audience.id
}
},
getAudience: async (request, { settings, externalId }) => {
const client: OrttoClient = new OrttoClient(request)
const audience = await client.getAudience(settings, externalId)
return {
externalId: audience.id
}
}
},
actions: {
syncAudience
}
}

export default destination
Loading
Loading