Skip to content

Commit

Permalink
Merge branch 'main' into next
Browse files Browse the repository at this point in the history
  • Loading branch information
scopsy committed Jul 26, 2023
2 parents e75a1f5 + 673a0e0 commit 7c5e575
Show file tree
Hide file tree
Showing 26 changed files with 930 additions and 31 deletions.
10 changes: 9 additions & 1 deletion .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,14 @@
"GROUP_BY",
"stefanprodan",
"Sendchamp",
"sendchamp"
"sendchamp",
"Quickstarts",
"quickstarts",
"quickstartslogo",
"reactjs",
"nextjs",
"vanillajs",
"quckstart"
],
"flagWords": [],
"patterns": [
Expand Down Expand Up @@ -570,6 +577,7 @@
".vscode/settings.json",
"*/**/.vscode/settings.json",
"docs/src/usage-examples.md",
"docs/static/csv/mock_data.csv",
"apps/worker/README.md",
".gitignore",
"angular.json",
Expand Down
134 changes: 134 additions & 0 deletions apps/api/src/app/events/e2e/trigger-event.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
45 changes: 45 additions & 0 deletions apps/api/src/app/subscribers/e2e/update-subscriber.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
Expand Down
22 changes: 9 additions & 13 deletions docs/docs/cookbook/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ The code sample below fetches the list of all In-App messages sent to a specific
```js
const { data: inAppMessages } = await novu.subscribers.getNotificationsFeed('subscriberId', {
page: 0,
limit: 10,

// it is of type string. By default all feeds messages are fetched
feedIdentifier: 'Marketing',
// seen filter of type boolean
seen: true

//These options will be available in the 0.17.0 release
read: true,
limit: 10
// seen and read filter of type boolean
seen: true,
read: true
});
```

Expand Down Expand Up @@ -120,12 +120,12 @@ You can mark an In-App message as read/seen. Messages from other channels: **Ema
<TabItem value="js" label="Node.js">

```javascript
const { data: markInAppMessageAsRead } = await novu.subscribers.markMessageRead(
const { data: markMessageAsRead } = await novu.subscribers.markMessageRead(
'subscriberId',
'messageId'
);

const { data: markInAppMessageAsSeen } = await novu.subscribers.markMessageSeen(
const { data: markMessageAsSeen } = await novu.subscribers.markMessageSeen(
'subscriberId',
'messageId'
);
Expand All @@ -146,8 +146,8 @@ The unread/unseen functionality has yet to be available in the Node.js SDK. Plea
<TabItem value="js" label="Node.js">

```javascript
// this method will be available in 0.17.0
const { data: markInAppMessageAsRead } = await novu.subscribers.markInAppMessageAs(
// this method will be available in 0.17.1
const { data: markMessageAs } = await novu.subscribers.markMessageAs(
'subscriberId',
'messageId',
{ seen: true, read: false }
Expand All @@ -163,10 +163,6 @@ You can mark all In-App messages as read/unread/seen/unseen.

Messages from other channels: **Email**, **Push**, **Chat**, **Sms** can't be marked as read/unread/seen/unseen.

:::info
This functionality has yet to be made available. It will be in the 0.17.0 release.
:::

<Tabs groupId="language" queryString>
<TabItem value="js" label="Node.js">

Expand Down
Loading

0 comments on commit 7c5e575

Please sign in to comment.