refactor(server): config system (#11081)

This commit is contained in:
forehalo
2025-03-27 12:32:28 +00:00
parent 7091111f85
commit 0ea38680fa
274 changed files with 7583 additions and 5841 deletions
@@ -1,7 +1,7 @@
import { getCurrentUserQuery } from '@affine/graphql';
import { Mockers } from '../mocks';
import { app, e2e } from './test';
import { Mockers } from '../../mocks';
import { app, e2e } from '../test';
e2e('should create test app correctly', async t => {
t.truthy(app);
@@ -18,12 +18,7 @@ e2e('should mock queue work', async t => {
e2e('should handle http request', async t => {
const res = await app.GET('/info');
t.is(res.status, 200);
t.is(res.body.compatibility, AFFiNE.version);
});
e2e('should handle gql request', async t => {
const user = await app.gql({ query: getCurrentUserQuery });
t.is(user.currentUser, null);
t.is(res.body.compatibility, env.version);
});
e2e('should create workspace with owner', async t => {
@@ -0,0 +1,46 @@
import { getCurrentUserQuery } from '@affine/graphql';
import { createApp } from '../create-app';
import { e2e } from '../test';
e2e('should init doc service', async t => {
// @ts-expect-error override
globalThis.env.FLAVOR = 'doc';
await using app = await createApp();
const res = await app.GET('/info').expect(200);
t.is(res.body.flavor, 'doc');
await t.throwsAsync(app.gql({ query: getCurrentUserQuery }));
});
e2e('should init graphql service', async t => {
// @ts-expect-error override
globalThis.env.FLAVOR = 'graphql';
await using app = await createApp();
const res = await app.GET('/info').expect(200);
t.is(res.body.flavor, 'graphql');
const user = await app.gql({ query: getCurrentUserQuery });
t.is(user.currentUser, null);
});
e2e('should init sync service', async t => {
// @ts-expect-error override
globalThis.env.FLAVOR = 'sync';
await using app = await createApp();
const res = await app.GET('/info').expect(200);
t.is(res.body.flavor, 'sync');
});
e2e('should init renderer service', async t => {
// @ts-expect-error override
globalThis.env.FLAVOR = 'renderer';
await using app = await createApp();
const res = await app.GET('/info').expect(200);
t.is(res.body.flavor, 'renderer');
});
@@ -13,6 +13,7 @@ import {
AFFiNELogger,
CacheInterceptor,
CloudThrottlerGuard,
EventBus,
GlobalExceptionFilter,
JobQueue,
OneMB,
@@ -23,6 +24,7 @@ import { Mailer } from '../../core/mail';
import {
createFactory,
MockedUser,
MockEventBus,
MockJobQueue,
MockMailer,
MockUser,
@@ -181,23 +183,19 @@ export class TestingApp extends NestApplication {
}
}
let GLOBAL_APP_INSTANCE: TestingApp | null = null;
export async function createApp(
metadata: TestingAppMetadata = {}
): Promise<TestingApp> {
if (GLOBAL_APP_INSTANCE) {
return GLOBAL_APP_INSTANCE;
}
const { buildAppModule } = await import('../../app.module');
const { tapModule, tapApp } = metadata;
const builder = Test.createTestingModule({
imports: [buildAppModule()],
imports: [buildAppModule(globalThis.env)],
});
builder.overrideProvider(Mailer).useValue(new MockMailer());
builder.overrideProvider(JobQueue).useValue(new MockJobQueue());
builder.overrideProvider(EventBus).useValue(new MockEventBus());
// when custom override happens
if (tapModule) {
@@ -240,6 +238,5 @@ export async function createApp(
await app.init();
GLOBAL_APP_INSTANCE = app;
return app;
}