Skip to content

Commit

Permalink
Merge branch 'next' into nv-4958-polishapi-parses-some-of-the-data-as…
Browse files Browse the repository at this point in the history
…-object-object
  • Loading branch information
djabarovgeorge authored Dec 12, 2024
2 parents 2d5d785 + bddd3f4 commit 96b03a2
Show file tree
Hide file tree
Showing 84 changed files with 1,062 additions and 537 deletions.
2 changes: 1 addition & 1 deletion apps/api/src/app/auth/usecases/login/login.command.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { IsDefined, IsEmail, IsNotEmpty } from 'class-validator';
import { BaseCommand } from '../../../shared/commands/base.command';
import { BaseCommand } from '@novu/application-generic';

export class LoginCommand extends BaseCommand {
@IsDefined()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { IsDefined, IsEmail, IsEnum, IsOptional } from 'class-validator';
import { PasswordResetFlowEnum } from '@novu/shared';
import { BaseCommand } from '../../../shared/commands/base.command';
import { BaseCommand } from '@novu/application-generic';

export class PasswordResetRequestCommand extends BaseCommand {
@IsEmail()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { IsDefined, IsString, IsUUID, MinLength } from 'class-validator';
import { BaseCommand } from '../../../shared/commands/base.command';
import { BaseCommand } from '@novu/application-generic';

export class PasswordResetCommand extends BaseCommand {
@IsString()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { IsBoolean, IsDefined, IsEmail, IsEnum, IsNotEmpty, IsOptional, IsString, MinLength } from 'class-validator';

import { JobTitleEnum, ProductUseCases, SignUpOriginEnum } from '@novu/shared';

import { BaseCommand } from '../../../shared/commands/base.command';
import { BaseCommand } from '@novu/application-generic';

export class UserRegisterCommand extends BaseCommand {
@IsDefined()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { IsNotEmpty, IsOptional } from 'class-validator';
import { BaseCommand } from '../../../shared/commands/base.command';
import { BaseCommand } from '@novu/application-generic';

export class GetMyEnvironmentsCommand extends BaseCommand {
@IsNotEmpty()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class DelayOutputRendererUsecase {
const delayTimeControlType: DelayTimeControlType = DelayTimeControlZodSchema.parse(renderCommand.controlValues);

return {
amount: delayTimeControlType.amount,
amount: delayTimeControlType.amount as number,
type: delayTimeControlType.type,
unit: delayTimeControlType.unit,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class DigestOutputRendererUsecase {
parse.lookBackWindow.unit
) {
return {
amount: parse.amount,
amount: parse.amount as number,
unit: parse.unit,
digestKey: parse.digestKey,
lookBackWindow: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { IsDefined } from 'class-validator';
import { NotificationTemplateEntity } from '@novu/dal';
import { BaseCommand } from '../../../shared/commands/base.command';
import { BaseCommand } from '@novu/application-generic';

export class VerifyPayloadCommand extends BaseCommand {
@IsDefined()
Expand Down
13 changes: 6 additions & 7 deletions apps/api/src/app/inbox/e2e/mark-notification-as.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import {
SubscriberRepository,
} from '@novu/dal';
import {
StepTypeEnum,
ChannelCTATypeEnum,
TemplateVariableTypeEnum,
ActorTypeEnum,
SystemAvatarIconEnum,
ButtonTypeEnum,
ChannelCTATypeEnum,
StepTypeEnum,
SystemAvatarIconEnum,
TemplateVariableTypeEnum,
} from '@novu/shared';

import { mapToDto } from '../utils/notification-mapper';
Expand Down Expand Up @@ -111,9 +111,8 @@ describe('Mark Notification As - /inbox/notifications/:id/{read,unread,archive,u
it('should throw bad request error when the notification id is not mongo id', async function () {
const id = 'fake';
const { body, status } = await updateNotification({ id, status: 'read' });

expect(status).to.equal(400);
expect(body.message[0]).to.equal(`notificationId must be a mongodb id`);
expect(body.statusCode).to.equal(400);
expect(body.cause.notificationId.messages[0]).to.equal(`notificationId must be a mongodb id`);
});

it("should throw not found error when the message doesn't exist", async function () {
Expand Down
12 changes: 6 additions & 6 deletions apps/api/src/app/inbox/e2e/update-notification-action.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@ import {
SubscriberRepository,
} from '@novu/dal';
import {
StepTypeEnum,
ChannelCTATypeEnum,
TemplateVariableTypeEnum,
ActorTypeEnum,
SystemAvatarIconEnum,
ButtonTypeEnum,
ChannelCTATypeEnum,
StepTypeEnum,
SystemAvatarIconEnum,
TemplateVariableTypeEnum,
} from '@novu/shared';

import { mapToDto } from '../utils/notification-mapper';

describe('Update Notification Action - /inbox/notifications/:id/{complete/revert} (PATCH)', async () => {
Expand Down Expand Up @@ -119,7 +118,8 @@ describe('Update Notification Action - /inbox/notifications/:id/{complete/revert
});

expect(status).to.equal(400);
expect(body.message[0]).to.equal(`notificationId must be a mongodb id`);
expect(body.statusCode).to.equal(400);
expect(body.cause.notificationId.messages[0]).to.equal(`notificationId must be a mongodb id`);
});

it("should throw not found error when the message doesn't exist", async function () {
Expand Down
5 changes: 2 additions & 3 deletions apps/api/src/app/inbox/e2e/update-preferences.e2e.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { EmailBlockTypeEnum, PreferenceLevelEnum, StepTypeEnum } from '@novu/shared';
import { UserSession } from '@novu/testing';
import { expect } from 'chai';
import e from 'express';

describe('Update global preferences - /inbox/preferences (PATCH)', function () {
let session: UserSession;
Expand Down Expand Up @@ -129,8 +128,8 @@ describe('Update workflow preferences - /inbox/preferences/:workflowId (PATCH)',
chat: true,
})
.set('Authorization', `Bearer ${session.subscriberToken}`);

expect(response.body.message[0]).to.equal(`workflowId must be a mongodb id`);
expect(response.body.statusCode).to.equal(400);
expect(response.body.cause.workflowId.messages[0]).to.equal(`workflowId must be a mongodb id`);
expect(response.status).to.equal(400);
});

Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/app/inbox/usecases/session/session.command.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { IsDefined, IsOptional, IsString } from 'class-validator';
import { BaseCommand } from '../../../shared/commands/base.command';
import { BaseCommand } from '@novu/application-generic';

export class SessionCommand extends BaseCommand {
@IsDefined()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ describe('Set Integration As Primary - /integrations/:integrationId/set-primary
const fakeIntegrationId = 'fakeIntegrationId';

const { body } = await session.testAgent.post(`/v1/integrations/${fakeIntegrationId}/set-primary`).send({});

expect(body.statusCode).to.equal(400);
expect(body.message[0]).to.equal(`integrationId must be a mongodb id`);
expect(body.cause.integrationId.messages[0]).to.equal(`integrationId must be a mongodb id`);
});

it('when integration does not exist should throw not found exception', async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { IsNotEmpty } from 'class-validator';
import { BaseCommand } from '../../../shared/commands/base.command';
import { BaseCommand } from '@novu/application-generic';

export class GetInviteCommand extends BaseCommand {
@IsNotEmpty()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { IsObject, IsString } from 'class-validator';
import { SubscriberEntity } from '@novu/dal';
import { BaseCommand } from '../../../shared/commands/base.command';
import { BaseCommand } from '@novu/application-generic';

export class InviteNudgeWebhookCommand extends BaseCommand {
@IsString()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { IsDefined, IsNumber, IsString } from 'class-validator';
import { BaseCommand } from '../../../shared/commands/base.command';
import { BaseCommand } from '@novu/application-generic';

export class EvaluateTokenBucketRateLimitCommand extends BaseCommand {
@IsDefined()
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/app/shared/commands/authenticated.command.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { IsNotEmpty } from 'class-validator';
import { BaseCommand } from './base.command';
import { BaseCommand } from '@novu/application-generic';

export abstract class AuthenticatedCommand extends BaseCommand {
@IsNotEmpty()
Expand Down
61 changes: 0 additions & 61 deletions apps/api/src/app/shared/commands/base.command.spec.ts

This file was deleted.

34 changes: 0 additions & 34 deletions apps/api/src/app/shared/commands/base.command.ts

This file was deleted.

4 changes: 1 addition & 3 deletions apps/api/src/app/shared/commands/project.command.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { BaseCommand } from '@novu/application-generic';
import { IsNotEmpty } from 'class-validator';
import { BaseCommand } from './base.command';

export { BaseCommand };

export abstract class EnvironmentCommand extends BaseCommand {
@IsNotEmpty()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
import { BaseCommand } from '@novu/application-generic';
// noinspection ExceptionCaughtLocallyJS

import { BaseCommand, CommandValidationException } from '@novu/application-generic';
import { expect } from 'chai';
import { IsNotEmpty } from './chat-oauth-callback.command';

function assertCommandValidationError(e: CommandValidationException, fieldName: string, fieldMsg: string) {
if (!(e instanceof CommandValidationException)) {
throw new Error(e);
}
if (!e.constraintsViolated) {
throw e;
}
expect(e.constraintsViolated[fieldName].messages[0]).to.equal(fieldMsg);
}

describe('@IsNotEmpty() validator', function () {
it('should create command with string name', async function () {
const validateNameCommand = IsNotEmptyNameCommand.create({ name: 'mike' });
Expand All @@ -13,9 +25,10 @@ describe('@IsNotEmpty() validator', function () {
const noValidation = NameCommand.create({ name: 'null' } as any);

try {
const validateNameCommand = IsNotEmptyNameCommand.create({ name: 'null' } as any);
IsNotEmptyNameCommand.create({ name: 'null' } as any);
throw new Error('should not have passed validation');
} catch (e) {
expect(e.response.message[0]).to.equal('name should not be null');
assertCommandValidationError(e, 'name', 'name should not be null');
}
});

Expand All @@ -24,28 +37,31 @@ describe('@IsNotEmpty() validator', function () {

try {
const validateNameCommand = IsNotEmptyNameCommand.create({ name: undefined } as any);
throw new Error('should not have passed validation');
} catch (e) {
expect(e.response.message[0]).to.equal('name should not be undefined');
assertCommandValidationError(e, 'name', 'name should not be undefined');
}
});

it('should throw exception on undefined null', async function () {
const noValidation = NameCommand.create({ name: 'undefined' } as any);

try {
const validateNameCommand = IsNotEmptyNameCommand.create({ name: 'undefined' } as any);
IsNotEmptyNameCommand.create({ name: 'undefined' } as any);
throw new Error('should not have passed validation');
} catch (e) {
expect(e.response.message[0]).to.equal('name should not be undefined');
assertCommandValidationError(e, 'name', 'name should not be undefined');
}
});

it('should throw exception on empty string', async function () {
const noValidation = NameCommand.create({ name: '' });

try {
const validateNameCommand = IsNotEmptyNameCommand.create({ name: '' });
IsNotEmptyNameCommand.create({ name: '' });
throw new Error('should not have passed validation');
} catch (e) {
expect(e.response.message[0]).to.equal('name should not be empty string');
assertCommandValidationError(e, 'name', 'name should not be empty string');
}
});
});
Expand Down
Loading

0 comments on commit 96b03a2

Please sign in to comment.