Skip to content

Commit

Permalink
feat(api): test changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
tatarco committed Dec 17, 2024
1 parent 96bd1a1 commit 9f08c70
Show file tree
Hide file tree
Showing 40 changed files with 951 additions and 735 deletions.
4 changes: 2 additions & 2 deletions apps/api/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@novu/api",
"name": "@novu/api-service",
"version": "2.1.1",
"description": "description",
"author": "",
Expand Down Expand Up @@ -42,7 +42,7 @@
"@nestjs/swagger": "7.4.0",
"@nestjs/terminus": "10.2.3",
"@nestjs/throttler": "6.2.1",
"@novu/api": "0.0.1-alpha.109",
"@novu/api": "0.0.1-alpha.119",
"@novu/application-generic": "workspace:*",
"@novu/dal": "workspace:*",
"@novu/framework": "workspace:*",
Expand Down
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?.name, 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
119 changes: 78 additions & 41 deletions apps/api/src/app/notifications/dtos/activities-response.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,177 +4,214 @@ import {
ExecutionDetailsStatusEnum,
MessageTemplateDto,
ProvidersIdEnum,
ProvidersIdEnumConst,
StepTypeEnum,
TriggerTypeEnum,
} from '@novu/shared';
import { StepFilter } from '@novu/dal';

export class ActivityNotificationStepResponseDto {
@ApiProperty()
@ApiProperty({ description: 'Unique identifier of the step' })
_id: string;

@ApiProperty()
@ApiProperty({ description: 'Whether the step is active or not' })
active: boolean;

@ApiProperty()
@ApiProperty({ description: 'Filter criteria for the step' })
filters: StepFilter;

@ApiPropertyOptional()
@ApiPropertyOptional({ description: 'Optional template for the step' })
template?: MessageTemplateDto;
}

export class ActivityNotificationExecutionDetailResponseDto {
@ApiProperty()
@ApiProperty({ description: 'Unique identifier of the execution detail' })
_id: string;

@ApiProperty()
@ApiProperty({ description: 'Unique identifier of the job' })
_jobId: string;

@ApiProperty({
enum: ExecutionDetailsStatusEnum,
description: 'Status of the execution detail',
})
status: ExecutionDetailsStatusEnum;

@ApiProperty()
@ApiProperty({ description: 'Detailed information about the execution' })
detail: string;

@ApiProperty()
@ApiProperty({ description: 'Whether the execution is a retry or not' })
isRetry: boolean;

@ApiProperty()
@ApiProperty({ description: 'Whether the execution is a test or not' })
isTest: boolean;

@ApiProperty()
@ApiProperty({
enum: [...Object.values(ProvidersIdEnumConst)],
enumName: 'ProvidersIdEnum',
description: 'Provider ID of the execution',
})
providerId: ProvidersIdEnum;

@ApiPropertyOptional()
@ApiPropertyOptional({ description: 'Raw data of the execution' })
raw?: string;

@ApiProperty({
enum: ExecutionDetailsSourceEnum,
description: 'Source of the execution detail',
})
source: ExecutionDetailsSourceEnum;
}

export class ActivityNotificationJobResponseDto {
@ApiProperty()
@ApiProperty({ description: 'Unique identifier of the job' })
_id: string;

@ApiProperty()
@ApiProperty({ description: 'Type of the job' })
type: string;

@ApiPropertyOptional()
@ApiPropertyOptional({ description: 'Optional digest for the job' })
digest?: Record<string, unknown>;

@ApiProperty()
@ApiProperty({
description: 'Execution details of the job',
type: [ActivityNotificationExecutionDetailResponseDto],
})
executionDetails: ActivityNotificationExecutionDetailResponseDto[];

@ApiProperty()
@ApiProperty({
description: 'Step details of the job',
type: ActivityNotificationStepResponseDto,
})
step: ActivityNotificationStepResponseDto;

@ApiPropertyOptional()
@ApiPropertyOptional({ description: 'Optional payload for the job' })
payload?: Record<string, unknown>;

@ApiProperty()
@ApiProperty({
enum: [...Object.values(ProvidersIdEnumConst)],
enumName: 'ProvidersIdEnum',
description: 'Provider ID of the job',
})
providerId: ProvidersIdEnum;

@ApiProperty()
@ApiProperty({ description: 'Status of the job' })
status: string;
}

