-
Notifications
You must be signed in to change notification settings - Fork 256
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
[Hyperengage] Destination #1621
Merged
Merged
Changes from 8 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
904ee55
Add unit and integration tests
zhadier39 521d658
Updated field descriptions for group, identify and track
saadhypng ab47298
Updated common fields
saadhypng f4832e4
Fix identify function error
zhadier39 6de967a
Added authentication endpoint
saadhypng ed36ea3
Merge pull request #1 from Hyperengage/feature/he-action-destination
saadhypng bb11b28
Revise tests to enable auth
zhadier39 a2f9483
Merge latest upstream changes
zhadier39 729c263
Update default paths for groupId.
zhadier39 557e01d
Implement recommended changes from PR #1621
zhadier39 e65c38d
Add url field
zhadier39 0b833d4
Resolve pathing issues and add tests/checks for first and last name f…
zhadier39 1c13eef
Resolve test issues, payload validation error, and correct context de…
zhadier39 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
packages/destination-actions/src/destinations/hyperengage/__tests__/hyperengage.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,30 @@ | ||
import { createTestIntegration } from '@segment/actions-core' | ||
import Definition from '../index' | ||
import nock from 'nock' | ||
|
||
export const apiKey = 'testApiKey' | ||
export const workspaceIdentifier = 'testApiIdentifier' | ||
|
||
const testDestination = createTestIntegration(Definition) | ||
beforeAll(() => { | ||
nock.disableNetConnect() | ||
}) | ||
|
||
afterAll(() => { | ||
nock.enableNetConnect() | ||
nock.cleanAll() | ||
}) | ||
|
||
describe('Hyperengage', () => { | ||
describe('testAuthentication', () => { | ||
test('should validate workspaceIdentifier and apiKey', async () => { | ||
nock('https://api.hyperengage.io/api/v1/verify_api_key') | ||
.post(/.*/, { | ||
api_key: apiKey, | ||
workspace_identifier: workspaceIdentifier | ||
}) | ||
.reply(200, { message: 'Mocked response' }) | ||
await expect(testDestination.testAuthentication({ apiKey, workspaceIdentifier })).resolves.not.toThrowError() | ||
}) | ||
}) | ||
}) |
94 changes: 94 additions & 0 deletions
94
packages/destination-actions/src/destinations/hyperengage/__tests__/validateInput.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,94 @@ | ||
import { validateInput } from '../validateInput' | ||
|
||
const fakeTrackData = { | ||
event_id: 'test-message-cz380xxe9kn', | ||
page_title: 'Title', | ||
event_name: 'test', | ||
event_type: 'track', | ||
properties: { | ||
required: 'false' | ||
}, | ||
timestamp: '2023-09-11T08:06:11.192Z', | ||
user_id: 'test', | ||
account_id: 'testAccount' | ||
} | ||
|
||
const fakeIdentifyData = { | ||
event_id: 'test-message-cz380xxe9kn', | ||
page_title: 'Title', | ||
event_name: 'test', | ||
event_type: 'identify', | ||
name: 'testUser', | ||
email: 'testEmail', | ||
traits: { | ||
required: 'false' | ||
}, | ||
timestamp: '2023-09-11T08:06:11.192Z', | ||
user_id: 'test', | ||
account_id: 'testAccount' | ||
} | ||
|
||
const fakeGroupData = { | ||
event_id: 'test-message-cz380xxe9kn', | ||
page_title: 'Title', | ||
event_name: 'test', | ||
event_type: 'group', | ||
name: 'Test account', | ||
plan: 'temporary', | ||
industry: 'test industry', | ||
website: 'test website', | ||
traits: { | ||
required: 'false' | ||
}, | ||
timestamp: '2023-09-11T08:06:11.192Z', | ||
user_id: 'test', | ||
account_id: 'testAccount' | ||
} | ||
|
||
const settings = { | ||
workspaceIdentifier: 'testWorkspaceId', | ||
apiKey: 'testApiKey' | ||
} | ||
|
||
describe('validateInput', () => { | ||
describe('test common payload', () => { | ||
it('should return converted payload', () => { | ||
const payload = validateInput(settings, fakeIdentifyData, 'user_identify') | ||
expect(payload.api_key).toBe(settings.apiKey) | ||
expect(payload.workspace_key).toBe(settings.workspaceIdentifier) | ||
expect(payload.doc_encoding).toBe('UTF-8') | ||
expect(payload.src).toBe('segment_api') | ||
expect(payload.anonymous_id).toHaveLength(10) | ||
}) | ||
}) | ||
|
||
describe('test identify payload', () => { | ||
it('should return converted payload', async () => { | ||
const payload = validateInput(settings, fakeIdentifyData, 'user_identify') | ||
expect(payload.user_id).toEqual(fakeIdentifyData.user_id) | ||
expect(payload.traits.email).toEqual(fakeIdentifyData.email) | ||
expect(payload.traits.name).toEqual(fakeIdentifyData.name) | ||
expect(payload.traits).toHaveProperty('required') | ||
}) | ||
}) | ||
|
||
describe('test group payload', () => { | ||
it('should return converted payload', async () => { | ||
const payload = validateInput(settings, fakeGroupData, 'account_identify') | ||
expect(payload.account_id).toEqual(fakeGroupData.account_id) | ||
expect(payload.traits.plan_name).toEqual(fakeGroupData.plan) | ||
expect(payload.traits.industry).toEqual(fakeGroupData.industry) | ||
expect(payload.traits.website).toEqual(fakeGroupData.website) | ||
expect(payload.traits).toHaveProperty('required') | ||
}) | ||
}) | ||
|
||
describe('test track payload', () => { | ||
it('should return converted payload', async () => { | ||
let payload = validateInput(settings, fakeGroupData, 'account_identify') | ||
expect(payload.event_type).toEqual('account_identify') | ||
payload = validateInput(settings, fakeTrackData, 'track') | ||
expect(payload.event_type).toEqual('test') | ||
}) | ||
}) | ||
}) |
156 changes: 156 additions & 0 deletions
156
packages/destination-actions/src/destinations/hyperengage/commonFields.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,156 @@ | ||
import { ActionDefinition } from '@segment/actions-core' | ||
import { Settings } from '../encharge/generated-types' | ||
|
||
export const commonFields: ActionDefinition<Settings>['fields'] = { | ||
event_id: { | ||
type: 'string', | ||
required: false, | ||
description: 'The ID of the event.', | ||
label: 'Event ID', | ||
default: { '@path': '$.messageId' } | ||
}, | ||
doc_path: { | ||
type: 'string', | ||
required: false, | ||
description: 'The path of the document.', | ||
label: 'Document Path', | ||
default: { '@path': '$.context.page.path' } | ||
}, | ||
doc_search: { | ||
type: 'string', | ||
required: false, | ||
description: 'The search query of the document.', | ||
label: 'Document Search', | ||
default: { '@path': '$.context.page.search' } | ||
}, | ||
page_title: { | ||
type: 'string', | ||
required: false, | ||
description: 'The title of the page where the event occurred.', | ||
label: 'Page Title', | ||
default: { '@path': '$.context.page.title' } | ||
}, | ||
referer: { | ||
type: 'string', | ||
required: false, | ||
description: 'The referrer of the page where the event occurred.', | ||
label: 'Referrer', | ||
default: { '@path': '$.context.page.referrer' } | ||
}, | ||
url: { | ||
type: 'string', | ||
required: false, | ||
description: 'The URL of the page where the event occurred.', | ||
label: 'URL', | ||
default: { '@path': '$.context.page.url' } | ||
}, | ||
user_agent: { | ||
type: 'string', | ||
required: false, | ||
description: 'The user agent of the browser.', | ||
label: 'User Agent', | ||
default: { '@path': '$.context.userAgent' } | ||
}, | ||
user_language: { | ||
type: 'string', | ||
required: false, | ||
description: 'The language of the browser.', | ||
label: 'User Language', | ||
default: { '@path': '$.context.locale' } | ||
}, | ||
utc_time: { | ||
type: 'string', | ||
required: false, | ||
description: 'The time of the event in UTC.', | ||
label: 'UTC Time', | ||
default: { '@path': '$.timestamp' } | ||
}, | ||
utm: { | ||
type: 'object', | ||
required: false, | ||
description: 'Information about the UTM parameters.', | ||
label: 'UTM', | ||
properties: { | ||
source: { | ||
label: 'Source', | ||
description: 'The source of the campaign.', | ||
type: 'string' | ||
}, | ||
medium: { | ||
label: 'Medium', | ||
description: 'The medium of the campaign.', | ||
type: 'string' | ||
}, | ||
name: { | ||
label: 'Name', | ||
description: 'The name of the campaign.', | ||
type: 'string' | ||
}, | ||
term: { | ||
label: 'Term', | ||
description: 'The term of the campaign.', | ||
type: 'string' | ||
}, | ||
content: { | ||
label: 'Content', | ||
description: 'The content of the campaign.', | ||
type: 'string' | ||
} | ||
}, | ||
default: { | ||
source: { '@path': '$.context.campaign.source' }, | ||
medium: { '@path': '$.context.campaign.medium' }, | ||
name: { '@path': '$.context.campaign.name' }, | ||
term: { '@path': '$.context.campaign.term' }, | ||
content: { '@path': '$.context.campaign.content' } | ||
} | ||
}, | ||
screen: { | ||
type: 'object', | ||
required: false, | ||
description: 'Information about the screen.', | ||
label: 'Screen', | ||
properties: { | ||
height: { | ||
label: 'Height', | ||
description: 'The height of the screen.', | ||
type: 'integer' | ||
}, | ||
width: { | ||
label: 'Width', | ||
description: 'The width of the screen.', | ||
type: 'integer' | ||
}, | ||
density: { | ||
label: 'Density', | ||
description: 'The density of the screen.', | ||
type: 'number' | ||
} | ||
}, | ||
default: { | ||
height: { '@path': '$.context.screen.height' }, | ||
width: { '@path': '$.context.screen.width' }, | ||
density: { '@path': '$.context.screen.density' } | ||
} | ||
}, | ||
timezone: { | ||
type: 'string', | ||
required: false, | ||
description: 'The timezone of the browser.', | ||
label: 'Timezone', | ||
default: { | ||
'@if': { | ||
exists: { '@path': '$.properties.timezone' }, | ||
then: { '@path': '$.properties.timezone' }, | ||
else: { '@path': '$.traits.timezone' } | ||
} | ||
} | ||
}, | ||
source_ip: { | ||
type: 'string', | ||
required: false, | ||
description: 'The IP address of the user.', | ||
label: 'IP Address', | ||
default: { '@path': '$.context.ip' } | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
packages/destination-actions/src/destinations/hyperengage/generated-types.ts
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
100 changes: 100 additions & 0 deletions
100
packages/destination-actions/src/destinations/hyperengage/group/__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,100 @@ | ||
import nock from 'nock' | ||
import { createTestEvent, createTestIntegration } from '@segment/actions-core' | ||
import Destination from '../../index' | ||
|
||
const testDestination = createTestIntegration(Destination) | ||
|
||
beforeEach(() => nock.cleanAll()) | ||
|
||
const heGroupMapping = { | ||
account_id: { | ||
'@path': '$.groupId' | ||
}, | ||
name: { | ||
'@if': { | ||
exists: { '@path': '$.traits.name' }, | ||
then: { '@path': '$.traits.name' }, | ||
else: { '@path': '$.properties.name' } | ||
} | ||
}, | ||
created_at: { | ||
'@path': '$.traits.created_at' | ||
}, | ||
traits: { | ||
'@path': '$.traits' | ||
}, | ||
plan: { | ||
'@path': '$.traits.plan' | ||
}, | ||
industry: { | ||
'@path': '$.traits.industry' | ||
}, | ||
website: { | ||
'@path': '$.traits.website' | ||
} | ||
} | ||
|
||
describe('Hyperengage.group', () => { | ||
test('Should throw an error if `account_id or` `name` is not defined', async () => { | ||
const event = createTestEvent({ | ||
type: 'group', | ||
traits: { | ||
email: '[email protected]' | ||
}, | ||
groupId: '[email protected]' | ||
}) | ||
|
||
await expect( | ||
testDestination.testAction('group', { | ||
event, | ||
mapping: heGroupMapping | ||
}) | ||
).rejects.toThrowError() | ||
}) | ||
|
||
test('Should throw an error if workspaceIdentifier or apiKey is not defined', async () => { | ||
const event = createTestEvent({ | ||
type: 'group', | ||
traits: { | ||
name: 'test' | ||
}, | ||
groupId: '123456' | ||
}) | ||
|
||
await expect( | ||
testDestination.testAction('group', { | ||
event, | ||
mapping: heGroupMapping, | ||
settings: { | ||
workspaceIdentifier: '', | ||
apiKey: '' | ||
} | ||
}) | ||
).rejects.toThrowError() | ||
}) | ||
|
||
test('Should send an group event to Hyperengage', async () => { | ||
// Mock: Segment group Call | ||
nock('https://events.hyperengage.io').post('/api/v1/s2s/event?token=apiKey').reply(200, { success: true }) | ||
|
||
const event = createTestEvent({ | ||
type: 'group', | ||
traits: { | ||
name: 'test' | ||
}, | ||
groupId: '123456' | ||
}) | ||
|
||
const responses = await testDestination.testAction('group', { | ||
event, | ||
mapping: heGroupMapping, | ||
settings: { | ||
workspaceIdentifier: 'identifier', | ||
apiKey: 'apiKey' | ||
} | ||
}) | ||
|
||
expect(responses.length).toBe(1) | ||
expect(responses[0].status).toEqual(200) | ||
}) | ||
}) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.