-
Notifications
You must be signed in to change notification settings - Fork 240
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added condition for event name in hubspot (#1364)
* Added condition for event name in hubspot * Added portalId in settings and added unit test * Added condition when portal Id is not configure in setting and added unit test * Resolve comments for PR --------- Co-authored-by: Harsh Vardhan <[email protected]>
- Loading branch information
1 parent
1a60942
commit dee4caf
Showing
8 changed files
with
220 additions
and
68 deletions.
There are no files selected for viewing
15 changes: 3 additions & 12 deletions
15
...estination-actions/src/destinations/hubspot/__tests__/__snapshots__/snapshot.test.ts.snap
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 |
---|---|---|
@@ -1,20 +1,11 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Testing snapshot for actions-hubspot-cloud destination: sendCustomBehavioralEvent action - all fields 1`] = ` | ||
Object { | ||
"email": "[email protected]", | ||
"eventName": "NTxWtuPi(z!bOHmgT^*3", | ||
"objectId": "NTxWtuPi(z!bOHmgT^*3", | ||
"occurredAt": "2021-02-01T00:00:00.000Z", | ||
"properties": Object { | ||
"testType": "NTxWtuPi(z!bOHmgT^*3", | ||
}, | ||
"utk": "NTxWtuPi(z!bOHmgT^*3", | ||
} | ||
`; | ||
exports[`Testing snapshot for actions-hubspot-cloud destination: sendCustomBehavioralEvent action - all fields 1`] = `[PayloadValidationError: EventName should begin with peNTxWtuPi(z!bOHmgT^*3_]`; | ||
|
||
exports[`Testing snapshot for actions-hubspot-cloud destination: sendCustomBehavioralEvent action - required fields 1`] = `[PayloadValidationError: One of the following parameters: email, user token, or objectId is required]`; | ||
|
||
exports[`Testing snapshot for actions-hubspot-cloud destination: sendCustomBehavioralEvent action - required fields 1`] = `[PayloadValidationError: EventName should begin with peNTxWtuPi(z!bOHmgT^*3_]`; | ||
|
||
exports[`Testing snapshot for actions-hubspot-cloud destination: upsertCompany action - all fields 1`] = ` | ||
Object { | ||
"properties": Object { | ||
|
7 changes: 6 additions & 1 deletion
7
packages/destination-actions/src/destinations/hubspot/generated-types.ts
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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 |
---|---|---|
|
@@ -12,3 +12,16 @@ Object { | |
"utk": "abverazffa===1314122f", | ||
} | ||
`; | ||
|
||
exports[`HubSpot.sendCustomBehavioralEvent should succeed when all fields are given 1`] = ` | ||
Object { | ||
"email": "[email protected]", | ||
"eventName": "pe22596207_test_event_http", | ||
"objectId": "802", | ||
"occurredAt": "2023-07-05T08:28:35.216Z", | ||
"properties": Object { | ||
"hs_city": "city", | ||
}, | ||
"utk": "abverazffa===1314122f", | ||
} | ||
`; |
36 changes: 2 additions & 34 deletions
36
...tinations/hubspot/sendCustomBehavioralEvent/__tests__/__snapshots__/snapshot.test.ts.snap
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 |
---|---|---|
@@ -1,37 +1,5 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Testing snapshot for HubSpot's sendCustomBehavioralEvent destination action: all fields 1`] = ` | ||
Object { | ||
"email": "[email protected]", | ||
"eventName": "9B#[dv&Iy", | ||
"objectId": "9B#[dv&Iy", | ||
"occurredAt": "2021-02-01T00:00:00.000Z", | ||
"properties": Object { | ||
"testType": "9B#[dv&Iy", | ||
}, | ||
"utk": "9B#[dv&Iy", | ||
} | ||
`; | ||
exports[`Testing snapshot for HubSpot's sendCustomBehavioralEvent destination action: all fields 1`] = `[PayloadValidationError: EventName should begin with pe9B#[dv&Iy_]`; | ||
|
||
exports[`Testing snapshot for HubSpot's sendCustomBehavioralEvent destination action: required fields 1`] = ` | ||
Object { | ||
"email": "[email protected]", | ||
"eventName": "9B#[dv&Iy", | ||
} | ||
`; | ||
|
||
exports[`Testing snapshot for HubSpot's sendCustomBehavioralEvent destination action: required fields 2`] = ` | ||
Headers { | ||
Symbol(map): Object { | ||
"authorization": Array [ | ||
"Bearer undefined", | ||
], | ||
"content-type": Array [ | ||
"application/json", | ||
], | ||
"user-agent": Array [ | ||
"Segment (Actions)", | ||
], | ||
}, | ||
} | ||
`; | ||
exports[`Testing snapshot for HubSpot's sendCustomBehavioralEvent destination action: required fields 1`] = `[PayloadValidationError: EventName should begin with pe9B#[dv&Iy_]`; |
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 |
---|---|---|
|
@@ -4,6 +4,9 @@ import Destination from '../../index' | |
import { HUBSPOT_BASE_URL } from '../../properties' | ||
|
||
let testDestination = createTestIntegration(Destination) | ||
const settings = { | ||
portalId: '22596207' | ||
} | ||
|
||
beforeEach((done) => { | ||
// Re-Initialize the destination before each test | ||
|
@@ -166,6 +169,139 @@ describe('HubSpot.sendCustomBehavioralEvent', () => { | |
}) | ||
}) | ||
|
||
test('should fail when event name does not start with pe{hubId}_ and hubId is configured in settings', async () => { | ||
const event = createTestEvent({ | ||
type: 'track', | ||
event: 'test_event', | ||
properties: { | ||
email: '[email protected]', | ||
utk: 'abverazffa===1314122f', | ||
userId: '802', | ||
city: 'city' | ||
} | ||
}) | ||
|
||
const mapping = { | ||
eventName: { | ||
'@path': '$.event' | ||
}, | ||
utk: { | ||
'@path': '$.properties.utk' | ||
}, | ||
objectId: { | ||
'@path': '$.properties.userId' | ||
}, | ||
properties: { | ||
hs_city: { | ||
'@path': '$.properties.city' | ||
} | ||
} | ||
} | ||
|
||
return expect( | ||
testDestination.testAction('sendCustomBehavioralEvent', { | ||
event, | ||
settings, | ||
useDefaultMappings: true, | ||
mapping: mapping | ||
}) | ||
).rejects.toThrowError(`EventName should begin with pe${settings.portalId}_`) | ||
}) | ||
|
||
test('should fail when event name does not start with pe{hubId}_ and hubId is not configured in settings', async () => { | ||
const event = createTestEvent({ | ||
type: 'track', | ||
event: 'test_event', | ||
properties: { | ||
email: '[email protected]', | ||
utk: 'abverazffa===1314122f', | ||
userId: '802', | ||
city: 'city' | ||
} | ||
}) | ||
|
||
settings.portalId = '' | ||
|
||
const mapping = { | ||
eventName: { | ||
'@path': '$.event' | ||
}, | ||
utk: { | ||
'@path': '$.properties.utk' | ||
}, | ||
objectId: { | ||
'@path': '$.properties.userId' | ||
}, | ||
properties: { | ||
hs_city: { | ||
'@path': '$.properties.city' | ||
} | ||
} | ||
} | ||
|
||
return expect( | ||
testDestination.testAction('sendCustomBehavioralEvent', { | ||
event, | ||
settings, | ||
useDefaultMappings: true, | ||
mapping: mapping | ||
}) | ||
).rejects.toThrowError(`EventName should begin with pe<hubId>_`) | ||
}) | ||
|
||
test('should succeed when all fields are given', async () => { | ||
const event = createTestEvent({ | ||
type: 'track', | ||
event: 'pe22596207_test_event_http', | ||
timestamp: '2023-07-05T08:28:35.216Z', | ||
properties: { | ||
email: '[email protected]', | ||
utk: 'abverazffa===1314122f', | ||
userId: '802', | ||
city: 'city' | ||
} | ||
}) | ||
|
||
const expectedPayload = { | ||
eventName: event.event, | ||
occurredAt: event.timestamp as string, | ||
utk: event.properties?.utk, | ||
email: event.properties?.email, | ||
objectId: event.properties?.userId, | ||
properties: { | ||
hs_city: event.properties?.city | ||
} | ||
} | ||
|
||
const mapping = { | ||
eventName: { | ||
'@path': '$.event' | ||
}, | ||
utk: { | ||
'@path': '$.properties.utk' | ||
}, | ||
objectId: { | ||
'@path': '$.properties.userId' | ||
}, | ||
properties: { | ||
hs_city: { | ||
'@path': '$.properties.city' | ||
} | ||
} | ||
} | ||
|
||
nock(HUBSPOT_BASE_URL).post('/events/v3/send', expectedPayload).reply(204, {}) | ||
|
||
const responses = await testDestination.testAction('sendCustomBehavioralEvent', { | ||
event, | ||
useDefaultMappings: true, | ||
mapping: mapping | ||
}) | ||
expect(responses.length).toBe(1) | ||
expect(responses[0].status).toBe(204) | ||
expect(responses[0].options.json).toMatchSnapshot() | ||
}) | ||
|
||
test('should fail when email, utk and objectId is not provided', async () => { | ||
const event = createTestEvent({ | ||
type: 'track', | ||
|
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 |
---|---|---|
|
@@ -21,19 +21,29 @@ describe(`Testing snapshot for ${destinationSlug}'s ${actionSlug} destination ac | |
properties: { ...eventData, email: '[email protected]' } | ||
}) | ||
|
||
const responses = await testDestination.testAction(actionSlug, { | ||
event: event, | ||
mapping: event.properties, | ||
settings: settingsData, | ||
auth: undefined | ||
}) | ||
try { | ||
const responses = await testDestination.testAction(actionSlug, { | ||
event: event, | ||
mapping: event.properties, | ||
settings: settingsData, | ||
auth: undefined | ||
}) | ||
|
||
const request = responses[0].request | ||
const json = await request.json() | ||
const request = responses[0].request | ||
const rawBody = await request.text() | ||
|
||
expect(json).toMatchSnapshot() | ||
try { | ||
const json = JSON.parse(rawBody) | ||
expect(json).toMatchSnapshot() | ||
return | ||
} catch (err) { | ||
expect(rawBody).toMatchSnapshot() | ||
} | ||
|
||
expect(request.headers).toMatchSnapshot() | ||
expect(request.headers).toMatchSnapshot() | ||
} catch (e) { | ||
expect(e).toMatchSnapshot() | ||
} | ||
}) | ||
|
||
it('all fields', async () => { | ||
|
@@ -46,15 +56,28 @@ describe(`Testing snapshot for ${destinationSlug}'s ${actionSlug} destination ac | |
properties: eventData | ||
}) | ||
|
||
const responses = await testDestination.testAction(actionSlug, { | ||
event: event, | ||
mapping: event.properties, | ||
settings: settingsData, | ||
auth: undefined | ||
}) | ||
try { | ||
const responses = await testDestination.testAction(actionSlug, { | ||
event: event, | ||
mapping: event.properties, | ||
settings: settingsData, | ||
auth: undefined | ||
}) | ||
|
||
const request = responses[0].request | ||
const rawBody = await request.json() | ||
|
||
try { | ||
const json = JSON.parse(rawBody) | ||
expect(json).toMatchSnapshot() | ||
return | ||
} catch (err) { | ||
expect(rawBody).toMatchSnapshot() | ||
} | ||
|
||
const request = responses[0].request | ||
const json = await request.json() | ||
expect(json).toMatchSnapshot() | ||
expect(request.headers).toMatchSnapshot() | ||
} catch (e) { | ||
expect(e).toMatchSnapshot() | ||
} | ||
}) | ||
}) |
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