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
+4 -19
View File
@@ -6,19 +6,13 @@ import {
getCurrentMailMessageCount,
getLatestMailMessage,
} from '@affine-test/kit/utils/cloud';
import { Test, TestingModule } from '@nestjs/testing';
import { TestingModule } from '@nestjs/testing';
import { PrismaClient } from '@prisma/client';
import ava, { type TestFn } 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 { AuthService } from '../src/modules/auth/service';
import { PrismaModule } from '../src/prisma';
import { RateLimiterModule } from '../src/throttler';
import { initFeatureConfigs } from './utils';
import { createTestingModule } from './utils';
const test = ava as TestFn<{
auth: AuthService;
@@ -34,7 +28,7 @@ test.beforeEach(async () => {
});
test.beforeEach(async t => {
t.context.module = await Test.createTestingModule({
t.context.module = await createTestingModule({
imports: [
ConfigModule.forRoot({
auth: {
@@ -43,18 +37,9 @@ test.beforeEach(async t => {
leeway: 1,
},
}),
PrismaModule,
GqlModule,
AuthModule,
CacheModule,
RateLimiterModule,
],
providers: [RevertCommand, RunCommand],
}).compile();
});
t.context.auth = t.context.module.get(AuthService);
// init features
await initFeatureConfigs(t.context.module);
});
test.afterEach.always(async t => {