Skip to content

Commit

Permalink
More tests
Browse files Browse the repository at this point in the history
  • Loading branch information
danrowden committed Aug 28, 2024
1 parent de67e21 commit b5ac1f8
Showing 1 changed file with 60 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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',
Expand Down Expand Up @@ -115,7 +117,7 @@ describe('Loops.createOrUpdateContact', () => {
})
})

it('should work with mailingLists data', async () => {
it('should work with mailingLists array', async () => {
const testPayloadIn = {
email: '[email protected]',
userId: 'some-id-2',
Expand Down Expand Up @@ -149,4 +151,61 @@ describe('Loops.createOrUpdateContact', () => {
id: 'someId'
})
})

it('should work with empty mailingLists object', async () => {
const testPayloadIn = {
email: '[email protected]',
userId: 'some-id-2',
mailingLists: []
}
const testPayloadOut = {
email: '[email protected]',
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: '[email protected]',
userId: 'some-id-2'
}
const testPayloadOut = {
email: '[email protected]',
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'
})
})
})

0 comments on commit b5ac1f8

Please sign in to comment.