-
Notifications
You must be signed in to change notification settings - Fork 254
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
[SFMC] Add Multistatus Support for SFMC #2639
Open
harsh-joshi99
wants to merge
8
commits into
main
Choose a base branch
from
STRATCONN-5315
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
5ed7ede
add multistatus suppport for sfmc
harsh-joshi99 c8c341c
update multistatus tests
harsh-joshi99 484b19b
update error response
harsh-joshi99 d9e6040
refactor multistatus code
harsh-joshi99 1f97df6
Merge branch 'main' into STRATCONN-5315
harsh-joshi99 85b7d1d
update error handling
harsh-joshi99 d65f464
update function name, check for auth error with error code
harsh-joshi99 e4d726f
Update error body
harsh-joshi99 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
356 changes: 356 additions & 0 deletions
356
...stination-actions/src/destinations/salesforce-marketing-cloud/_tests_/multistatus.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,356 @@ | ||
import { SegmentEvent, createTestEvent, createTestIntegration } from '@segment/actions-core' | ||
import nock from 'nock' | ||
import sfmc from '../index' | ||
import { Settings } from '../generated-types' | ||
|
||
beforeEach(() => nock.cleanAll()) | ||
|
||
const testDestination = createTestIntegration(sfmc) | ||
const settings: Settings = { | ||
subdomain: 'test123', | ||
client_id: 'test123', | ||
client_secret: 'test123', | ||
account_id: 'test123' | ||
} | ||
const requestUrl = `https://${settings.subdomain}.rest.marketingcloudapis.com/hub/v1/dataevents/1234567890/rowset` | ||
const mapping = { | ||
id: { '@path': '$.properties.id' }, | ||
keys: { '@path': '$.properties.keys' }, | ||
values: { '@path': '$.properties.values' } | ||
} | ||
|
||
describe('Multistatus', () => { | ||
describe('dataExtension', () => { | ||
it('should successfully handle a batch of events with complete success response from SFMC API', async () => { | ||
nock(requestUrl).post('').reply(200, {}) | ||
|
||
const events: SegmentEvent[] = [ | ||
// Valid Event | ||
createTestEvent({ | ||
type: 'track', | ||
userId: 'harry-1', | ||
properties: { | ||
id: '1234567890', | ||
keys: { | ||
id: 'HS1' | ||
}, | ||
values: { | ||
name: 'Harry Styles' | ||
} | ||
} | ||
}), | ||
// Valid Event | ||
createTestEvent({ | ||
type: 'track', | ||
userId: 'harry-1', | ||
properties: { | ||
id: '1234567890', | ||
keys: { | ||
id: 'HS1' | ||
}, | ||
values: { | ||
name: 'Harry Styles' | ||
} | ||
} | ||
}) | ||
] | ||
|
||
const response = await testDestination.executeBatch('dataExtension', { | ||
events, | ||
settings, | ||
mapping | ||
}) | ||
|
||
expect(response[0]).toMatchObject({ | ||
status: 200, | ||
body: {} | ||
}) | ||
|
||
expect(response[1]).toMatchObject({ | ||
status: 200, | ||
body: {} | ||
}) | ||
}) | ||
it('should handle the case where both key and id are missing', async () => { | ||
const events: SegmentEvent[] = [ | ||
createTestEvent({ | ||
type: 'track', | ||
userId: 'harry-1', | ||
properties: { | ||
keys: { | ||
id: 'HS1' | ||
}, | ||
values: { | ||
name: 'Harry Styles' | ||
} | ||
} | ||
}), | ||
createTestEvent({ | ||
type: 'track', | ||
userId: 'harry-2', | ||
properties: { | ||
keys: { | ||
id: 'HP1' | ||
}, | ||
values: { | ||
name: 'Harry Potter' | ||
} | ||
} | ||
}) // No key and id provided | ||
] | ||
|
||
const response = await testDestination.executeBatch('dataExtension', { | ||
events, | ||
settings, | ||
mapping | ||
}) | ||
|
||
expect(response[0]).toMatchObject({ | ||
status: 400, | ||
errortype: 'PAYLOAD_VALIDATION_FAILED', | ||
errormessage: | ||
'In order to send an event to a data extension either Data Extension ID or Data Extension Key must be defined.', | ||
errorreporter: 'INTEGRATIONS' | ||
}) | ||
|
||
expect(response[1]).toMatchObject({ | ||
status: 400, | ||
errortype: 'PAYLOAD_VALIDATION_FAILED', | ||
errormessage: | ||
'In order to send an event to a data extension either Data Extension ID or Data Extension Key must be defined.', | ||
errorreporter: 'INTEGRATIONS' | ||
}) | ||
}) | ||
it('should handle multistatus errors when some events fail with specific error messages', async () => { | ||
const errorResponse = { | ||
status: 400, | ||
message: 'Invalid keys for ID: HS1', | ||
additionalErrors: [ | ||
{ | ||
message: 'No record found for ID: HS2' | ||
} | ||
] | ||
} | ||
|
||
nock(requestUrl).post('').reply(400, errorResponse) | ||
|
||
const events: SegmentEvent[] = [ | ||
createTestEvent({ | ||
type: 'track', | ||
userId: 'harry-1', | ||
properties: { | ||
id: '1234567890', | ||
keys: { | ||
id: 'HS1' // Valid key | ||
}, | ||
values: { | ||
name: 'Harry Styles' | ||
} | ||
} | ||
}), | ||
createTestEvent({ | ||
type: 'track', | ||
userId: 'harry-2', | ||
properties: { | ||
id: '1234567890', | ||
keys: { | ||
id: 'HS2' // Invalid key | ||
}, | ||
values: { | ||
name: 'Harry Potter' | ||
} | ||
} | ||
}) | ||
] | ||
|
||
const response = await testDestination.executeBatch('dataExtension', { | ||
events, | ||
settings, | ||
mapping | ||
}) | ||
|
||
expect(response[0]).toMatchObject({ | ||
status: 400, | ||
errortype: 'BAD_REQUEST', | ||
errormessage: 'No record found for ID: HS2', | ||
errorreporter: 'DESTINATION' | ||
}) | ||
|
||
expect(response[1]).toMatchObject({ | ||
status: 400, | ||
errortype: 'BAD_REQUEST', | ||
errormessage: 'No record found for ID: HS2', | ||
errorreporter: 'DESTINATION' | ||
}) | ||
}) | ||
}) | ||
|
||
describe('contactDataExtension', () => { | ||
it('should successfully handle a batch of events with complete success response from SFMC API', async () => { | ||
nock(requestUrl).post('').reply(200, {}) | ||
|
||
const events: SegmentEvent[] = [ | ||
createTestEvent({ | ||
type: 'track', | ||
properties: { | ||
id: '1234567890', | ||
keys: { | ||
contactKey: 'harry-1', | ||
id: 'HS1' | ||
}, | ||
values: { | ||
name: 'Harry Styles' | ||
} | ||
} | ||
}), | ||
createTestEvent({ | ||
type: 'track', | ||
properties: { | ||
id: '1234567890', | ||
keys: { | ||
contactKey: 'harry-2', | ||
id: 'HP1' | ||
}, | ||
values: { | ||
name: 'Harry Potter' | ||
} | ||
} | ||
}) | ||
] | ||
|
||
const response = await testDestination.executeBatch('contactDataExtension', { | ||
events, | ||
settings, | ||
mapping | ||
}) | ||
|
||
expect(response[0]).toMatchObject({ | ||
status: 200, | ||
body: {} | ||
}) | ||
|
||
expect(response[1]).toMatchObject({ | ||
status: 200, | ||
body: {} | ||
}) | ||
}) | ||
|
||
it('should handle the case where both key and id are missing', async () => { | ||
const events: SegmentEvent[] = [ | ||
createTestEvent({ | ||
type: 'track', | ||
userId: 'harry-1', | ||
properties: { | ||
keys: { | ||
contactKey: 'harry-1', | ||
id: 'HS1' | ||
}, | ||
values: { | ||
name: 'Harry Styles' | ||
} | ||
} | ||
}), | ||
createTestEvent({ | ||
type: 'track', | ||
userId: 'harry-2', | ||
properties: { | ||
keys: { | ||
contactKey: 'harry-2', | ||
id: 'HP1' | ||
}, | ||
values: { | ||
name: 'Harry Potter' | ||
} | ||
} | ||
}) // No key and id provided | ||
] | ||
|
||
const response = await testDestination.executeBatch('contactDataExtension', { | ||
events, | ||
settings, | ||
mapping | ||
}) | ||
|
||
expect(response[0]).toMatchObject({ | ||
status: 400, | ||
errortype: 'PAYLOAD_VALIDATION_FAILED', | ||
errormessage: | ||
'In order to send an event to a data extension either Data Extension ID or Data Extension Key must be defined.', | ||
errorreporter: 'INTEGRATIONS' | ||
}) | ||
|
||
expect(response[1]).toMatchObject({ | ||
status: 400, | ||
errortype: 'PAYLOAD_VALIDATION_FAILED', | ||
errormessage: | ||
'In order to send an event to a data extension either Data Extension ID or Data Extension Key must be defined.', | ||
errorreporter: 'INTEGRATIONS' | ||
}) | ||
}) | ||
|
||
it('should handle multistatus errors when some events fail with specific error messages', async () => { | ||
const errorResponse = { | ||
status: 400, | ||
message: 'Invalid keys for ID: HS1', | ||
additionalErrors: [ | ||
{ | ||
message: 'No record found for ID: HS2' | ||
} | ||
] | ||
} | ||
|
||
nock(requestUrl).post('').reply(400, errorResponse) | ||
|
||
const events: SegmentEvent[] = [ | ||
createTestEvent({ | ||
type: 'track', | ||
userId: 'harry-1', | ||
properties: { | ||
id: '1234567890', | ||
keys: { | ||
contactKey: 'harry-1', | ||
id: 'HS1' | ||
}, | ||
values: { | ||
name: 'Harry Styles' | ||
} | ||
} | ||
}), | ||
createTestEvent({ | ||
type: 'track', | ||
userId: 'harry-2', | ||
properties: { | ||
id: '1234567890', | ||
keys: { | ||
contactKey: 'harry-2', | ||
id: 'HS2' | ||
}, | ||
values: { | ||
name: 'Harry Potter' | ||
} | ||
} | ||
}) | ||
] | ||
|
||
const response = await testDestination.executeBatch('contactDataExtension', { | ||
events, | ||
settings, | ||
mapping | ||
}) | ||
|
||
expect(response[0]).toMatchObject({ | ||
status: 400, | ||
errortype: 'BAD_REQUEST', | ||
errormessage: 'No record found for ID: HS2', | ||
errorreporter: 'DESTINATION' | ||
}) | ||
|
||
expect(response[1]).toMatchObject({ | ||
status: 400, | ||
errortype: 'BAD_REQUEST', | ||
errormessage: 'No record found for ID: HS2', | ||
errorreporter: 'DESTINATION' | ||
}) | ||
}) | ||
}) | ||
}) |
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.
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.
Question for my understanding: Why would
response[0]
show an error related to ID: HS2 whenevents[0]
is sending ID: HS1?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.
SFMC will return an error if any event in the payload is invalid and will fail the entire batch. Therefore, the error message is returned for all events to indicate that at least one of them has an issue.
Also the error message here is a dummy example, SFMC error messages do not specify the id.