-
Notifications
You must be signed in to change notification settings - Fork 254
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into soap-api-support
- Loading branch information
Showing
46 changed files
with
1,516 additions
and
126 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
|
@@ -204,4 +204,52 @@ describe('Hubspot.upsertContact', () => { | |
} | ||
]) | ||
}) | ||
|
||
test('trims string traits', async () => { | ||
const context = new Context({ | ||
type: 'identify', | ||
userId: 'mike', | ||
traits: { | ||
friendly: false, | ||
email: '[email protected]', | ||
address: { | ||
street: '6th St', | ||
city: ' San Francisco ', // to be trimmed | ||
state: 'CA', | ||
postalCode: '94103', | ||
country: 'USA' | ||
}, | ||
equipment: { | ||
type: '🚘', | ||
color: ' red ', // to be trimmed | ||
make: { | ||
make: 'Tesla', | ||
model: 'Model S', | ||
year: 2019 | ||
} | ||
} | ||
} | ||
}) | ||
|
||
await upsertContactEvent.identify?.(context) | ||
expect(mockHubspot.push).toHaveBeenCalledTimes(1) | ||
expect(mockHubspot.push).toHaveBeenCalledWith([ | ||
'identify', | ||
{ | ||
email: '[email protected]', | ||
id: 'mike', | ||
friendly: false, | ||
address: '6th St', | ||
country: 'USA', | ||
state: 'CA', | ||
city: 'San Francisco', | ||
zip: '94103', | ||
equipment_type: '🚘', | ||
equipment_color: 'red', | ||
equipment_make_make: 'Tesla', | ||
equipment_make_model: 'Model S', | ||
equipment_make_year: 2019 | ||
} | ||
]) | ||
}) | ||
}) |
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
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 |
---|---|---|
|
@@ -352,9 +352,19 @@ const multiStatusCompatibleDestination: DestinationDefinition<JSONObject> = { | |
label: 'Email', | ||
description: 'The user email', | ||
type: 'string' | ||
}, | ||
phone: { | ||
label: 'Phone', | ||
description: 'The user phone number', | ||
type: 'string' | ||
} | ||
}, | ||
perform: (_request, { payload }) => { | ||
// Emulate an API error | ||
if (payload.phone) { | ||
throw new IntegrationError('Phone number validation failed', 'Invalid Phone Number', 400) | ||
} | ||
|
||
if (payload.email) { | ||
throw new IntegrationError('Email is required', 'Missing required fields', 400) | ||
} | ||
|
@@ -367,6 +377,21 @@ const multiStatusCompatibleDestination: DestinationDefinition<JSONObject> = { | |
performBatch: (_request, { payload }) => { | ||
const response = new MultiStatusResponse() | ||
payload.forEach((event) => { | ||
// Emulate an API error | ||
if (event?.phone) { | ||
response.pushErrorResponse({ | ||
status: 400, | ||
errortype: ErrorCodes.BAD_REQUEST, | ||
errormessage: 'Phone number validation failed', | ||
sent: event, | ||
body: { | ||
events_processed: 0, | ||
message: 'Phone number validation failed' | ||
} | ||
}) | ||
return | ||
} | ||
|
||
if (event?.email) { | ||
response.pushSuccessResponse({ | ||
body: {}, | ||
|
@@ -1803,6 +1828,15 @@ describe('destination kit', () => { | |
email: '[email protected]' | ||
}, | ||
receivedAt | ||
}, | ||
{ | ||
// Valid Event with emulated rejection | ||
event: 'Add to Cart', | ||
type: 'track', | ||
properties: { | ||
phone: '1234567890' | ||
}, | ||
receivedAt | ||
} | ||
] | ||
|
||
|
@@ -1813,7 +1847,8 @@ describe('destination kit', () => { | |
partnerAction: 'trackEvent', | ||
mapping: { | ||
name: { '@path': '$.event' }, | ||
email: { '@path': '$.properties.email' } | ||
email: { '@path': '$.properties.email' }, | ||
phone: { '@path': '$.properties.phone' } | ||
} | ||
} | ||
} | ||
|
@@ -1856,7 +1891,7 @@ describe('destination kit', () => { | |
}, | ||
Object { | ||
"errormessage": "Email is required", | ||
"errorreporter": "DESTINATION", | ||
"errorreporter": "INTEGRATIONS", | ||
"errortype": "PAYLOAD_VALIDATION_FAILED", | ||
"status": 400, | ||
}, | ||
|
@@ -1865,6 +1900,20 @@ describe('destination kit', () => { | |
"sent": Object {}, | ||
"status": 200, | ||
}, | ||
Object { | ||
"body": Object { | ||
"events_processed": 0, | ||
"message": "Phone number validation failed", | ||
}, | ||
"errormessage": "Phone number validation failed", | ||
"errorreporter": "DESTINATION", | ||
"errortype": "BAD_REQUEST", | ||
"sent": Object { | ||
"name": "Add to Cart", | ||
"phone": "1234567890", | ||
}, | ||
"status": 400, | ||
}, | ||
], | ||
}, | ||
] | ||
|
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
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
Oops, something went wrong.