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

View File

@@ -3,17 +3,16 @@ import { randomUUID } from 'node:crypto';
import { Transformer } from '@napi-rs/image';
import type { INestApplication } from '@nestjs/common';
import { Test } from '@nestjs/testing';
import { hashSync } from '@node-rs/argon2';
import { type User } from '@prisma/client';
import ava, { type TestFn } from 'ava';
import type { Express } from 'express';
import graphqlUploadExpress from 'graphql-upload/graphqlUploadExpress.mjs';
import request from 'supertest';
import { AppModule } from '../src/app';
import { FeatureManagementService } from '../src/modules/features';
import { PrismaService } from '../src/prisma/service';
import { createTestingApp } from './utils';
const gql = '/graphql';
@@ -49,25 +48,18 @@ class FakePrisma {
}
test.beforeEach(async t => {
const module = await Test.createTestingModule({
const { app } = await createTestingApp({
imports: [AppModule],
})
.overrideProvider(PrismaService)
.useClass(FakePrisma)
.overrideProvider(FeatureManagementService)
.useValue({ canEarlyAccess: () => true })
.compile();
t.context.app = module.createNestApplication({
cors: true,
bodyParser: true,
tapModule(builder) {
builder
.overrideProvider(PrismaService)
.useClass(FakePrisma)
.overrideProvider(FeatureManagementService)
.useValue({ canEarlyAccess: () => true });
},
});
t.context.app.use(
graphqlUploadExpress({
maxFileSize: 10 * 1024 * 1024,
maxFiles: 5,
})
);
await t.context.app.init();
t.context.app = app;
});
test.afterEach.always(async t => {