mirror of https://github.com/mx-space/core
fix: test config
This commit is contained in:
parent
01079097fe
commit
1bc6b61e37
|
@ -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',
|
||||
},
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue