test(server): make server testing utils (#5544)

This commit is contained in:
liuyi
2024-01-11 06:40:55 +00:00
parent 9253e522aa
commit 12fdb18a80
20 changed files with 238 additions and 451 deletions
+5 -29
View File
@@ -1,34 +1,19 @@
/// <reference types="../src/global.d.ts" />
import { Test, TestingModule } from '@nestjs/testing';
import { PrismaClient } from '@prisma/client';
import { TestingModule } from '@nestjs/testing';
import test from 'ava';
import { CacheModule } from '../src/cache';
import { ConfigModule } from '../src/config';
import { RevertCommand, RunCommand } from '../src/data/commands/run';
import { GqlModule } from '../src/graphql.module';
import { AuthModule } from '../src/modules/auth';
import { AuthResolver } from '../src/modules/auth/resolver';
import { AuthService } from '../src/modules/auth/service';
import { PrismaModule } from '../src/prisma';
import { mintChallengeResponse, verifyChallengeResponse } from '../src/storage';
import { RateLimiterModule } from '../src/throttler';
import { initFeatureConfigs } from './utils';
import { createTestingModule } from './utils';
let authService: AuthService;
let authResolver: AuthResolver;
let module: TestingModule;
// cleanup database before each test
test.beforeEach(async () => {
const client = new PrismaClient();
await client.$connect();
await client.user.deleteMany({});
await client.$disconnect();
});
test.beforeEach(async () => {
module = await Test.createTestingModule({
module = await createTestingModule({
imports: [
ConfigModule.forRoot({
auth: {
@@ -39,20 +24,11 @@ test.beforeEach(async () => {
host: 'example.org',
https: true,
}),
PrismaModule,
CacheModule,
GqlModule,
AuthModule,
RateLimiterModule,
RevertCommand,
RunCommand,
],
}).compile();
});
authService = module.get(AuthService);
authResolver = module.get(AuthResolver);
// init features
await initFeatureConfigs(module);
});
test.afterEach.always(async () => {