fix: test config

This commit is contained in:
Innei 2022-04-10 20:40:32 +08:00
parent 01079097fe
commit 1bc6b61e37
No known key found for this signature in database
GPG Key ID: 0F62D33977F021F7
3 changed files with 6 additions and 3 deletions

View File

@ -17,7 +17,7 @@ module.exports = {
globals: {
'ts-jest': {
useESM: true,
tsConfig: './test/tsconfig.json',
tsconfig: './test/tsconfig.json',
},
isDev: process.env.NODE_ENV === 'development',
},

View File

@ -9,6 +9,7 @@
import { CanActivate, ExecutionContext, Injectable } from '@nestjs/common'
import { AuthGuard } from '@nestjs/passport'
import { isTest } from '~/global/env.global'
import { AuthService } from '~/modules/auth/auth.service'
import { getNestExecutionContextRequest } from '~/transformers/get-req.transformer'
@ -29,7 +30,8 @@ export class RolesGuard extends AuthGuard('jwt') implements CanActivate {
try {
isMaster = (await super.canActivate(context)) as boolean
} catch {}
if (!isMaster) {
// FIXME test env
if (!isMaster && !isTest) {
const [isValidToken, userModel] =
await this.authService.verifyCustomToken(authorization as string)
if (isValidToken) {

View File

@ -10,6 +10,7 @@ import {
import { AuthGuard } from '@nestjs/passport'
import { NestFastifyApplication } from '@nestjs/platform-fastify'
import { Test } from '@nestjs/testing'
import { fastifyApp } from '~/common/adapters/fastify.adapter'
import { RolesGuard } from '~/common/guard/roles.guard'
import { AttachHeaderTokenMiddleware } from '~/common/middlewares/attach-auth.middleware'
@ -36,7 +37,7 @@ describe('AuthMiddleware (e2e)', () => {
imports: [AppModule],
})
.overrideProvider(AuthGuard)
.useValue({ canActivate: () => true })
.useValue({ canActivate: () => true, verifyCustomToken: () => false })
.compile()
app = moduleRef.createNestApplication<NestFastifyApplication>(fastifyApp)