Skip to content

Commit 24a74a3

Browse files
adding multistatus unit tests
1 parent 5e6be46 commit 24a74a3

1 file changed

Lines changed: 122 additions & 1 deletion

File tree

  • packages/destination-actions/src/destinations/braze/mergeUsers/__tests__

packages/destination-actions/src/destinations/braze/mergeUsers/__tests__/index.test.ts

Lines changed: 122 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import nock from 'nock'
2-
import { createTestEvent, createTestIntegration, SegmentEvent } from '@segment/actions-core'
2+
import { createTestEvent, createTestIntegration, SegmentEvent, MultiStatusResponse } from '@segment/actions-core'
33
import Destination from '../../index'
44

55
const testDestination = createTestIntegration(Destination)
@@ -576,3 +576,124 @@ describe('Braze.mergeUsers batch', () => {
576576
expect(mergeUpdates[1].identifier_to_keep).not.toHaveProperty('prioritization')
577577
})
578578
})
579+
580+
describe('Braze.mergeUsers multiStatus', () => {
581+
afterEach(() => {
582+
nock.cleanAll()
583+
})
584+
585+
it('should handle a batch with mixed validation failures and successes', async () => {
586+
nock(settings.endpoint).post('/users/merge').reply(200, { message: 'success' })
587+
588+
const events: SegmentEvent[] = [
589+
createTestEvent({ type: 'alias', userId: 'keep-1', previousId: 'merge-1' }),
590+
createTestEvent({ type: 'alias', userId: '', previousId: 'merge-2' }),
591+
createTestEvent({ type: 'alias', userId: 'keep-3', previousId: 'merge-3' }),
592+
createTestEvent({ type: 'alias', userId: '', previousId: '' })
593+
]
594+
595+
const response = await testDestination.executeBatch('mergeUsers', {
596+
events,
597+
settings,
598+
mapping: {
599+
previousIdType: 'external_id',
600+
previousIdValue: { '@path': '$.previousId' },
601+
keepIdType: 'external_id',
602+
keepIdValue: { '@path': '$.userId' }
603+
}
604+
})
605+
606+
expect(response[0]).toMatchObject({
607+
status: 200,
608+
body: { merge_updates: [{ identifier_to_merge: { external_id: 'merge-1' }, identifier_to_keep: { external_id: 'keep-1' } }] }
609+
})
610+
611+
expect(response[1]).toMatchObject({
612+
status: 400,
613+
errortype: 'PAYLOAD_VALIDATION_FAILED',
614+
errormessage: 'ID value to keep must be provided.',
615+
errorreporter: 'DESTINATION'
616+
})
617+
618+
expect(response[2]).toMatchObject({
619+
status: 200,
620+
body: { merge_updates: [{ identifier_to_merge: { external_id: 'merge-3' }, identifier_to_keep: { external_id: 'keep-3' } }] }
621+
})
622+
623+
expect(response[3]).toMatchObject({
624+
status: 400,
625+
errortype: 'PAYLOAD_VALIDATION_FAILED',
626+
errorreporter: 'DESTINATION'
627+
})
628+
})
629+
630+
it('should handle a batch with validation failures and an unsuccessful HTTP response', async () => {
631+
nock(settings.endpoint).post('/users/merge').reply(400, { message: 'Invalid merge request' })
632+
633+
const events: SegmentEvent[] = [
634+
createTestEvent({ type: 'alias', userId: 'keep-1', previousId: 'merge-1' }),
635+
createTestEvent({ type: 'alias', userId: '', previousId: 'merge-2' }),
636+
createTestEvent({ type: 'alias', userId: 'keep-3', previousId: 'merge-3' })
637+
]
638+
639+
const response = await testDestination.executeBatch('mergeUsers', {
640+
events,
641+
settings,
642+
mapping: {
643+
previousIdType: 'external_id',
644+
previousIdValue: { '@path': '$.previousId' },
645+
keepIdType: 'external_id',
646+
keepIdValue: { '@path': '$.userId' }
647+
}
648+
})
649+
650+
expect(response[0]).toMatchObject({
651+
status: 400,
652+
errorreporter: 'DESTINATION'
653+
})
654+
655+
expect(response[1]).toMatchObject({
656+
status: 400,
657+
errortype: 'PAYLOAD_VALIDATION_FAILED',
658+
errormessage: 'ID value to keep must be provided.',
659+
errorreporter: 'DESTINATION'
660+
})
661+
662+
expect(response[2]).toMatchObject({
663+
status: 400,
664+
errorreporter: 'DESTINATION'
665+
})
666+
})
667+
668+
it('should handle a batch where all payloads fail validation', async () => {
669+
const events: SegmentEvent[] = [
670+
createTestEvent({ type: 'alias', userId: '', previousId: 'merge-1' }),
671+
createTestEvent({ type: 'alias', userId: '', previousId: 'merge-2' })
672+
]
673+
674+
const response = await testDestination.executeBatch('mergeUsers', {
675+
events,
676+
settings,
677+
mapping: {
678+
previousIdType: 'external_id',
679+
previousIdValue: { '@path': '$.previousId' },
680+
keepIdType: 'external_id',
681+
keepIdValue: { '@path': '$.userId' }
682+
}
683+
})
684+
685+
expect(response[0]).toMatchObject({
686+
status: 400,
687+
errortype: 'PAYLOAD_VALIDATION_FAILED',
688+
errormessage: 'ID value to keep must be provided.',
689+
errorreporter: 'DESTINATION'
690+
})
691+
692+
expect(response[1]).toMatchObject({
693+
status: 400,
694+
errortype: 'PAYLOAD_VALIDATION_FAILED',
695+
errormessage: 'ID value to keep must be provided.',
696+
errorreporter: 'DESTINATION'
697+
})
698+
})
699+
})

0 commit comments

Comments
 (0)