From 1b3db6e47c199f94ee6b16e20774806242e5ffb9 Mon Sep 17 00:00:00 2001 From: Jaime Leonardo Suncin Cruz Date: Sat, 3 Sep 2022 22:49:24 -0600 Subject: [PATCH] fix: amend typescript errors --- src/auth/controllers/auth.controller.spec.ts | 4 +++- src/auth/dto/login-user.dto.spec.ts | 2 ++ src/auth/dto/register-user.dto.spec.ts | 2 ++ src/auth/dto/update-user.dto.spec.ts | 2 ++ .../current-user.interceptor.spec.ts | 4 ++-- src/auth/interceptors/token.interceptor.spec.ts | 4 +++- src/auth/pipes/strip-id.pipe.spec.ts | 2 +- src/auth/pipes/swap-password.pipe.spec.ts | 2 +- src/auth/pipes/swap-password.pipe.ts | 6 ++++-- src/auth/services/authentication.service.spec.ts | 2 ++ src/auth/services/authentication.service.ts | 6 +++--- src/auth/strategies/jwt.strategy.ts | 6 +++--- .../is-already-register.validator.spec.ts | 2 ++ .../validators/is-already-register.validator.ts | 2 +- src/auth/validators/is-not-the-same.spec.ts | 2 +- src/auth/validators/is-not-the-same.ts | 2 +- .../validators/is-not-vulnerable.validator.ts | 2 +- .../validate-credential.validator.spec.ts | 2 ++ .../validators/validate-credential.validator.ts | 2 +- src/blog/controllers/article.controller.spec.ts | 6 ++++-- src/blog/controllers/comment.controller.spec.ts | 4 +++- src/blog/controllers/comment.controller.ts | 2 +- src/blog/dto/create-comment.spec.ts | 2 ++ src/blog/fixtures/article.fixture.ts | 2 +- src/blog/guards/is-author.guard.spec.ts | 2 ++ src/blog/guards/is-author.guard.ts | 4 +++- .../interceptors/set-article.interceptor.spec.ts | 2 +- .../interceptors/set-author.interceptor.spec.ts | 2 +- src/blog/interceptors/set-author.interceptor.ts | 2 +- src/blog/pipes/article.pipe.spec.ts | 2 ++ src/blog/seeders/article.seeder.ts | 4 ++-- src/blog/seeders/comment.seeder.ts | 16 ++++++++-------- src/blog/services/article.service.spec.ts | 4 +++- src/blog/services/comment.service.spec.ts | 6 ++++-- src/blog/services/comment.service.ts | 2 +- .../validators/article-exist.validator.spec.ts | 2 ++ src/blog/validators/article-exist.validator.ts | 2 +- src/common/test-helpers.ts | 3 ++- src/data-source.ts | 2 +- src/migrations/1637703183543-create-user.ts | 2 +- .../1651517018946-create-article-comment.ts | 2 +- 41 files changed, 84 insertions(+), 47 deletions(-) diff --git a/src/auth/controllers/auth.controller.spec.ts b/src/auth/controllers/auth.controller.spec.ts index 1ceac281..3bd84b58 100644 --- a/src/auth/controllers/auth.controller.spec.ts +++ b/src/auth/controllers/auth.controller.spec.ts @@ -3,7 +3,7 @@ import { Test } from '@nestjs/testing'; import { createMock } from 'ts-auto-mock'; import { AuthController } from '@/auth/controllers/auth.controller'; -import { LoginUser } from '@/auth/dto/login-user.dto'; +import type { LoginUser } from '@/auth/dto/login-user.dto'; import type { RegisterUser } from '@/auth/dto/register-user.dto'; import type { UpdateUser } from '@/auth/dto/update-user.dto'; import { User } from '@/auth/entities/user.entity'; @@ -47,6 +47,8 @@ describe('AuthController', () => { ), }); } + + return; }) .compile(); diff --git a/src/auth/dto/login-user.dto.spec.ts b/src/auth/dto/login-user.dto.spec.ts index 369d3997..c78c99eb 100644 --- a/src/auth/dto/login-user.dto.spec.ts +++ b/src/auth/dto/login-user.dto.spec.ts @@ -26,6 +26,8 @@ describe('Login user validations', () => { ), }); } + + return; }) .compile(); diff --git a/src/auth/dto/register-user.dto.spec.ts b/src/auth/dto/register-user.dto.spec.ts index 62ea7678..41671ab5 100644 --- a/src/auth/dto/register-user.dto.spec.ts +++ b/src/auth/dto/register-user.dto.spec.ts @@ -23,6 +23,8 @@ describe('Register user validations', () => { if (token === getRepositoryToken(User)) { return createMock>(); } + + return; }) .compile(); diff --git a/src/auth/dto/update-user.dto.spec.ts b/src/auth/dto/update-user.dto.spec.ts index 8ea2281b..d55338d7 100644 --- a/src/auth/dto/update-user.dto.spec.ts +++ b/src/auth/dto/update-user.dto.spec.ts @@ -26,6 +26,8 @@ describe('Update user validations', () => { if (token === getRepositoryToken(User)) { return createMock>(); } + + return; }) .compile(); diff --git a/src/auth/interceptors/current-user.interceptor.spec.ts b/src/auth/interceptors/current-user.interceptor.spec.ts index 48e7683e..f1126c28 100644 --- a/src/auth/interceptors/current-user.interceptor.spec.ts +++ b/src/auth/interceptors/current-user.interceptor.spec.ts @@ -1,4 +1,4 @@ -import { CallHandler } from '@nestjs/common'; +import type { CallHandler } from '@nestjs/common'; import { ExecutionContextHost } from '@nestjs/core/helpers/execution-context-host'; import { createMocks } from 'node-mocks-http'; import { lastValueFrom, of } from 'rxjs'; @@ -42,8 +42,8 @@ describe('UserInterceptor', () => { it("should not inject the user's id when there is no request's body", async () => { const { req, res } = createMocks({ user, - body: undefined, }); + delete req.body; const context = new ExecutionContextHost([req, res]); const next: CallHandler = { handle: () => of({}), diff --git a/src/auth/interceptors/token.interceptor.spec.ts b/src/auth/interceptors/token.interceptor.spec.ts index feb3d16c..a756f386 100644 --- a/src/auth/interceptors/token.interceptor.spec.ts +++ b/src/auth/interceptors/token.interceptor.spec.ts @@ -6,7 +6,7 @@ import { createMocks } from 'node-mocks-http'; import { lastValueFrom, of } from 'rxjs'; import { createMock } from 'ts-auto-mock'; -import { User } from '@/auth/entities/user.entity'; +import type { User } from '@/auth/entities/user.entity'; import { TokenInterceptor } from '@/auth/interceptors/token.interceptor'; describe('TokenInterceptor', () => { @@ -21,6 +21,8 @@ describe('TokenInterceptor', () => { if (token === JwtService) { return createMock(); } + + return; }) .compile(); diff --git a/src/auth/pipes/strip-id.pipe.spec.ts b/src/auth/pipes/strip-id.pipe.spec.ts index 43ea1b35..ee5efb98 100644 --- a/src/auth/pipes/strip-id.pipe.spec.ts +++ b/src/auth/pipes/strip-id.pipe.spec.ts @@ -1,4 +1,4 @@ -import { ArgumentMetadata } from '@nestjs/common'; +import type { ArgumentMetadata } from '@nestjs/common'; import { StripIdPipe } from '@/auth/pipes/strip-id.pipe'; import { credentials } from '@/common/test-helpers'; diff --git a/src/auth/pipes/swap-password.pipe.spec.ts b/src/auth/pipes/swap-password.pipe.spec.ts index 703e8f9a..a8c55ce4 100644 --- a/src/auth/pipes/swap-password.pipe.spec.ts +++ b/src/auth/pipes/swap-password.pipe.spec.ts @@ -1,4 +1,4 @@ -import { ArgumentMetadata } from '@nestjs/common'; +import type { ArgumentMetadata } from '@nestjs/common'; import { SwapPasswordPipe } from '@/auth/pipes/swap-password.pipe'; import { credentials } from '@/common/test-helpers'; diff --git a/src/auth/pipes/swap-password.pipe.ts b/src/auth/pipes/swap-password.pipe.ts index 15f16187..33d2cde3 100644 --- a/src/auth/pipes/swap-password.pipe.ts +++ b/src/auth/pipes/swap-password.pipe.ts @@ -1,4 +1,5 @@ import { ArgumentMetadata, Injectable, PipeTransform } from '@nestjs/common'; +import invariant from 'tiny-invariant'; import type { UpdateUser } from '@/auth/dto/update-user.dto'; @@ -13,10 +14,11 @@ export class SwapPasswordPipe implements PipeTransform { if (metadata.type !== 'body') return value; if (this.#want2ChangePassword(value)) { + invariant(value.newPassword); value.password = value.newPassword; delete value.newPassword; } else { - delete value.password; + delete value['password']; } return value; @@ -25,6 +27,6 @@ export class SwapPasswordPipe implements PipeTransform { #want2ChangePassword( value: Record, ): value is Writeable { - return typeof value.newPassword === 'string'; + return typeof value['newPassword'] === 'string'; } } diff --git a/src/auth/services/authentication.service.spec.ts b/src/auth/services/authentication.service.spec.ts index 6ac48d20..0f9461ff 100644 --- a/src/auth/services/authentication.service.spec.ts +++ b/src/auth/services/authentication.service.spec.ts @@ -44,6 +44,8 @@ describe('AuthenticationService', () => { merge: jest.fn().mockImplementation(Object.assign), }); } + + return; }) .compile(); diff --git a/src/auth/services/authentication.service.ts b/src/auth/services/authentication.service.ts index f8ff6204..b60f6284 100644 --- a/src/auth/services/authentication.service.ts +++ b/src/auth/services/authentication.service.ts @@ -2,9 +2,9 @@ import { Injectable } from '@nestjs/common'; import { InjectRepository } from '@nestjs/typeorm'; import type { Repository } from 'typeorm'; -import { LoginUser } from '@/auth/dto/login-user.dto'; -import { RegisterUser } from '@/auth/dto/register-user.dto'; -import { UpdateUser } from '@/auth/dto/update-user.dto'; +import type { LoginUser } from '@/auth/dto/login-user.dto'; +import type { RegisterUser } from '@/auth/dto/register-user.dto'; +import type { UpdateUser } from '@/auth/dto/update-user.dto'; import { User } from '@/auth/entities/user.entity'; import type { JwtPayload } from '@/auth/interfaces/jwt-payload.interface'; diff --git a/src/auth/strategies/jwt.strategy.ts b/src/auth/strategies/jwt.strategy.ts index e64b4c2f..0897d817 100644 --- a/src/auth/strategies/jwt.strategy.ts +++ b/src/auth/strategies/jwt.strategy.ts @@ -2,8 +2,8 @@ import { Injectable } from '@nestjs/common'; import { PassportStrategy } from '@nestjs/passport'; import { ExtractJwt, JwtFromRequestFunction, Strategy } from 'passport-jwt'; -import { User } from '@/auth/entities/user.entity'; -import { JwtPayload } from '@/auth/interfaces/jwt-payload.interface'; +import type { User } from '@/auth/entities/user.entity'; +import type { JwtPayload } from '@/auth/interfaces/jwt-payload.interface'; import { AuthenticationService } from '@/auth/services/authentication.service'; declare module 'express' { @@ -16,7 +16,7 @@ declare module 'express' { export const JWT = 'jwt' as const; const extractJwtFromCookie: JwtFromRequestFunction = (request) => { - return request.signedCookies.token; + return request.signedCookies['token']!; }; @Injectable() diff --git a/src/auth/validators/is-already-register.validator.spec.ts b/src/auth/validators/is-already-register.validator.spec.ts index 64024243..99b11968 100644 --- a/src/auth/validators/is-already-register.validator.spec.ts +++ b/src/auth/validators/is-already-register.validator.spec.ts @@ -39,6 +39,8 @@ describe('IsAlreadyRegister', () => { if (token === getRepositoryToken(User)) { return createMock>(); } + + return; }) .compile(); diff --git a/src/auth/validators/is-already-register.validator.ts b/src/auth/validators/is-already-register.validator.ts index d7513f11..42ede2fb 100644 --- a/src/auth/validators/is-already-register.validator.ts +++ b/src/auth/validators/is-already-register.validator.ts @@ -47,7 +47,7 @@ export class IsAlreadyRegisterConstraint } } -export function IsAlreadyRegister(options?: ValidationOptions) { +export function IsAlreadyRegister(options: ValidationOptions = {}) { return function (object: object, propertyName: 'username' | 'email') { registerDecorator({ target: object.constructor, diff --git a/src/auth/validators/is-not-the-same.spec.ts b/src/auth/validators/is-not-the-same.spec.ts index 14d240be..ab81dd45 100644 --- a/src/auth/validators/is-not-the-same.spec.ts +++ b/src/auth/validators/is-not-the-same.spec.ts @@ -29,7 +29,7 @@ describe('IsNotTheSame', () => { const errors = validateSync(dto); expect(errors).toHaveLength(1); - expect(errors[0].constraints).toMatchObject({ + expect(errors[0]!.constraints).toMatchObject({ isNotTheSame: 'password must be different than username', }); }); diff --git a/src/auth/validators/is-not-the-same.ts b/src/auth/validators/is-not-the-same.ts index c1e0ca0c..65249d88 100644 --- a/src/auth/validators/is-not-the-same.ts +++ b/src/auth/validators/is-not-the-same.ts @@ -25,7 +25,7 @@ export class IsNotTheSameConstraint implements ValidatorConstraintInterface { export function IsNotTheSame( property: keyof Type, - validationOptions?: ValidationOptions, + validationOptions: ValidationOptions = {}, ) { return (object: object, propertyName: string) => { registerDecorator({ diff --git a/src/auth/validators/is-not-vulnerable.validator.ts b/src/auth/validators/is-not-vulnerable.validator.ts index 3570a2db..3a38508f 100644 --- a/src/auth/validators/is-not-vulnerable.validator.ts +++ b/src/auth/validators/is-not-vulnerable.validator.ts @@ -35,7 +35,7 @@ class IsNotVulnerableConstraint implements ValidatorConstraintInterface { } } -export function IsNotVulnerable(options?: ValidationOptions) { +export function IsNotVulnerable(options: ValidationOptions = {}) { return function (object: object, propertyName: string) { registerDecorator({ target: object.constructor, diff --git a/src/auth/validators/validate-credential.validator.spec.ts b/src/auth/validators/validate-credential.validator.spec.ts index 31507de9..df6b98a7 100644 --- a/src/auth/validators/validate-credential.validator.spec.ts +++ b/src/auth/validators/validate-credential.validator.spec.ts @@ -55,6 +55,8 @@ describe('ValidateCredential', () => { if (token === getRepositoryToken(User)) { return createMock>(); } + + return; }) .compile(); diff --git a/src/auth/validators/validate-credential.validator.ts b/src/auth/validators/validate-credential.validator.ts index 77df19ad..b9ee7c2b 100644 --- a/src/auth/validators/validate-credential.validator.ts +++ b/src/auth/validators/validate-credential.validator.ts @@ -57,7 +57,7 @@ export class ValidateCredentialConstraint } } -export function ValidateCredential(options?: ValidationOptions) { +export function ValidateCredential(options: ValidationOptions = {}) { return function (object: object, propertyName: 'username' | 'password') { registerDecorator({ target: object.constructor, diff --git a/src/blog/controllers/article.controller.spec.ts b/src/blog/controllers/article.controller.spec.ts index 263887c6..51129721 100644 --- a/src/blog/controllers/article.controller.spec.ts +++ b/src/blog/controllers/article.controller.spec.ts @@ -3,8 +3,8 @@ import { createMock } from 'ts-auto-mock'; import { User } from '@/auth/entities/user.entity'; import { ArticleController } from '@/blog/controllers/article.controller'; -import { CreateArticle } from '@/blog/dto/create-article.dto'; -import { UpdateArticle } from '@/blog/dto/update-article.dto'; +import type { CreateArticle } from '@/blog/dto/create-article.dto'; +import type { UpdateArticle } from '@/blog/dto/update-article.dto'; import { Article } from '@/blog/entities/article.entity'; import { ArticleService } from '@/blog/services/article.service'; @@ -20,6 +20,8 @@ describe('ArticleController', () => { if (token === ArticleService) { return createMock(); } + + return; }) .compile(); diff --git a/src/blog/controllers/comment.controller.spec.ts b/src/blog/controllers/comment.controller.spec.ts index 952fe1a9..addddb1d 100644 --- a/src/blog/controllers/comment.controller.spec.ts +++ b/src/blog/controllers/comment.controller.spec.ts @@ -3,7 +3,7 @@ import { createMock } from 'ts-auto-mock'; import { User } from '@/auth/entities/user.entity'; import { CommentController } from '@/blog/controllers/comment.controller'; -import { CreateComment } from '@/blog/dto/create-comment'; +import type { CreateComment } from '@/blog/dto/create-comment'; import { Article } from '@/blog/entities/article.entity'; import { Comment } from '@/blog/entities/comment.entity'; import { ArticleService } from '@/blog/services/article.service'; @@ -25,6 +25,8 @@ describe('CommentController', () => { if (token === ArticleService) { return createMock(); } + + return; }) .compile(); diff --git a/src/blog/controllers/comment.controller.ts b/src/blog/controllers/comment.controller.ts index f7c958af..3b761054 100644 --- a/src/blog/controllers/comment.controller.ts +++ b/src/blog/controllers/comment.controller.ts @@ -18,7 +18,7 @@ import { JWTAuthGuard } from '@/auth/guards/jwt-auth.guard'; import { IsComment } from '@/blog/decorators/is-entity.decorator'; import { CreateComment } from '@/blog/dto/create-comment'; import type { Article } from '@/blog/entities/article.entity'; -import { Comment } from '@/blog/entities/comment.entity'; +import type { Comment } from '@/blog/entities/comment.entity'; import { IsAuthorGuard } from '@/blog/guards/is-author.guard'; import { SetArticleInterceptor } from '@/blog/interceptors/set-article.interceptor'; import { SetAuthorInterceptor } from '@/blog/interceptors/set-author.interceptor'; diff --git a/src/blog/dto/create-comment.spec.ts b/src/blog/dto/create-comment.spec.ts index a30c3f95..5d9d358a 100644 --- a/src/blog/dto/create-comment.spec.ts +++ b/src/blog/dto/create-comment.spec.ts @@ -23,6 +23,8 @@ describe('CreateComment DTO', () => { ), }); } + + return; }) .compile(); diff --git a/src/blog/fixtures/article.fixture.ts b/src/blog/fixtures/article.fixture.ts index 03c625cd..72c9c1e5 100644 --- a/src/blog/fixtures/article.fixture.ts +++ b/src/blog/fixtures/article.fixture.ts @@ -2,7 +2,7 @@ import { plainToInstance } from 'class-transformer'; import { fluse } from 'fluse'; import { CreateArticle } from '@/blog/dto/create-article.dto'; -import { UpdateArticle } from '@/blog/dto/update-article.dto'; +import type { UpdateArticle } from '@/blog/dto/update-article.dto'; import { fakerPlugin } from '@/common/fluse-plugin-faker'; import { txtgenPlugin } from '@/common/fluse-plugin-txtgen'; diff --git a/src/blog/guards/is-author.guard.spec.ts b/src/blog/guards/is-author.guard.spec.ts index 45ba7c8c..96720682 100644 --- a/src/blog/guards/is-author.guard.spec.ts +++ b/src/blog/guards/is-author.guard.spec.ts @@ -56,6 +56,8 @@ describe('IsAuthorGuard', () => { ), }); } + + return; }), }), }, diff --git a/src/blog/guards/is-author.guard.ts b/src/blog/guards/is-author.guard.ts index 2b61be24..515083a5 100644 --- a/src/blog/guards/is-author.guard.ts +++ b/src/blog/guards/is-author.guard.ts @@ -21,7 +21,9 @@ export class IsAuthorGuard implements CanActivate { ) {} async canActivate(context: ExecutionContext): Promise { - const request = context.switchToHttp().getRequest(); + const request = context + .switchToHttp() + .getRequest>(); const kindOf = this.reflector.get( ENTITY_METADATA_KEY, context.getHandler(), diff --git a/src/blog/interceptors/set-article.interceptor.spec.ts b/src/blog/interceptors/set-article.interceptor.spec.ts index 891c5347..e18cebc7 100644 --- a/src/blog/interceptors/set-article.interceptor.spec.ts +++ b/src/blog/interceptors/set-article.interceptor.spec.ts @@ -1,4 +1,4 @@ -import { CallHandler } from '@nestjs/common'; +import type { CallHandler } from '@nestjs/common'; import { ExecutionContextHost } from '@nestjs/core/helpers/execution-context-host'; import { createMocks } from 'node-mocks-http'; import { lastValueFrom, of } from 'rxjs'; diff --git a/src/blog/interceptors/set-author.interceptor.spec.ts b/src/blog/interceptors/set-author.interceptor.spec.ts index 657ce173..c68deb6d 100644 --- a/src/blog/interceptors/set-author.interceptor.spec.ts +++ b/src/blog/interceptors/set-author.interceptor.spec.ts @@ -1,4 +1,4 @@ -import { CallHandler } from '@nestjs/common'; +import type { CallHandler } from '@nestjs/common'; import { ExecutionContextHost } from '@nestjs/core/helpers/execution-context-host'; import { createMocks } from 'node-mocks-http'; import { lastValueFrom, of } from 'rxjs'; diff --git a/src/blog/interceptors/set-author.interceptor.ts b/src/blog/interceptors/set-author.interceptor.ts index 5b00d21c..aea52cb7 100644 --- a/src/blog/interceptors/set-author.interceptor.ts +++ b/src/blog/interceptors/set-author.interceptor.ts @@ -5,7 +5,7 @@ import { NestInterceptor, } from '@nestjs/common'; import type { Request } from 'express'; -import { Observable } from 'rxjs'; +import type { Observable } from 'rxjs'; import invariant from 'tiny-invariant'; @Injectable() diff --git a/src/blog/pipes/article.pipe.spec.ts b/src/blog/pipes/article.pipe.spec.ts index 5b29ee1d..5a5aee83 100644 --- a/src/blog/pipes/article.pipe.spec.ts +++ b/src/blog/pipes/article.pipe.spec.ts @@ -26,6 +26,8 @@ describe('ArticlePipe', () => { ), }); } + + return; }) .compile(); diff --git a/src/blog/seeders/article.seeder.ts b/src/blog/seeders/article.seeder.ts index 5f3d7efb..124e8a59 100644 --- a/src/blog/seeders/article.seeder.ts +++ b/src/blog/seeders/article.seeder.ts @@ -21,7 +21,7 @@ export class ArticleSeeder implements Seeder { However, cats have begun to rent blueberries over the past few months, specifically for sharks associated with their puppies. Some assert that however, ducks have begun to rent octopus over the past few months, specifically for sharks associated with their snakes. Though we assume the latter, however, birds have begun to rent kumquats over the past few months, specifically for chickens associated with their watermelons.`, - author: users.find((user) => user.username === 'john-doe'), + author: users.find((user) => user.username === 'john-doe')!, }); await articleFactory.save({ id: '31a10506-c334-4841-97a6-144a55bf4ebb', @@ -32,7 +32,7 @@ Though we assume the latter, however, birds have begun to rent kumquats over the Of course, however, plums have begun to rent raspberries over the past few months, specifically for giraffes associated with their lions. This is not to discredit the idea that however, alligators have begun to rent sharks over the past few months, specifically for sheeps associated with their monkeys. However, pomegranates have begun to rent sheeps over the past few months, specifically for apricots associated with their grapes.`, - author: users.find((user) => user.username === 'jane-doe'), + author: users.find((user) => user.username === 'jane-doe')!, }); for (const author of users) { diff --git a/src/blog/seeders/comment.seeder.ts b/src/blog/seeders/comment.seeder.ts index 76d8ad68..fedbebe5 100644 --- a/src/blog/seeders/comment.seeder.ts +++ b/src/blog/seeders/comment.seeder.ts @@ -30,21 +30,21 @@ export class CommentSeeder implements Seeder { await Promise.allSettled([ commentFactory.save({ id: '9395e782-367b-4487-a048-242e37169109', - article: article1, - author: jane, + article: article1!, + author: jane!, }), commentFactory.saveMany(14, { - article: article1, - author: jane, + article: article1!, + author: jane!, }), commentFactory.save({ id: '2cce7079-b434-42fb-85e3-8d1aadd7bb8a', - article: article2, - author: john, + article: article2!, + author: john!, }), commentFactory.saveMany(14, { - article: article2, - author: john, + article: article2!, + author: john!, }), ]); } diff --git a/src/blog/services/article.service.spec.ts b/src/blog/services/article.service.spec.ts index 8b15f35d..bb631617 100644 --- a/src/blog/services/article.service.spec.ts +++ b/src/blog/services/article.service.spec.ts @@ -5,7 +5,7 @@ import { Repository } from 'typeorm'; import { User } from '@/auth/entities/user.entity'; import type { CreateArticle } from '@/blog/dto/create-article.dto'; -import { UpdateArticle } from '@/blog/dto/update-article.dto'; +import type { UpdateArticle } from '@/blog/dto/update-article.dto'; import { Article } from '@/blog/entities/article.entity'; import { ArticleService } from '@/blog/services/article.service'; @@ -37,6 +37,8 @@ describe('ArticleService', () => { return mock; } + + return; }) .compile(); diff --git a/src/blog/services/comment.service.spec.ts b/src/blog/services/comment.service.spec.ts index ac790fb3..b5be50e0 100644 --- a/src/blog/services/comment.service.spec.ts +++ b/src/blog/services/comment.service.spec.ts @@ -1,10 +1,10 @@ import { Test } from '@nestjs/testing'; import { getRepositoryToken } from '@nestjs/typeorm'; import { createMock } from 'ts-auto-mock'; -import { type SelectQueryBuilder,Repository } from 'typeorm'; +import { type SelectQueryBuilder, Repository } from 'typeorm'; import { User } from '@/auth/entities/user.entity'; -import { CreateComment } from '@/blog/dto/create-comment'; +import type { CreateComment } from '@/blog/dto/create-comment'; import { Article } from '@/blog/entities/article.entity'; import { Comment } from '@/blog/entities/comment.entity'; import { CommentService } from '@/blog/services/comment.service'; @@ -36,6 +36,8 @@ describe('CommentService', () => { return mock; } + + return; }) .compile(); diff --git a/src/blog/services/comment.service.ts b/src/blog/services/comment.service.ts index b4faf7b4..506345d1 100644 --- a/src/blog/services/comment.service.ts +++ b/src/blog/services/comment.service.ts @@ -7,7 +7,7 @@ import { } from 'nestjs-typeorm-paginate'; import type { Repository } from 'typeorm'; -import { CreateComment } from '@/blog/dto/create-comment'; +import type { CreateComment } from '@/blog/dto/create-comment'; import { Comment } from '@/blog/entities/comment.entity'; @Injectable() diff --git a/src/blog/validators/article-exist.validator.spec.ts b/src/blog/validators/article-exist.validator.spec.ts index aad24825..631ac2b4 100644 --- a/src/blog/validators/article-exist.validator.spec.ts +++ b/src/blog/validators/article-exist.validator.spec.ts @@ -35,6 +35,8 @@ describe('ArticleExist', () => { ), }); } + + return; }) .compile(); diff --git a/src/blog/validators/article-exist.validator.ts b/src/blog/validators/article-exist.validator.ts index 9c686d22..703334d8 100644 --- a/src/blog/validators/article-exist.validator.ts +++ b/src/blog/validators/article-exist.validator.ts @@ -22,7 +22,7 @@ export class ArticleExistConstraint implements ValidatorConstraintInterface { } } -export function ArticleExist(options?: ValidationOptions) { +export function ArticleExist(options: ValidationOptions = {}) { return (object: object, propertyName: string) => registerDecorator({ target: object.constructor, diff --git a/src/common/test-helpers.ts b/src/common/test-helpers.ts index e18f65a6..a9758174 100644 --- a/src/common/test-helpers.ts +++ b/src/common/test-helpers.ts @@ -45,6 +45,7 @@ export async function buildTestApplication( const module = await Test.createTestingModule({ imports: [ TypeOrmModule.forRootAsync({ + // @ts-expect-error for testing purpose only useFactory: () => ({ ...dataSourceOptions, url: undefined, @@ -68,7 +69,7 @@ export async function buildTestApplication( errorHttpStatusCode: HttpStatus.UNPROCESSABLE_ENTITY, }), ); - app.use(cookieParser(process.env.SECRET)); + app.use(cookieParser(process.env['SECRET'])); useContainer(module, { fallbackOnErrors: true }); return app.init(); diff --git a/src/data-source.ts b/src/data-source.ts index 1b367494..827e941f 100644 --- a/src/data-source.ts +++ b/src/data-source.ts @@ -15,7 +15,7 @@ import { CreateArticleComment1651517018946 } from '@/migrations/1651517018946-cr export const dataSourceOptions: DataSourceOptions & SeederOptions = { type: 'postgres', - url: process.env.DATABASE_URL, + url: process.env['DATABASE_URL']!, synchronize: false, entities: [User, Article, Comment], migrations: [CreateUser1637703183543, CreateArticleComment1651517018946], diff --git a/src/migrations/1637703183543-create-user.ts b/src/migrations/1637703183543-create-user.ts index 3901b55c..5b62ee6b 100644 --- a/src/migrations/1637703183543-create-user.ts +++ b/src/migrations/1637703183543-create-user.ts @@ -1,4 +1,4 @@ -import { MigrationInterface, QueryRunner } from 'typeorm'; +import type { MigrationInterface, QueryRunner } from 'typeorm'; export class CreateUser1637703183543 implements MigrationInterface { name = 'CreateUser1637703183543'; diff --git a/src/migrations/1651517018946-create-article-comment.ts b/src/migrations/1651517018946-create-article-comment.ts index 59154b0e..28fb10a0 100644 --- a/src/migrations/1651517018946-create-article-comment.ts +++ b/src/migrations/1651517018946-create-article-comment.ts @@ -1,4 +1,4 @@ -import { MigrationInterface, QueryRunner } from 'typeorm'; +import type { MigrationInterface, QueryRunner } from 'typeorm'; export class CreateArticleComment1651517018946 implements MigrationInterface { name = 'CreateArticleComment1651517018946';