forked from segmentio/action-destinations
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add performBatch in upsert profile (segmentio#1741)
* Add performBatch in upsert profile * Add enable batching * Update error handling * Update error handling * Remove unused import
- Loading branch information
1 parent
f45356f
commit 6ae4522
Showing
6 changed files
with
225 additions
and
7 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
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 |
---|---|---|
|
@@ -146,7 +146,7 @@ describe('Upsert Profile', () => { | |
|
||
await expect( | ||
testDestination.testAction('upsertProfile', { event, settings, useDefaultMappings: true }) | ||
).rejects.toThrowError('An error occurred while processing the request') | ||
).rejects.toThrowError('Internal Server Error') | ||
}) | ||
|
||
it('should add a profile to a list if list_id is provided', async () => { | ||
|
@@ -263,3 +263,108 @@ describe('Upsert Profile', () => { | |
expect(Functions.addProfileToList).toHaveBeenCalledWith(expect.anything(), profileId, listId) | ||
}) | ||
}) | ||
|
||
describe('Upsert Profile Batch', () => { | ||
beforeEach(() => { | ||
nock.cleanAll() | ||
jest.resetAllMocks() | ||
}) | ||
|
||
it('should discard profiles without email, phone_number, or external_id', async () => { | ||
const events = [createTestEvent({ traits: { first_name: 'John', last_name: 'Doe' } })] | ||
|
||
const response = await testDestination.testBatchAction('upsertProfile', { | ||
settings, | ||
events, | ||
useDefaultMappings: true | ||
}) | ||
|
||
expect(response).toEqual([]) | ||
}) | ||
|
||
it('should process profiles with and without list_ids separately', async () => { | ||
const eventWithListId = createTestEvent({ | ||
traits: { first_name: 'John', last_name: 'Doe', email: '[email protected]', list_id: 'abc123' } | ||
}) | ||
const eventWithoutListId = createTestEvent({ | ||
traits: { first_name: 'Jane', last_name: 'Smith', email: '[email protected]' } | ||
}) | ||
|
||
nock(API_URL).post('/profile-bulk-import-jobs/').reply(200, { success: true, withList: true }) | ||
nock(API_URL).post('/profile-bulk-import-jobs/').reply(200, { success: true, withoutList: true }) | ||
|
||
const responseWithList = await testDestination.testBatchAction('upsertProfile', { | ||
settings, | ||
events: [eventWithListId], | ||
mapping: { list_id: 'abc123' }, | ||
useDefaultMappings: true | ||
}) | ||
|
||
const responseWithoutList = await testDestination.testBatchAction('upsertProfile', { | ||
settings, | ||
events: [eventWithoutListId], | ||
mapping: {}, | ||
useDefaultMappings: true | ||
}) | ||
|
||
expect(responseWithList[0]).toMatchObject({ | ||
data: { success: true, withList: true } | ||
}) | ||
|
||
expect(responseWithoutList[0]).toMatchObject({ | ||
data: { success: true, withoutList: true } | ||
}) | ||
}) | ||
|
||
it('should process profiles with list_ids only', async () => { | ||
const events = [createTestEvent({ traits: { email: '[email protected]', list_id: 'abc123' } })] | ||
|
||
nock(API_URL).post('/profile-bulk-import-jobs/').reply(200, { success: true, withList: true }) | ||
|
||
const response = await testDestination.testBatchAction('upsertProfile', { | ||
settings, | ||
events, | ||
mapping: { list_id: 'abc123' }, | ||
useDefaultMappings: true | ||
}) | ||
|
||
expect(response[0].data).toMatchObject({ | ||
success: true, | ||
withList: true | ||
}) | ||
expect(response).toHaveLength(1) | ||
}) | ||
|
||
it('should process profiles without list_ids only', async () => { | ||
const events = [createTestEvent({ traits: { email: '[email protected]' } })] | ||
|
||
nock(API_URL).post('/profile-bulk-import-jobs/').reply(200, { success: true, withoutList: true }) | ||
|
||
const response = await testDestination.testBatchAction('upsertProfile', { | ||
settings, | ||
events, | ||
mapping: {}, | ||
useDefaultMappings: true | ||
}) | ||
|
||
expect(response[0].data).toMatchObject({ | ||
success: true, | ||
withoutList: true | ||
}) | ||
expect(response).toHaveLength(1) | ||
}) | ||
|
||
it('should handle errors when sending profiles to Klaviyo', async () => { | ||
const events = [createTestEvent({ traits: { email: '[email protected]' } })] | ||
|
||
nock(API_URL).post('/profile-bulk-import-jobs/').reply(500, { error: 'Server error' }) | ||
|
||
await expect( | ||
testDestination.testBatchAction('upsertProfile', { | ||
settings, | ||
events, | ||
useDefaultMappings: true | ||
}) | ||
).rejects.toThrow() | ||
}) | ||
}) |
4 changes: 4 additions & 0 deletions
4
packages/destination-actions/src/destinations/klaviyo/upsertProfile/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