/
githubmirror
/
novu
Обзор
Документация
Войти
/
githubmirror
/
novu
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
next
libs/application-generic/src/commands/base.command.spec.ts
61 строка
2 KB
Adam Chmara
chore(root): apply biome formatter & linter fixes NV-6436 (#8838)
31 июл 2025, 14:59
Не верифицирован
31 июл 2025, 14:59
855fb8f
Код
Авторство
О чём код?
import { BadRequestException } from '@nestjs/common'; import * as Sentry from '@sentry/node'; import { IsDefined, IsEmail, IsNotEmpty } from 'class-validator'; import sinon from 'sinon'; import { BaseCommand } from './base.command'; export class TestCommand extends BaseCommand { @IsDefined() @IsNotEmpty() @IsEmail() email: string; @IsDefined() password: string; } describe('BaseCommand', () => { beforeAll(() => { sinon.stub(Sentry, 'addBreadcrumb'); }); it('should throw BadRequestException with error messages when field values are not valid', async () => { try { TestCommand.create({ email: undefined, password: undefined }); expect(false).toBeTruthy(); } catch (e) { expect((e as BadRequestException).getResponse()).toEqual({ statusCode: 400, error: 'Bad Request', message: [ 'email should not be null or undefined', 'email must be an email', 'email should not be empty', 'password should not be null or undefined', ], }); } }); it('should throw BadRequestException with error message when only one field is not valid', async () => { try { TestCommand.create({ email: 'test@test.com', password: undefined }); expect(false).toBeTruthy(); } catch (e) { expect((e as BadRequestException).getResponse()).toEqual({ statusCode: 400, error: 'Bad Request', message: ['password should not be null or undefined'], }); } }); it('should return object of type that extends the base', async () => { const obj = { email: 'test@test.com', password: 'P@ssw0rd' }; const res = TestCommand.create(obj); expect(res instanceof TestCommand).toBeTruthy(); expect(res).toEqual(obj); }); });