AFFiNE/packages/backend/server/tests/app.e2e.ts

58 lines
1.1 KiB
TypeScript
Raw Normal View History

import type { INestApplication } from '@nestjs/common';
import type { TestFn } from 'ava';
import ava from 'ava';
2023-04-19 02:14:25 +03:00
import request from 'supertest';
import { AppModule } from '../src/app.module';
import { createTestingApp } from './utils';
2023-04-19 02:14:25 +03:00
const gql = '/graphql';
const test = ava as TestFn<{
app: INestApplication;
}>;
2023-04-19 02:14:25 +03:00
test.beforeEach(async t => {
const { app } = await createTestingApp({
2023-09-01 22:41:29 +03:00
imports: [AppModule],
2023-04-19 02:14:25 +03:00
});
t.context.app = app;
2023-09-01 22:41:29 +03:00
});
2023-04-19 02:14:25 +03:00
test.afterEach.always(async t => {
await t.context.app.close();
2023-09-01 22:41:29 +03:00
});
2023-04-19 02:14:25 +03:00
test('should init app', async t => {
await request(t.context.app.getHttpServer())
2023-09-01 22:41:29 +03:00
.post(gql)
.send({
query: `
query {
error
}
`,
2023-09-01 22:41:29 +03:00
})
.expect(400);
const response = await request(t.context.app.getHttpServer())
2023-09-01 22:41:29 +03:00
.post(gql)
.send({
query: `query {
serverConfig {
name
version
type
features
2023-04-19 02:14:25 +03:00
}
}`,
2023-09-01 22:41:29 +03:00
})
.expect(200);
2023-06-21 09:08:32 +03:00
const config = response.body.data.serverConfig;
2023-06-21 09:08:32 +03:00
t.is(config.type, 'Affine');
t.true(Array.isArray(config.features));
2023-04-19 02:14:25 +03:00
});