test(server): all instance variants (#7882)

This commit is contained in:
forehalo
2024-08-15 10:01:54 +00:00
parent 624f3514fc
commit e53dde7944
5 changed files with 59 additions and 24 deletions

View File

@@ -15,7 +15,7 @@ export class AppController {
compatibility: this.config.version,
message: `AFFiNE ${this.config.version} Server`,
type: this.config.type,
flavor: this.config.flavor,
flavor: this.config.flavor.type,
};
}
}

View File

@@ -3,8 +3,8 @@ import type { TestFn } from 'ava';
import ava from 'ava';
import request from 'supertest';
import { AppModule } from '../src/app.module';
import { createTestingApp } from './utils';
import { buildAppModule } from '../../src/app.module';
import { createTestingApp } from '../utils';
const gql = '/graphql';
@@ -12,15 +12,17 @@ const test = ava as TestFn<{
app: INestApplication;
}>;
test.beforeEach(async t => {
test.before('start app', async t => {
// @ts-expect-error override
AFFiNE.flavor = { type: 'graphql', graphql: true, sync: false };
const { app } = await createTestingApp({
imports: [AppModule],
imports: [buildAppModule()],
});
t.context.app = app;
});
test.afterEach.always(async t => {
test.after.always(async t => {
await t.context.app.close();
});
@@ -55,3 +57,17 @@ test('should init app', async t => {
t.is(config.type, 'Affine');
t.true(Array.isArray(config.features));
});
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');
});

View File

@@ -101,9 +101,11 @@ test('should always return static asset files', async t => {
});
test('should be able to call apis', async t => {
await request(t.context.app.getHttpServer()).get('/info').expect(200);
const res = await request(t.context.app.getHttpServer())
.get('/info')
.expect(200);
t.pass();
t.is(res.body.flavor, 'allinone');
});
const blockedPages = [

View File

@@ -0,0 +1,33 @@
import type { INestApplication } from '@nestjs/common';
import type { TestFn } from 'ava';
import ava from 'ava';
import request from 'supertest';
import { buildAppModule } from '../../src/app.module';
import { createTestingApp } from '../utils';
const test = ava as TestFn<{
app: INestApplication;
}>;
test.before('start app', async t => {
// @ts-expect-error override
AFFiNE.flavor = { type: 'sync', graphql: false, sync: true };
const { app } = await createTestingApp({
imports: [buildAppModule()],
});
t.context.app = app;
});
test.after.always(async t => {
await t.context.app.close();
});
test('should init app', async t => {
const res = await request(t.context.app.getHttpServer())
.get('/info')
.expect(200);
t.is(res.body.flavor, 'sync');
});

View File

@@ -1,16 +0,0 @@
import { Test } from '@nestjs/testing';
import test from 'ava';
test('should be able to bootstrap sync server', async t => {
// set env before import
process.env.SERVER_FLAVOR = 'sync';
const { AppModule } = await import('../src/app.module');
await t.notThrowsAsync(async () => {
const module = await Test.createTestingModule({
imports: [AppModule],
}).compile();
const app = module.createNestApplication();
await app.close();
});
process.env.SERVER_FLAVOR = '';
});