fix: testing

Signed-off-by: Innei <i@innei.in>
This commit is contained in:
Innei
2024-04-30 15:39:12 +08:00
parent 9432f4c990
commit f74ef93dc3
3 changed files with 20 additions and 18 deletions

View File

@@ -1,21 +1,23 @@
import { map } from 'rxjs'
import { Inject, Injectable } from '@nestjs/common'
import {
type CallHandler,
type ExecutionContext,
Inject,
Injectable,
type NestInterceptor,
} from '@nestjs/common'
import { HTTP_RES_UPDATE_DOC_COUNT_TYPE } from '~/constants/meta.constant'
import { REFLECTOR } from '~/constants/system.constant'
import { CountingService } from '~/processors/helper/helper.counting.service'
import type { Reflector } from '@nestjs/core'
import type { CountingService } from '~/processors/helper/helper.counting.service'
import type {
CallHandler,
ExecutionContext,
NestInterceptor,
} from '@nestjs/common'
@Injectable()
export class MockingCountingInterceptor<T> implements NestInterceptor<T> {
constructor(
@Inject(REFLECTOR) private readonly reflector: Reflector,
@Inject(CountingService)
private readonly countingService: CountingService,
) {}

View File

@@ -62,13 +62,13 @@ describe('test serverless function service', () => {
const model = new SnippetModel()
Object.assign<SnippetModel, Partial<SnippetModel>>(model, {
type: SnippetType.Function,
raw: async function handler(context, require) {
raw: async function handler() {
return 1 + 1
}.toString(),
})
const data = await service.injectContextIntoServerlessFunctionAndCall(
model,
{ req: {} as any, res: {} as any },
{ req: {} as any, res: {} as any, isAuthenticated: false },
)
expect(data).toBe(2)
})
@@ -78,12 +78,12 @@ describe('test serverless function service', () => {
Object.assign<SnippetModel, Partial<SnippetModel>>(model, {
type: SnippetType.Function,
raw: async function handler(context, require) {
return (await require('path')).join('1', '1')
return (await require('node:path')).join('1', '1')
}.toString(),
})
const data = await service.injectContextIntoServerlessFunctionAndCall(
model,
{ req: {} as any, res: {} as any },
{ req: {} as any, res: {} as any, isAuthenticated: false },
)
expect(data).toBe('1/1')
})
@@ -98,7 +98,7 @@ describe('test serverless function service', () => {
})
const data = await service.injectContextIntoServerlessFunctionAndCall(
model,
{ req: {} as any, res: {} as any },
{ req: {} as any, res: {} as any, isAuthenticated: false },
)
expect(data).toBeDefined()
})
@@ -108,7 +108,7 @@ describe('test serverless function service', () => {
Object.assign<SnippetModel, Partial<SnippetModel>>(model, {
type: SnippetType.Function,
raw: async function handler(context, require) {
return await require('os')
return await require('node:os')
}.toString(),
})
@@ -116,6 +116,7 @@ describe('test serverless function service', () => {
service.injectContextIntoServerlessFunctionAndCall(model, {
req: {} as any,
res: {} as any,
isAuthenticated: false,
}),
).rejects.toThrow()
})
@@ -141,7 +142,7 @@ describe('test serverless function service', () => {
const model = new SnippetModel()
Object.assign<SnippetModel, Partial<SnippetModel>>(model, {
type: SnippetType.Function,
raw: async function handler(context, require) {
raw: async function handler(context) {
return context.throws(404, 'not found')
}.toString(),
})
@@ -150,6 +151,7 @@ describe('test serverless function service', () => {
service.injectContextIntoServerlessFunctionAndCall(model, {
req: {} as any,
res: createMockedContextResponse({} as any),
isAuthenticated: false,
}),
).rejects.toThrow()
})
@@ -163,7 +165,7 @@ describe('test serverless function service', () => {
})
const data = await service.injectContextIntoServerlessFunctionAndCall(
model,
{ req: {} as any, res: {} as any },
{ req: {} as any, res: {} as any, isAuthenticated: false },
)
expect(typeof data.get).toBe('function')
@@ -177,7 +179,7 @@ describe('test serverless function service', () => {
})
const data = await service.injectContextIntoServerlessFunctionAndCall(
model,
{ req: {} as any, res: {} as any },
{ req: {} as any, res: {} as any, isAuthenticated: false },
)
expect(typeof data).toBe('function')
})

View File

@@ -20,8 +20,6 @@ export default sxzz(
'packages/*/esm',
'packages/*/types',
'test/**/*.db.ts',
'apps/core/test/**/*',
],
languageOptions: {
parserOptions: {