2023-06-08 20:42:58 +03:00
|
|
|
import type { INestApplication } from '@nestjs/common';
|
2024-03-25 06:55:32 +03:00
|
|
|
import type { TestFn } from 'ava';
|
|
|
|
import ava from 'ava';
|
2023-04-19 02:14:25 +03:00
|
|
|
import request from 'supertest';
|
|
|
|
|
2024-08-15 13:01:54 +03:00
|
|
|
import { buildAppModule } from '../../src/app.module';
|
|
|
|
import { createTestingApp } from '../utils';
|
2023-04-19 02:14:25 +03:00
|
|
|
|
|
|
|
const gql = '/graphql';
|
|
|
|
|
2023-09-08 08:15:33 +03:00
|
|
|
const test = ava as TestFn<{
|
|
|
|
app: INestApplication;
|
|
|
|
}>;
|
2023-04-19 02:14:25 +03:00
|
|
|
|
2024-08-15 13:01:54 +03:00
|
|
|
test.before('start app', async t => {
|
|
|
|
// @ts-expect-error override
|
2024-09-10 07:03:52 +03:00
|
|
|
AFFiNE.flavor = {
|
|
|
|
type: 'graphql',
|
|
|
|
allinone: false,
|
|
|
|
graphql: true,
|
|
|
|
sync: false,
|
|
|
|
renderer: false,
|
|
|
|
} satisfies typeof AFFiNE.flavor;
|
2024-01-11 09:40:55 +03:00
|
|
|
const { app } = await createTestingApp({
|
2024-08-15 13:01:54 +03:00
|
|
|
imports: [buildAppModule()],
|
2023-04-19 02:14:25 +03:00
|
|
|
});
|
2024-01-11 09:40:55 +03:00
|
|
|
|
|
|
|
t.context.app = app;
|
2023-09-01 22:41:29 +03:00
|
|
|
});
|
2023-04-19 02:14:25 +03:00
|
|
|
|
2024-08-15 13:01:54 +03:00
|
|
|
test.after.always(async t => {
|
2023-09-08 08:15:33 +03:00
|
|
|
await t.context.app.close();
|
2023-09-01 22:41:29 +03:00
|
|
|
});
|
2023-04-19 02:14:25 +03:00
|
|
|
|
2023-09-05 11:01:45 +03:00
|
|
|
test('should init app', async t => {
|
2023-09-08 08:15:33 +03:00
|
|
|
await request(t.context.app.getHttpServer())
|
2023-09-01 22:41:29 +03:00
|
|
|
.post(gql)
|
|
|
|
.send({
|
|
|
|
query: `
|
2023-04-28 02:02:05 +03:00
|
|
|
query {
|
|
|
|
error
|
|
|
|
}
|
|
|
|
`,
|
2023-09-01 22:41:29 +03:00
|
|
|
})
|
|
|
|
.expect(400);
|
2023-04-28 02:02:05 +03:00
|
|
|
|
2024-03-12 13:00:09 +03:00
|
|
|
const response = await request(t.context.app.getHttpServer())
|
2023-09-01 22:41:29 +03:00
|
|
|
.post(gql)
|
|
|
|
.send({
|
2024-03-12 13:00:09 +03:00
|
|
|
query: `query {
|
|
|
|
serverConfig {
|
|
|
|
name
|
|
|
|
version
|
|
|
|
type
|
|
|
|
features
|
2023-04-19 02:14:25 +03:00
|
|
|
}
|
2024-03-12 13:00:09 +03:00
|
|
|
}`,
|
2023-09-01 22:41:29 +03:00
|
|
|
})
|
2024-03-12 13:00:09 +03:00
|
|
|
.expect(200);
|
2023-06-21 09:08:32 +03:00
|
|
|
|
2024-03-12 13:00:09 +03:00
|
|
|
const config = response.body.data.serverConfig;
|
2023-06-21 09:08:32 +03:00
|
|
|
|
2024-03-12 13:00:09 +03:00
|
|
|
t.is(config.type, 'Affine');
|
|
|
|
t.true(Array.isArray(config.features));
|
2023-04-19 02:14:25 +03:00
|
|
|
});
|
2024-08-15 13:01:54 +03:00
|
|
|
|
|
|
|
test('should return 404 for unknown path', async t => {
|
|
|
|
await request(t.context.app.getHttpServer()).get('/unknown').expect(404);
|
|
|
|
|
|
|
|
t.pass();
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should be able to call apis', async t => {
|
|
|
|
const res = await request(t.context.app.getHttpServer())
|
|
|
|
.get('/info')
|
|
|
|
.expect(200);
|
|
|
|
|
|
|
|
t.is(res.body.flavor, 'graphql');
|
|
|
|
});
|