mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-11 20:08:37 +00:00
feat: integrate new modules (#5087)
This commit is contained in:
@@ -14,10 +14,16 @@ import {
|
||||
|
||||
import { CacheModule } from '../src/cache';
|
||||
import { Config, ConfigModule } from '../src/config';
|
||||
import {
|
||||
collectMigrations,
|
||||
RevertCommand,
|
||||
RunCommand,
|
||||
} from '../src/data/commands/run';
|
||||
import { EventModule } from '../src/event';
|
||||
import { DocManager, DocModule } from '../src/modules/doc';
|
||||
import { QuotaModule } from '../src/modules/quota';
|
||||
import { PrismaModule, PrismaService } from '../src/prisma';
|
||||
import { flushDB } from './utils';
|
||||
import { FakeStorageModule, flushDB } from './utils';
|
||||
|
||||
const createModule = () => {
|
||||
return Test.createTestingModule({
|
||||
@@ -25,8 +31,12 @@ const createModule = () => {
|
||||
PrismaModule,
|
||||
CacheModule,
|
||||
EventModule,
|
||||
QuotaModule,
|
||||
FakeStorageModule.forRoot(),
|
||||
ConfigModule.forRoot(),
|
||||
DocModule,
|
||||
RevertCommand,
|
||||
RunCommand,
|
||||
],
|
||||
}).compile();
|
||||
};
|
||||
@@ -45,6 +55,13 @@ test.beforeEach(async () => {
|
||||
app = m.createNestApplication();
|
||||
app.enableShutdownHooks();
|
||||
await app.init();
|
||||
|
||||
// init features
|
||||
const run = m.get(RunCommand);
|
||||
const revert = m.get(RevertCommand);
|
||||
const migrations = await collectMigrations();
|
||||
await Promise.allSettled(migrations.map(m => revert.run([m.name])));
|
||||
await run.run();
|
||||
});
|
||||
|
||||
test.afterEach.always(async () => {
|
||||
|
||||
@@ -57,14 +57,10 @@ test.beforeEach(async t => {
|
||||
],
|
||||
}).compile();
|
||||
|
||||
const quota = module.get(FeatureService);
|
||||
const storageQuota = module.get(FeatureManagementService);
|
||||
const auth = module.get(AuthService);
|
||||
|
||||
t.context.app = module;
|
||||
t.context.feature = quota;
|
||||
t.context.early_access = storageQuota;
|
||||
t.context.auth = auth;
|
||||
t.context.auth = module.get(AuthService);
|
||||
t.context.feature = module.get(FeatureService);
|
||||
t.context.early_access = module.get(FeatureManagementService);
|
||||
|
||||
// init features
|
||||
await initFeatureConfigs(module);
|
||||
|
||||
@@ -8,8 +8,9 @@ import * as Sinon from 'sinon';
|
||||
import { ConfigModule } from '../src/config';
|
||||
import type { EventPayload } from '../src/event';
|
||||
import { DocHistoryManager } from '../src/modules/doc';
|
||||
import { QuotaModule } from '../src/modules/quota';
|
||||
import { PrismaModule, PrismaService } from '../src/prisma';
|
||||
import { flushDB } from './utils';
|
||||
import { FakeStorageModule, flushDB } from './utils';
|
||||
|
||||
let app: INestApplication;
|
||||
let m: TestingModule;
|
||||
@@ -20,7 +21,13 @@ let db: PrismaService;
|
||||
test.beforeEach(async () => {
|
||||
await flushDB();
|
||||
m = await Test.createTestingModule({
|
||||
imports: [PrismaModule, ScheduleModule.forRoot(), ConfigModule.forRoot()],
|
||||
imports: [
|
||||
PrismaModule,
|
||||
QuotaModule,
|
||||
FakeStorageModule.forRoot(),
|
||||
ScheduleModule.forRoot(),
|
||||
ConfigModule.forRoot(),
|
||||
],
|
||||
providers: [DocHistoryManager],
|
||||
}).compile();
|
||||
|
||||
@@ -277,8 +284,8 @@ test('should be able to recover from history', async t => {
|
||||
t.is(history2.timestamp.getTime(), snapshot.updatedAt.getTime());
|
||||
|
||||
// new history data force created with snapshot state before recovered
|
||||
t.deepEqual(history2?.blob, Buffer.from([1, 1]));
|
||||
t.deepEqual(history2?.state, Buffer.from([1, 1]));
|
||||
t.deepEqual(history2.blob, Buffer.from([1, 1]));
|
||||
t.deepEqual(history2.state, Buffer.from([1, 1]));
|
||||
});
|
||||
|
||||
test('should be able to cleanup expired history', async t => {
|
||||
|
||||
@@ -16,9 +16,8 @@ import {
|
||||
QuotaType,
|
||||
} from '../src/modules/quota';
|
||||
import { PrismaModule } from '../src/prisma';
|
||||
import { StorageModule } from '../src/storage';
|
||||
import { RateLimiterModule } from '../src/throttler';
|
||||
import { initFeatureConfigs } from './utils';
|
||||
import { FakeStorageModule, initFeatureConfigs } from './utils';
|
||||
|
||||
const test = ava as TestFn<{
|
||||
auth: AuthService;
|
||||
@@ -47,10 +46,10 @@ test.beforeEach(async t => {
|
||||
host: 'example.org',
|
||||
https: true,
|
||||
}),
|
||||
StorageModule.forRoot(),
|
||||
PrismaModule,
|
||||
AuthModule,
|
||||
QuotaModule,
|
||||
FakeStorageModule.forRoot(),
|
||||
RateLimiterModule,
|
||||
RevertCommand,
|
||||
RunCommand,
|
||||
|
||||
@@ -6,7 +6,8 @@ import graphqlUploadExpress from 'graphql-upload/graphqlUploadExpress.mjs';
|
||||
import request from 'supertest';
|
||||
|
||||
import { AppModule } from '../src/app';
|
||||
import { currentUser, signUp } from './utils';
|
||||
import { RevertCommand, RunCommand } from '../src/data/commands/run';
|
||||
import { currentUser, initFeatureConfigs, signUp } from './utils';
|
||||
|
||||
let app: INestApplication;
|
||||
|
||||
@@ -21,6 +22,7 @@ test.beforeEach(async () => {
|
||||
test.beforeEach(async () => {
|
||||
const module = await Test.createTestingModule({
|
||||
imports: [AppModule],
|
||||
providers: [RevertCommand, RunCommand],
|
||||
}).compile();
|
||||
app = module.createNestApplication();
|
||||
app.use(
|
||||
@@ -30,6 +32,9 @@ test.beforeEach(async () => {
|
||||
})
|
||||
);
|
||||
await app.init();
|
||||
|
||||
// init features
|
||||
await initFeatureConfigs(module);
|
||||
});
|
||||
|
||||
test.afterEach.always(async () => {
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
import { randomUUID } from 'node:crypto';
|
||||
|
||||
import type { INestApplication } from '@nestjs/common';
|
||||
import type {
|
||||
DynamicModule,
|
||||
FactoryProvider,
|
||||
INestApplication,
|
||||
} from '@nestjs/common';
|
||||
import { TestingModule } from '@nestjs/testing';
|
||||
import { hashSync } from '@node-rs/argon2';
|
||||
import { PrismaClient, type User } from '@prisma/client';
|
||||
@@ -10,6 +14,7 @@ import { RevertCommand, RunCommand } from '../src/data/commands/run';
|
||||
import type { TokenType } from '../src/modules/auth';
|
||||
import type { UserType } from '../src/modules/users';
|
||||
import type { InvitationType, WorkspaceType } from '../src/modules/workspaces';
|
||||
import { StorageProvide } from '../src/storage';
|
||||
|
||||
const gql = '/graphql';
|
||||
|
||||
@@ -563,6 +568,24 @@ export class FakePrisma {
|
||||
}
|
||||
}
|
||||
|
||||
export class FakeStorageModule {
|
||||
static forRoot(): DynamicModule {
|
||||
const storageProvider: FactoryProvider = {
|
||||
provide: StorageProvide,
|
||||
useFactory: async () => {
|
||||
return null;
|
||||
},
|
||||
};
|
||||
|
||||
return {
|
||||
global: true,
|
||||
module: FakeStorageModule,
|
||||
providers: [storageProvider],
|
||||
exports: [storageProvider],
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export async function initFeatureConfigs(module: TestingModule) {
|
||||
const run = module.get(RunCommand);
|
||||
const revert = module.get(RevertCommand);
|
||||
|
||||
Reference in New Issue
Block a user