Skip to content

Commit

Permalink
fix(api): align e2e testing and open api for notification and subscri…
Browse files Browse the repository at this point in the history
…bers
  • Loading branch information
tatarco committed Dec 23, 2024
1 parent a207e52 commit 59c6011
Show file tree
Hide file tree
Showing 83 changed files with 2,321 additions and 1,641 deletions.
21 changes: 14 additions & 7 deletions apps/api/src/app/inbox/e2e/get-notifications-count.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,27 @@ import { expect } from 'chai';
import { UserSession } from '@novu/testing';
import { MessageRepository, NotificationTemplateEntity, SubscriberEntity, SubscriberRepository } from '@novu/dal';
import {
StepTypeEnum,
ChannelCTATypeEnum,
TemplateVariableTypeEnum,
ActorTypeEnum,
SystemAvatarIconEnum,
ChannelCTATypeEnum,
ChannelTypeEnum,
StepTypeEnum,
SystemAvatarIconEnum,
TemplateVariableTypeEnum,
} from '@novu/shared';
import { Novu } from '@novu/api';
import { initNovuClassSdk } from '../../shared/helpers/e2e/sdk/e2e-sdk.helper';

describe('Get Notifications Count - /inbox/notifications/count (GET)', async () => {
let session: UserSession;
let template: NotificationTemplateEntity;
let subscriber: SubscriberEntity | null;
const messageRepository = new MessageRepository();
const subscriberRepository = new SubscriberRepository();

let novuClient: Novu;
beforeEach(async () => {
session = new UserSession();
await session.initialize();

novuClient = initNovuClassSdk(session);
subscriber = await subscriberRepository.findBySubscriberId(session.environment._id, session.subscriberId);
template = await session.createTemplate({
noFeedId: true,
Expand Down Expand Up @@ -60,7 +62,12 @@ describe('Get Notifications Count - /inbox/notifications/count (GET)', async ()
const triggerEvent = async (templateToTrigger: NotificationTemplateEntity, times = 1) => {
const promises: Array<Promise<unknown>> = [];
for (let i = 0; i < times; i += 1) {
promises.push(session.triggerEvent(templateToTrigger.triggers[0].identifier, session.subscriberId));
promises.push(
novuClient.trigger({
name: templateToTrigger.triggers[0].identifier,
to: { subscriberId: session.subscriberId },
})
);
}

await Promise.all(promises);
Expand Down
13 changes: 10 additions & 3 deletions apps/api/src/app/inbox/e2e/get-notifications.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,21 @@ import {
SystemAvatarIconEnum,
TemplateVariableTypeEnum,
} from '@novu/shared';
import { Novu } from '@novu/api';
import { mapToDto } from '../utils/notification-mapper';
import { initNovuClassSdk } from '../../shared/helpers/e2e/sdk/e2e-sdk.helper';

describe('Get Notifications - /inbox/notifications (GET)', async () => {
let session: UserSession;
let template: NotificationTemplateEntity;
let subscriber: SubscriberEntity | null;
const messageRepository = new MessageRepository();
const subscriberRepository = new SubscriberRepository();

let novuClient: Novu;
beforeEach(async () => {
session = new UserSession();
await session.initialize();

novuClient = initNovuClassSdk(session);
subscriber = await subscriberRepository.findBySubscriberId(session.environment._id, session.subscriberId);
template = await session.createTemplate({
noFeedId: true,
Expand Down Expand Up @@ -92,7 +94,12 @@ describe('Get Notifications - /inbox/notifications (GET)', async () => {
const triggerEvent = async (templateToTrigger: NotificationTemplateEntity, times = 1) => {
const promises: Array<Promise<unknown>> = [];
for (let i = 0; i < times; i += 1) {
promises.push(session.triggerEvent(templateToTrigger.triggers[0].identifier, session.subscriberId));
promises.push(
novuClient.trigger({
name: templateToTrigger.triggers[0].identifier,
to: { subscriberId: session.subscriberId },
})
);
}

await Promise.all(promises);
Expand Down
13 changes: 10 additions & 3 deletions apps/api/src/app/inbox/e2e/mark-notification-as.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ import {
TemplateVariableTypeEnum,
} from '@novu/shared';

import { Novu } from '@novu/api';
import { mapToDto } from '../utils/notification-mapper';
import { initNovuClassSdk } from '../../shared/helpers/e2e/sdk/e2e-sdk.helper';

describe('Mark Notification As - /inbox/notifications/:id/{read,unread,archive,unarchive} (PATCH)', async () => {
let session: UserSession;
Expand All @@ -25,7 +27,7 @@ describe('Mark Notification As - /inbox/notifications/:id/{read,unread,archive,u
let message: MessageEntity;
const messageRepository = new MessageRepository();
const subscriberRepository = new SubscriberRepository();

let novuClient: Novu;
const updateNotification = async ({
id,
status,
Expand All @@ -42,7 +44,12 @@ describe('Mark Notification As - /inbox/notifications/:id/{read,unread,archive,u
const triggerEvent = async (templateToTrigger: NotificationTemplateEntity, times = 1) => {
const promises: Array<Promise<unknown>> = [];
for (let i = 0; i < times; i += 1) {
promises.push(session.triggerEvent(templateToTrigger.triggers[0].identifier, session.subscriberId));
promises.push(
novuClient.trigger({
name: templateToTrigger.triggers[0].identifier,
to: { subscriberId: session.subscriberId },
})
);
}

await Promise.all(promises);
Expand All @@ -65,7 +72,7 @@ describe('Mark Notification As - /inbox/notifications/:id/{read,unread,archive,u
beforeEach(async () => {
session = new UserSession();
await session.initialize();

novuClient = initNovuClassSdk(session);
subscriber = await subscriberRepository.findBySubscriberId(session.environment._id, session.subscriberId);
template = await session.createTemplate({
noFeedId: true,
Expand Down
21 changes: 14 additions & 7 deletions apps/api/src/app/inbox/e2e/update-all-notifications.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,23 @@ import { expect } from 'chai';
import { UserSession } from '@novu/testing';
import { MessageRepository, NotificationTemplateEntity, SubscriberEntity, SubscriberRepository } from '@novu/dal';
import {
StepTypeEnum,
ChannelCTATypeEnum,
TemplateVariableTypeEnum,
ActorTypeEnum,
SystemAvatarIconEnum,
ButtonTypeEnum,
ChannelCTATypeEnum,
StepTypeEnum,
SystemAvatarIconEnum,
TemplateVariableTypeEnum,
} from '@novu/shared';
import { Novu } from '@novu/api';
import { initNovuClassSdk } from '../../shared/helpers/e2e/sdk/e2e-sdk.helper';

describe('Update All Notifications - /inbox/notifications/{read,archive,read-archive} (POST)', async () => {
let session: UserSession;
let template: NotificationTemplateEntity;
let subscriber: SubscriberEntity | null;
const messageRepository = new MessageRepository();
const subscriberRepository = new SubscriberRepository();

let novuClient: Novu;
const updateAllNotifications = async ({
action,
tags,
Expand All @@ -33,7 +35,12 @@ describe('Update All Notifications - /inbox/notifications/{read,archive,read-arc
const triggerEvent = async (templateToTrigger: NotificationTemplateEntity, times = 1) => {
const promises: Array<Promise<unknown>> = [];
for (let i = 0; i < times; i += 1) {
promises.push(session.triggerEvent(templateToTrigger.triggers[0].identifier, session.subscriberId));
promises.push(
novuClient.trigger({
name: templateToTrigger.triggers[0].identifier,
to: { subscriberId: session.subscriberId },
})
);
}

await Promise.all(promises);
Expand All @@ -56,7 +63,7 @@ describe('Update All Notifications - /inbox/notifications/{read,archive,read-arc
beforeEach(async () => {
session = new UserSession();
await session.initialize();

novuClient = initNovuClassSdk(session);
subscriber = await subscriberRepository.findBySubscriberId(session.environment._id, session.subscriberId);
template = await session.createTemplate({
noFeedId: true,
Expand Down
13 changes: 10 additions & 3 deletions apps/api/src/app/inbox/e2e/update-notification-action.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ import {
SystemAvatarIconEnum,
TemplateVariableTypeEnum,
} from '@novu/shared';
import { Novu } from '@novu/api';
import { mapToDto } from '../utils/notification-mapper';
import { initNovuClassSdk } from '../../shared/helpers/e2e/sdk/e2e-sdk.helper';

describe('Update Notification Action - /inbox/notifications/:id/{complete/revert} (PATCH)', async () => {
let session: UserSession;
Expand All @@ -24,7 +26,7 @@ describe('Update Notification Action - /inbox/notifications/:id/{complete/revert
let message: MessageEntity;
const messageRepository = new MessageRepository();
const subscriberRepository = new SubscriberRepository();

let novuClient: Novu;
const updateNotificationAction = async ({
id,
action,
Expand All @@ -43,7 +45,12 @@ describe('Update Notification Action - /inbox/notifications/:id/{complete/revert
const triggerEvent = async (templateToTrigger: NotificationTemplateEntity, times = 1) => {
const promises: Array<Promise<unknown>> = [];
for (let i = 0; i < times; i += 1) {
promises.push(session.triggerEvent(templateToTrigger.triggers[0].identifier, session.subscriberId));
promises.push(
novuClient.trigger({
name: templateToTrigger.triggers[0].identifier,
to: { subscriberId: session.subscriberId },
})
);
}

await Promise.all(promises);
Expand All @@ -66,7 +73,7 @@ describe('Update Notification Action - /inbox/notifications/:id/{complete/revert
beforeEach(async () => {
session = new UserSession();
await session.initialize();

novuClient = initNovuClassSdk(session);
subscriber = await subscriberRepository.findBySubscriberId(session.environment._id, session.subscriberId);
template = await session.createTemplate({
noFeedId: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { Type } from 'class-transformer';
import { ChannelTypeEnum, ICreateIntegrationBodyDto } from '@novu/shared';

import { CredentialsDto } from './credentials.dto';
import { StepFilter } from '../../shared/dtos/step-filter';
import { StepFilterDto } from '../../shared/dtos/step-filter-dto';

export class CreateIntegrationRequestDto implements ICreateIntegrationBodyDto {
@ApiPropertyOptional({ type: String, description: 'The name of the integration' })
Expand Down Expand Up @@ -67,11 +67,11 @@ export class CreateIntegrationRequestDto implements ICreateIntegrationBodyDto {
check?: boolean;

@ApiPropertyOptional({
type: [StepFilter],
type: [StepFilterDto],
description: 'Conditions for the integration',
})
@IsArray()
@IsOptional()
@ValidateNested({ each: true })
conditions?: StepFilter[];
conditions?: StepFilterDto[];
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { ChannelTypeEnum } from '@novu/shared';
import { StepFilter } from '../../shared/dtos/step-filter';
import { StepFilterDto } from '../../shared/dtos/step-filter-dto';
import { CredentialsDto } from './credentials.dto';

export class IntegrationResponseDto {
Expand Down Expand Up @@ -92,7 +92,7 @@ export class IntegrationResponseDto {
@ApiPropertyOptional({
description:
'An array of conditions associated with the integration that may influence its behavior or processing logic.',
type: [StepFilter],
type: [StepFilterDto],
})
conditions?: StepFilter[];
conditions?: StepFilterDto[];
}
6 changes: 3 additions & 3 deletions apps/api/src/app/integrations/dtos/update-integration.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { IUpdateIntegrationBodyDto } from '@novu/shared';
import { IsArray, IsBoolean, IsMongoId, IsOptional, IsString, ValidateNested } from 'class-validator';
import { Type } from 'class-transformer';
import { CredentialsDto } from './credentials.dto';
import { StepFilter } from '../../shared/dtos/step-filter';
import { StepFilterDto } from '../../shared/dtos/step-filter-dto';

export class UpdateIntegrationRequestDto implements IUpdateIntegrationBodyDto {
@ApiPropertyOptional({ type: String })
Expand Down Expand Up @@ -51,10 +51,10 @@ export class UpdateIntegrationRequestDto implements IUpdateIntegrationBodyDto {
check?: boolean;

@ApiPropertyOptional({
type: [StepFilter],
type: [StepFilterDto],
})
@IsArray()
@IsOptional()
@ValidateNested({ each: true })
conditions?: StepFilter[];
conditions?: StepFilterDto[];
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ChannelTypeEnum } from '@novu/shared';
import { SubscribersService, UserSession } from '@novu/testing';
import { expect } from 'chai';
import { Novu } from '@novu/api';
import { initNovuClassSdk } from '../../shared/helpers/e2e/sdk/e2e-sdk.helper';
import { expectSdkExceptionGeneric, initNovuClassSdk } from '../../shared/helpers/e2e/sdk/e2e-sdk.helper';

describe('Delete Messages By TransactionId - /messages/?transactionId= (DELETE)', function () {
let session: UserSession;
Expand All @@ -23,10 +23,9 @@ describe('Delete Messages By TransactionId - /messages/?transactionId= (DELETE)'
});

it('should fail to delete non existing message', async function () {
const response = await session.testAgent.delete(`/v1/messages/transaction/abc-1234`);

expect(response.statusCode).to.equal(404);
expect(response.body.error).to.equal('Not Found');
const { error } = await expectSdkExceptionGeneric(() => novuClient.messages.deleteByTransactionId('abc-1234'));
expect(error?.statusCode).to.equal(404);
expect(error?.ctx?.error, JSON.stringify(error)).to.equal('Not Found');
});

it('should delete messages by transactionId', async function () {
Expand Down
26 changes: 20 additions & 6 deletions apps/api/src/app/notifications/dtos/activities-request.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,57 +4,71 @@ import { IsOptional } from 'class-validator';

export class ActivitiesRequestDto {
@ApiPropertyOptional({
enum: ChannelTypeEnum,
enum: [...Object.values(ChannelTypeEnum)],
enumName: 'ChannelTypeEnum',
isArray: true,
description: 'Array of channel types',
})
@IsOptional()
channels?: ChannelTypeEnum[] | ChannelTypeEnum;

@ApiPropertyOptional({
type: String,
isArray: true,
description: 'Array of template IDs or a single template ID',
})
@IsOptional()
templates?: string[] | string;

@ApiPropertyOptional({
type: String,
isArray: true,
description: 'Array of email addresses or a single email address',
})
@IsOptional()
emails?: string | string[];

@ApiPropertyOptional({
type: String,
deprecated: true,
description: 'Search term (deprecated)',
})
@IsOptional()
search?: string;

@ApiPropertyOptional({
type: String,
isArray: true,
description: 'Array of subscriber IDs or a single subscriber ID',
})
@IsOptional()
subscriberIds?: string | string[];

@ApiPropertyOptional({
type: Number,
required: false,
default: 0,
description: 'Page number for pagination',
})
page?: number = 0;
@IsOptional()
page?: number;

@ApiPropertyOptional({
type: String,
required: false,
description: 'Transaction ID for filtering',
})
@IsOptional()
transactionId?: string;

@ApiPropertyOptional({
type: String,
required: false,
description: 'Date filter for records after this timestamp',
})
@IsOptional()
after?: string;

@ApiPropertyOptional({
type: String,
required: false,
description: 'Date filter for records before this timestamp',
})
@IsOptional()
before?: string;
Expand Down
Loading

0 comments on commit 59c6011

Please sign in to comment.