fix: app config shared

This commit is contained in:
Innei
2021-10-02 13:11:40 +08:00
parent 6faf5a8cec
commit b7db64e3ae
17 changed files with 909 additions and 693 deletions

View File

@@ -0,0 +1,52 @@
import { GraphQLModule } from '@nestjs/graphql'
import { NestFastifyApplication } from '@nestjs/platform-fastify'
import { Test } from '@nestjs/testing'
import { join } from 'path'
import { AppResolver } from '~/app.resolver'
import { fastifyApp } from '~/common/adapt/fastify'
describe('GQL test (e2e)', () => {
let app: NestFastifyApplication
beforeAll(async () => {
const moduleRef = await Test.createTestingModule({
imports: [
GraphQLModule.forRoot({
autoSchemaFile: join(process.cwd(), 'schema.gql'),
context: ({ req }) => ({ req }),
}),
AppResolver,
],
}).compile()
app = moduleRef.createNestApplication<NestFastifyApplication>(fastifyApp)
await app.init()
await app.getHttpAdapter().getInstance().ready()
})
it('GET /graphql', () => {
return app
.inject({
method: 'post',
url: '/graphql',
payload: {
operationName: null,
variables: {},
query: ` {
sayHello
}`,
},
})
.then((res) => {
expect(res.statusCode).toBe(200)
expect(res.json()).toStrictEqual({
data: {
sayHello: 'Hello World!',
},
})
})
})
afterAll(async () => {
await app.close()
})
})