-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
930 additions
and
31 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -169,6 +169,140 @@ describe(`Trigger event - ${eventTriggerPath} (POST)`, function () { | |
expect(createdSubscriber?.locale).to.equal(payload.locale); | ||
}); | ||
|
||
it('should update a subscribers email if one dont exists', async function () { | ||
const subscriberId = SubscriberRepository.createObjectId(); | ||
const payload = { | ||
subscriberId, | ||
firstName: 'Test Name', | ||
lastName: 'Last of name', | ||
email: undefined, | ||
locale: 'en', | ||
}; | ||
|
||
await axiosInstance.post( | ||
`${session.serverUrl}${eventTriggerPath}`, | ||
{ | ||
name: template.triggers[0].identifier, | ||
to: { | ||
...payload, | ||
}, | ||
payload: { | ||
urlVar: '/test/url/path', | ||
}, | ||
}, | ||
{ | ||
headers: { | ||
authorization: `ApiKey ${session.apiKey}`, | ||
}, | ||
} | ||
); | ||
|
||
await session.awaitRunningJobs(); | ||
const createdSubscriber = await subscriberRepository.findBySubscriberId(session.environment._id, subscriberId); | ||
|
||
expect(createdSubscriber?.subscriberId).to.equal(subscriberId); | ||
expect(createdSubscriber?.firstName).to.equal(payload.firstName); | ||
expect(createdSubscriber?.lastName).to.equal(payload.lastName); | ||
expect(createdSubscriber?.email).to.equal(payload.email); | ||
expect(createdSubscriber?.locale).to.equal(payload.locale); | ||
|
||
await axiosInstance.post( | ||
`${session.serverUrl}${eventTriggerPath}`, | ||
{ | ||
name: template.triggers[0].identifier, | ||
to: { | ||
...payload, | ||
email: '[email protected]', | ||
}, | ||
payload: { | ||
urlVar: '/test/url/path', | ||
}, | ||
}, | ||
{ | ||
headers: { | ||
authorization: `ApiKey ${session.apiKey}`, | ||
}, | ||
} | ||
); | ||
|
||
await session.awaitRunningJobs(); | ||
|
||
const updatedSubscriber = await subscriberRepository.findBySubscriberId(session.environment._id, subscriberId); | ||
|
||
expect(updatedSubscriber?.subscriberId).to.equal(subscriberId); | ||
expect(updatedSubscriber?.firstName).to.equal(payload.firstName); | ||
expect(updatedSubscriber?.lastName).to.equal(payload.lastName); | ||
expect(updatedSubscriber?.email).to.equal('[email protected]'); | ||
expect(updatedSubscriber?.locale).to.equal(payload.locale); | ||
}); | ||
|
||
it('should not unset a subscriber email', async function () { | ||
const subscriberId = SubscriberRepository.createObjectId(); | ||
const payload = { | ||
subscriberId, | ||
firstName: 'Test Name', | ||
lastName: 'Last of name', | ||
email: '[email protected]', | ||
locale: 'en', | ||
}; | ||
|
||
await axiosInstance.post( | ||
`${session.serverUrl}${eventTriggerPath}`, | ||
{ | ||
name: template.triggers[0].identifier, | ||
to: { | ||
...payload, | ||
}, | ||
payload: { | ||
urlVar: '/test/url/path', | ||
}, | ||
}, | ||
{ | ||
headers: { | ||
authorization: `ApiKey ${session.apiKey}`, | ||
}, | ||
} | ||
); | ||
|
||
await session.awaitRunningJobs(); | ||
const createdSubscriber = await subscriberRepository.findBySubscriberId(session.environment._id, subscriberId); | ||
|
||
expect(createdSubscriber?.subscriberId).to.equal(subscriberId); | ||
expect(createdSubscriber?.firstName).to.equal(payload.firstName); | ||
expect(createdSubscriber?.lastName).to.equal(payload.lastName); | ||
expect(createdSubscriber?.email).to.equal(payload.email); | ||
expect(createdSubscriber?.locale).to.equal(payload.locale); | ||
|
||
await axiosInstance.post( | ||
`${session.serverUrl}${eventTriggerPath}`, | ||
{ | ||
name: template.triggers[0].identifier, | ||
to: { | ||
...payload, | ||
email: undefined, | ||
}, | ||
payload: { | ||
urlVar: '/test/url/path', | ||
}, | ||
}, | ||
{ | ||
headers: { | ||
authorization: `ApiKey ${session.apiKey}`, | ||
}, | ||
} | ||
); | ||
|
||
await session.awaitRunningJobs(); | ||
|
||
const updatedSubscriber = await subscriberRepository.findBySubscriberId(session.environment._id, subscriberId); | ||
|
||
expect(updatedSubscriber?.subscriberId).to.equal(subscriberId); | ||
expect(updatedSubscriber?.firstName).to.equal(payload.firstName); | ||
expect(updatedSubscriber?.lastName).to.equal(payload.lastName); | ||
expect(updatedSubscriber?.email).to.equal('[email protected]'); | ||
expect(updatedSubscriber?.locale).to.equal(payload.locale); | ||
}); | ||
|
||
it('should override subscriber email based on event data', async function () { | ||
const subscriberId = SubscriberRepository.createObjectId(); | ||
const transactionId = SubscriberRepository.createObjectId(); | ||
|
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 |
---|---|---|
|
@@ -59,6 +59,51 @@ describe('Update Subscriber - /subscribers/:subscriberId (PUT)', function () { | |
expect(createdSubscriber?.data?.test).to.equal('test value'); | ||
}); | ||
|
||
it('should allow unsetting the email', async function () { | ||
await axiosInstance.post( | ||
`${session.serverUrl}/v1/subscribers`, | ||
{ | ||
subscriberId: '123', | ||
firstName: 'John', | ||
lastName: 'Doe', | ||
email: '[email protected]', | ||
}, | ||
{ | ||
headers: { | ||
authorization: `ApiKey ${session.apiKey}`, | ||
}, | ||
} | ||
); | ||
|
||
const response = await axiosInstance.put( | ||
`${session.serverUrl}/v1/subscribers/123`, | ||
{ | ||
lastName: 'Test Changed', | ||
email: null, | ||
phone: '+972523333333', | ||
locale: 'sv', | ||
data: { test: 'test value' }, | ||
}, | ||
{ | ||
headers: { | ||
authorization: `ApiKey ${session.apiKey}`, | ||
}, | ||
} | ||
); | ||
|
||
const { data: body } = response; | ||
|
||
expect(body.data).to.be.ok; | ||
const createdSubscriber = await subscriberRepository.findBySubscriberId(session.environment._id, '123'); | ||
|
||
expect(createdSubscriber?.firstName).to.equal('John'); | ||
expect(createdSubscriber?.lastName).to.equal('Test Changed'); | ||
expect(createdSubscriber?.email).to.equal(null); | ||
expect(createdSubscriber?.phone).to.equal('+972523333333'); | ||
expect(createdSubscriber?.locale).to.equal('sv'); | ||
expect(createdSubscriber?.data?.test).to.equal('test value'); | ||
}); | ||
|
||
it('should update an existing subscriber credentials', async function () { | ||
await axiosInstance.post( | ||
`${session.serverUrl}/v1/subscribers`, | ||
|
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
Oops, something went wrong.