Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(api): api docs not generated and added more e2e tests #2665

Merged
merged 1 commit into from
Feb 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ export class SendMessage {
const shouldRun = await this.filter(command);
const preferred = await this.filterPreferredChannels(command.job);

const stepType = command.step?.template?.type;

if (!command.payload?.$on_boarding_trigger) {
this.analyticsService.track('Process Workflow Step - [Triggers]', command.userId, {
_template: command.job._templateId,
Expand All @@ -85,12 +87,11 @@ export class SendMessage {
return;
}

if (command.step.template.type !== StepTypeEnum.DELAY) {
if (stepType !== StepTypeEnum.DELAY) {
await this.createExecutionDetails.execute(
CreateExecutionDetailsCommand.create({
...CreateExecutionDetailsCommand.getDetailsFromJob(command.job),
detail:
command.step.template.type === StepTypeEnum.DIGEST ? DetailEnum.START_DIGESTING : DetailEnum.START_SENDING,
detail: stepType === StepTypeEnum.DIGEST ? DetailEnum.START_DIGESTING : DetailEnum.START_SENDING,
source: ExecutionDetailsSourceEnum.INTERNAL,
status: ExecutionDetailsStatusEnum.PENDING,
isTest: false,
Expand All @@ -99,7 +100,7 @@ export class SendMessage {
);
}

switch (command.step.template.type) {
switch (stepType) {
case StepTypeEnum.SMS:
return await this.sendMessageSms.execute(command);
case StepTypeEnum.IN_APP:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export class UpdateNotificationTemplate {
for (const message of steps) {
let stepId = message._id;
if (message._templateId) {
if (!message.template) throw new ApiException("Something un-expected happened, template couldn't be found");
if (!message.template) throw new ApiException(`Something un-expected happened, template couldn't be found`);

const template = await this.updateMessageTemplate.execute(
UpdateMessageTemplateCommand.create({
Expand Down
22 changes: 11 additions & 11 deletions apps/api/src/app/subscribers/e2e/create-subscriber.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ describe('Create Subscriber - /subscribers (POST)', function () {
expect(body.data).to.be.ok;
const createdSubscriber = await subscriberRepository.findBySubscriberId(session.environment._id, '123');

expect(createdSubscriber.firstName).to.equal('John');
expect(createdSubscriber.email).to.equal('john@doe.com');
expect(createdSubscriber.phone).to.equal('+972523333333');
expect(createdSubscriber.locale).to.equal('en');
expect(createdSubscriber.data.test1).to.equal('test value1');
expect(createdSubscriber?.firstName).to.equal('John');
expect(createdSubscriber?.email).to.equal('john@doe.com');
expect(createdSubscriber?.phone).to.equal('+972523333333');
expect(createdSubscriber?.locale).to.equal('en');
Comment on lines +41 to +44
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Linter warnings fixes

expect(createdSubscriber?.data?.test1).to.equal('test value1');
});

it('should update subscriber if already created', async function () {
Expand Down Expand Up @@ -96,11 +96,11 @@ describe('Create Subscriber - /subscribers (POST)', function () {
expect(body.data).to.be.ok;
const createdSubscriber = await subscriberRepository.findBySubscriberId(session.environment._id, '123');

expect(createdSubscriber.firstName).to.equal('Mary');
expect(createdSubscriber.email).to.equal('john@doe.com');
expect(createdSubscriber.locale).to.equal('en');
expect(createdSubscriber.data.test1).to.equal('new test value1');
expect(!createdSubscriber.data.test2).to.equal(true);
expect(createdSubscriber.data.test3).to.equal('test value3');
expect(createdSubscriber?.firstName).to.equal('Mary');
expect(createdSubscriber?.email).to.equal('john@doe.com');
expect(createdSubscriber?.locale).to.equal('en');
Comment on lines +99 to +101
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Linter warnings fixes

expect(createdSubscriber?.data?.test1).to.equal('new test value1');
expect(!createdSubscriber?.data?.test2).to.equal(true);
expect(createdSubscriber?.data?.test3).to.equal('test value3');
});
});
11 changes: 1 addition & 10 deletions apps/api/src/app/subscribers/e2e/get-preferences.e2e.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { UserSession } from '@novu/testing';
import { expect } from 'chai';
import axios from 'axios';
import { NotificationTemplateEntity } from '@novu/dal';

const axiosInstance = axios.create();
import { getPreference } from './helpers';

describe('Get Subscribers preferences - /subscribers/preferences/:subscriberId (GET)', function () {
let session: UserSession;
Expand All @@ -26,11 +25,3 @@ describe('Get Subscribers preferences - /subscribers/preferences/:subscriberId (
expect(data.preference.channels.in_app).to.equal(true);
});
});

export async function getPreference(session) {
return await axiosInstance.get(`${session.serverUrl}/v1/subscribers/${session.subscriberId}/preferences`, {
headers: {
authorization: `ApiKey ${session.apiKey}`,
},
});
}
64 changes: 64 additions & 0 deletions apps/api/src/app/subscribers/e2e/helpers/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { UserSession } from '@novu/testing';
import { IUpdateNotificationTemplateDto } from '@novu/shared';
import axios from 'axios';

import { UpdateSubscriberOnlineFlagRequestDto } from '../../dtos/update-subscriber-online-flag-request.dto';
import { UpdateSubscriberPreferenceRequestDto } from '../../../widgets/dtos/update-subscriber-preference-request.dto';

const axiosInstance = axios.create();

export async function getNotificationTemplate(session: UserSession, id: string) {
return await axiosInstance.get(`${session.serverUrl}/v1/notification-templates/${id}`, {
headers: {
authorization: `ApiKey ${session.apiKey}`,
},
});
}

export async function updateNotificationTemplate(
session: UserSession,
id: string,
data: IUpdateNotificationTemplateDto
) {
return await axiosInstance.put(`${session.serverUrl}/v1/notification-templates/${id}`, data, {
headers: {
authorization: `ApiKey ${session.apiKey}`,
},
});
}

export async function getPreference(session: UserSession) {
return await axiosInstance.get(`${session.serverUrl}/v1/subscribers/${session.subscriberId}/preferences`, {
headers: {
authorization: `ApiKey ${session.apiKey}`,
},
});
}

export async function updateSubscriberOnlineFlag(
data: UpdateSubscriberOnlineFlagRequestDto,
session: UserSession,
subscriberId: string
) {
return await axiosInstance.patch(`${session.serverUrl}/v1/subscribers/${subscriberId}/online-status`, data, {
headers: {
authorization: `ApiKey ${session.apiKey}`,
},
});
}

export async function updatePreference(
data: UpdateSubscriberPreferenceRequestDto,
session: UserSession,
templateId: string
) {
return await axiosInstance.patch(
`${session.serverUrl}/v1/subscribers/${session.subscriberId}/preferences/${templateId}`,
data,
{
headers: {
authorization: `ApiKey ${session.apiKey}`,
},
}
);
}
2 changes: 1 addition & 1 deletion apps/api/src/app/subscribers/e2e/remove-subscriber.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('Delete Subscriber - /subscribers/:subscriberId (DELETE)', function ()
);

const createdSubscriber = await subscriberRepository.findBySubscriberId(session.environment._id, '123');
expect(createdSubscriber.subscriberId).to.equal('123');
expect(createdSubscriber?.subscriberId).to.equal('123');
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Linter warnings fixes


await axiosInstance.delete(`${session.serverUrl}/v1/subscribers/123`, {
headers: {
Expand Down
17 changes: 1 addition & 16 deletions apps/api/src/app/subscribers/e2e/update-online-flag.e2e.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import { SubscribersService, UserSession } from '@novu/testing';
import { expect } from 'chai';
import axios from 'axios';
import { sub } from 'date-fns';
import { SubscriberEntity } from '@novu/dal';

import { UpdateSubscriberOnlineFlagRequestDto } from '../../subscribers/dtos/update-subscriber-online-flag-request.dto';

const axiosInstance = axios.create();
import { updateSubscriberOnlineFlag } from './helpers';

describe('Update Subscriber online flag - /subscribers/:subscriberId/online-status (PATCH)', function () {
let session: UserSession;
Expand Down Expand Up @@ -49,15 +46,3 @@ describe('Update Subscriber online flag - /subscribers/:subscriberId/online-stat
expect(data.data.isOnline).to.equal(true);
});
});

async function updateSubscriberOnlineFlag(
data: UpdateSubscriberOnlineFlagRequestDto,
session: UserSession,
subscriberId: string
) {
return await axiosInstance.patch(`${session.serverUrl}/v1/subscribers/${subscriberId}/online-status`, data, {
headers: {
authorization: `ApiKey ${session.apiKey}`,
},
});
}
Loading