export class ActivityNotificationSubscriberResponseDto {
@ApiPropertyOptional()
@ApiPropertyOptional({ description: 'First name of the subscriber' })
firstName?: string;

@ApiProperty()
@ApiProperty({ description: 'Unique identifier of the subscriber' })
_id: string;

@ApiPropertyOptional()
@ApiPropertyOptional({ description: 'Last name of the subscriber' })
lastName?: string;

@ApiPropertyOptional()
@ApiPropertyOptional({ description: 'Email of the subscriber' })
email?: string;

@ApiPropertyOptional()
@ApiPropertyOptional({ description: 'Phone number of the subscriber' })
phone?: string;
}

export class NotificationTriggerVariable {
@ApiProperty({ description: 'Name of the variable' })
name: string;
}

export class NotificationTrigger {
@ApiProperty({
enum: TriggerTypeEnum,
description: 'Type of the trigger',
})
type: TriggerTypeEnum;

@ApiProperty()
@ApiProperty({ description: 'Identifier of the trigger' })
identifier: string;

@ApiProperty({
description: 'Variables of the trigger',
type: [NotificationTriggerVariable],
})
variables: NotificationTriggerVariable[];

@ApiProperty({
@ApiPropertyOptional({
description: 'Subscriber variables of the trigger',
type: [NotificationTriggerVariable],
})
subscriberVariables?: NotificationTriggerVariable[];
}

class ActivityNotificationTemplateResponseDto {
@ApiPropertyOptional()
@ApiPropertyOptional({ description: 'Unique identifier of the template' })
_id?: string;

@ApiProperty()
@ApiProperty({ description: 'Name of the template' })
name: string;

@ApiProperty()
@ApiProperty({
description: 'Triggers of the template',
type: [NotificationTrigger],
})
triggers: NotificationTrigger[];
}

export class ActivityNotificationResponseDto {
@ApiPropertyOptional()
@ApiPropertyOptional({ description: 'Unique identifier of the notification' })
_id?: string;

@ApiProperty()
@ApiProperty({ description: 'Environment ID of the notification' })
_environmentId: string;

@ApiProperty()
@ApiProperty({ description: 'Organization ID of the notification' })
_organizationId: string;

@ApiProperty()
@ApiProperty({ description: 'Transaction ID of the notification' })
transactionId: string;

@ApiPropertyOptional()
@ApiPropertyOptional({ description: 'Creation time of the notification' })
createdAt?: string;

@ApiPropertyOptional({
description: 'Channels of the notification',
enum: StepTypeEnum,
})
channels?: StepTypeEnum[];

@ApiPropertyOptional()
@ApiPropertyOptional({
description: 'Subscriber of the notification',
type: ActivityNotificationSubscriberResponseDto,
})
subscriber?: ActivityNotificationSubscriberResponseDto;

@ApiPropertyOptional()
@ApiPropertyOptional({
description: 'Template of the notification',
type: ActivityNotificationTemplateResponseDto,
})
template?: ActivityNotificationTemplateResponseDto;

@ApiPropertyOptional()
@ApiPropertyOptional({
description: 'Jobs of the notification',
type: [ActivityNotificationJobResponseDto],
})
jobs?: ActivityNotificationJobResponseDto[];
}

export class ActivitiesResponseDto {
@ApiProperty()
@ApiProperty({ description: 'Whether there are more activities' })
hasMore: boolean;

@ApiProperty({ type: [ActivityNotificationResponseDto], description: 'Array of Activity notifications' })
@ApiProperty({
description: 'Array of activity notifications',
type: [ActivityNotificationResponseDto],
})
data: ActivityNotificationResponseDto[];

@ApiProperty()
@ApiProperty({ description: 'Page size of the activities' })
pageSize: number;

@ApiProperty()
@ApiProperty({ description: 'Current page of the activities' })
page: number;
}
Loading

0 comments on commit 9f08c70

Please sign in to comment.