Skip to content

Commit

Permalink
Merge pull request #5 from Loops-so/fix_tests
Browse files Browse the repository at this point in the history
update tests and snapshots
  • Loading branch information
askkaz authored Aug 22, 2024
2 parents 954b21d + 9d27c0c commit a9b8c4f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Object {
"firstName": "3dQ7ER]1HKW",
"lastName": "3dQ7ER]1HKW",
"mailingLists": Object {
"testType": "3dQ7ER]1HKW",
"3dQ7ER]1HKW": true,
},
"source": "3dQ7ER]1HKW",
"subscribed": true,
Expand All @@ -19,6 +19,7 @@ Object {

exports[`Testing snapshot for actions-loops destination: createOrUpdateContact action - required fields 1`] = `
Object {
"mailingLists": Object {},
"userId": "3dQ7ER]1HKW",
}
`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Object {
"firstName": "IAIhDY9yOUxjQs(FSFfe",
"lastName": "IAIhDY9yOUxjQs(FSFfe",
"mailingLists": Object {
"testType": "IAIhDY9yOUxjQs(FSFfe",
"IAIhDY9yOUxjQs(FSFfe": false,
},
"source": "IAIhDY9yOUxjQs(FSFfe",
"subscribed": false,
Expand All @@ -19,6 +19,7 @@ Object {

exports[`Testing snapshot for Loops's createOrUpdateContact destination action: required fields 1`] = `
Object {
"mailingLists": Object {},
"userId": "IAIhDY9yOUxjQs(FSFfe",
}
`;
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ describe('Loops.createOrUpdateContact', () => {
source: 'Segment',
subscribed: true,
userGroup: 'Alum',
userId: 'some-id-1'
userId: 'some-id-1',
mailingLists: {}
}
nock('https://app.loops.so/api/v1').put('/contacts/update', testPayloadOut).reply(200, {
success: true,
Expand All @@ -65,34 +66,44 @@ describe('Loops.createOrUpdateContact', () => {
})

it('should not work without email', async () => {
const testPayload = {
const testPayloadIn = {
firstName: 'Ellen',
userId: 'some-id-1'
}
nock('https://app.loops.so/api/v1').put('/contacts/update', testPayload).reply(400, {
const testPayloadOut = {
firstName: 'Ellen',
userId: 'some-id-1',
mailingLists: {}
}
nock('https://app.loops.so/api/v1').put('/contacts/update', testPayloadOut).reply(400, {
success: false,
message: 'userId not found and cannot create a new contact without an email.'
})
await expect(
testDestination.testAction('createOrUpdateContact', {
mapping: testPayload,
mapping: testPayloadIn,
settings: { apiKey: LOOPS_API_KEY }
})
).rejects.toThrow('Bad Request')
})

it('should work without optional fields', async () => {
const testPayload = {
const testPayloadIn = {
email: '[email protected]',
userId: 'some-id-2'
}
nock('https://app.loops.so/api/v1').put('/contacts/update', testPayload).reply(200, {
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: testPayload,
mapping: testPayloadIn,
settings: { apiKey: LOOPS_API_KEY }
})

Expand Down

0 comments on commit a9b8c4f

Please sign in to comment.