Skip to content
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

livelike-cloud action destination PE-41 #1020

Merged
merged 2 commits into from
Feb 8, 2023
Merged
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,32 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Testing snapshot for actions-livelike-cloud destination: trackEvent action - all fields 1`] = `
Object {
"events": Array [
Object {
"action_description": "n]C0wig#f82f0li1(A",
"action_key": "n]C0wig#f82f0li1(A",
"action_name": "n]C0wig#f82f0li1(A",
"livelike_profile_id": "n]C0wig#f82f0li1(A",
"properties": Object {
"testType": "n]C0wig#f82f0li1(A",
},
"timestamp": "2021-02-01T00:00:00.000Z",
"user_id": "n]C0wig#f82f0li1(A",
},
],
}
`;

exports[`Testing snapshot for actions-livelike-cloud destination: trackEvent action - required fields 1`] = `
Object {
"events": Array [
Object {
"action_key": "n]C0wig#f82f0li1(A",
"livelike_profile_id": "n]C0wig#f82f0li1(A",
"timestamp": "2021-02-01T00:00:00.000Z",
"user_id": "n]C0wig#f82f0li1(A",
},
],
}
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import nock from 'nock'
import { createTestIntegration } from '@segment/actions-core'
import Definition from '../index'
import { apiBaseUrl } from '../properties'

const testDestination = createTestIntegration(Definition)

describe('Livelike', () => {
describe('testAuthentication', () => {
it('should throw an error in case of invalid inputs', async () => {
nock(apiBaseUrl).get('/applications/abc/validate-app/').matchHeader('authorization', `Bearer 123`).reply(401, {})

const authData = { clientId: 'abc', producerToken: '123' }

await expect(testDestination.testAuthentication(authData)).rejects.toThrowError()
})

it('should validate authentication inputs', async () => {
nock(apiBaseUrl).get('/applications/abc/validate-app/').matchHeader('authorization', `Bearer 123`).reply(200, {})

const authData = { clientId: 'abc', producerToken: '123' }

await expect(testDestination.testAuthentication(authData)).resolves.not.toThrowError()
})
})
})
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-livelike-cloud'

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()
}
})
}
})

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,84 @@
import { defaultValues, DestinationDefinition } from '@segment/actions-core'
import type { Settings } from './generated-types'
import { apiBaseUrl } from './properties'

import trackEvent from './trackEvent'

const presets: DestinationDefinition['presets'] = [
{
name: 'Track User Actions',
subscribe: 'type = "track"',
partnerAction: 'trackEvent',
mapping: defaultValues(trackEvent.fields)
},
{
name: 'Page Calls',
subscribe: 'type = "page"',
partnerAction: 'trackEvent',
mapping: {
...defaultValues(trackEvent.fields),
action_name: {
'@if': {
exists: { '@path': '$.properties.action_name' },
then: { '@path': '$.properties.action_name' },
else: { '@path': '$.properties.title' }
}
}
}
},
{
name: 'Screen Calls',
subscribe: 'type = "screen"',
partnerAction: 'trackEvent',
mapping: {
...defaultValues(trackEvent.fields),
action_name: {
'@if': {
exists: { '@path': '$.properties.action_name' },
then: { '@path': '$.properties.action_name' },
else: { '@path': '$.properties.title' }
}
}
}
}
]

const destination: DestinationDefinition<Settings> = {
name: 'LiveLike',
slug: 'actions-livelike-cloud',
mode: 'cloud',

authentication: {
scheme: 'custom',
fields: {
clientId: {
label: 'Client ID',
description: 'Your LiveLike Application Client ID.',
type: 'string',
required: true
},
producerToken: {
label: 'Producer Token',
description: 'Your LiveLike Producer token.',
type: 'password',
required: true
}
},
testAuthentication: async (request, { settings }) => {
return request(`${apiBaseUrl}/applications/${settings.clientId}/validate-app/`, {
method: 'get'
})
}
},
extendRequest: ({ settings }) => {
return {
headers: { Authorization: `Bearer ${settings.producerToken}` }
}
},
presets,
actions: {
trackEvent
}
}

export default destination
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const apiBaseUrl = 'https://cf-blast-iconic.livelikecdn.com/api/v1'
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Testing snapshot for LivelikeCloud's trackEvent destination action: all fields 1`] = `
Object {
"events": Array [
Object {
"action_description": "&Lu]rW[@yx2%6aWnTgQ",
"action_key": "&Lu]rW[@yx2%6aWnTgQ",
"action_name": "&Lu]rW[@yx2%6aWnTgQ",
"livelike_profile_id": "&Lu]rW[@yx2%6aWnTgQ",
"properties": Object {
"testType": "&Lu]rW[@yx2%6aWnTgQ",
},
"timestamp": "2021-02-01T00:00:00.000Z",
"user_id": "&Lu]rW[@yx2%6aWnTgQ",
},
],
}
`;

exports[`Testing snapshot for LivelikeCloud's trackEvent destination action: required fields 1`] = `
Object {
"events": Array [
Object {
"action_key": "&Lu]rW[@yx2%6aWnTgQ",
"livelike_profile_id": "&Lu]rW[@yx2%6aWnTgQ",
"timestamp": "2021-02-01T00:00:00.000Z",
"user_id": "&Lu]rW[@yx2%6aWnTgQ",
},
],
}
`;
Loading