diff --git a/packages/destination-actions/src/destinations/loops/createOrUpdateContact/__tests__/index.test.ts b/packages/destination-actions/src/destinations/loops/createOrUpdateContact/__tests__/index.test.ts index db31d2bb92..5536bba7a0 100644 --- a/packages/destination-actions/src/destinations/loops/createOrUpdateContact/__tests__/index.test.ts +++ b/packages/destination-actions/src/destinations/loops/createOrUpdateContact/__tests__/index.test.ts @@ -22,6 +22,7 @@ describe('Loops.createOrUpdateContact', () => { }) it('should work', async () => { + /* Event data going into Segment */ const testPayloadIn = { createdAt: '2025-05-05T14:17:38.089Z', customAttributes: { @@ -35,6 +36,7 @@ describe('Loops.createOrUpdateContact', () => { userGroup: 'Alum', userId: 'some-id-1' } + /* Processed data coming out of Segment to the API */ const testPayloadOut = { createdAt: '2025-05-05T14:17:38.089Z', favoriteColor: 'blue', @@ -115,7 +117,7 @@ describe('Loops.createOrUpdateContact', () => { }) }) - it('should work with mailingLists data', async () => { + it('should work with mailingLists array', async () => { const testPayloadIn = { email: 'test@example.com', userId: 'some-id-2', @@ -149,4 +151,61 @@ describe('Loops.createOrUpdateContact', () => { id: 'someId' }) }) + + it('should work with empty mailingLists object', async () => { + const testPayloadIn = { + email: 'test@example.com', + userId: 'some-id-2', + mailingLists: [] + } + const testPayloadOut = { + email: 'test@example.com', + userId: 'some-id-2', + mailingLists: {} + } + nock('https://app.loops.so/api/v1').put('/contacts/update', testPayloadOut).reply(200, { + success: true, + id: 'someId' + }) + + const responses = await testDestination.testAction('createOrUpdateContact', { + mapping: testPayloadIn, + settings: { apiKey: LOOPS_API_KEY } + }) + + expect(responses.length).toBe(1) + expect(responses[0].status).toBe(200) + expect(responses[0].data).toStrictEqual({ + success: true, + id: 'someId' + }) + }) + + it('should work with no mailingLists object', async () => { + const testPayloadIn = { + email: 'test@example.com', + userId: 'some-id-2' + } + const testPayloadOut = { + email: 'test@example.com', + userId: 'some-id-2', + mailingLists: {} + } + nock('https://app.loops.so/api/v1').put('/contacts/update', testPayloadOut).reply(200, { + success: true, + id: 'someId' + }) + + const responses = await testDestination.testAction('createOrUpdateContact', { + mapping: testPayloadIn, + settings: { apiKey: LOOPS_API_KEY } + }) + + expect(responses.length).toBe(1) + expect(responses[0].status).toBe(200) + expect(responses[0].data).toStrictEqual({ + success: true, + id: 'someId' + }) + }) })