mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-13 16:16:46 +08:00
test(server): make server testing utils (#5544)
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { DynamicModule, Module, Type } from '@nestjs/common';
|
||||
import { APP_INTERCEPTOR } from '@nestjs/core';
|
||||
|
||||
import { AppController } from './app.controller';
|
||||
@@ -13,7 +13,7 @@ import { PrismaModule } from './prisma';
|
||||
import { SessionModule } from './session';
|
||||
import { RateLimiterModule } from './throttler';
|
||||
|
||||
export const BasicModules = [
|
||||
export const FunctionalityModules: Array<Type | DynamicModule> = [
|
||||
ConfigModule.forRoot(),
|
||||
CacheModule,
|
||||
PrismaModule,
|
||||
@@ -26,7 +26,7 @@ export const BasicModules = [
|
||||
|
||||
// better module registration logic
|
||||
if (AFFiNE.redis.enabled) {
|
||||
BasicModules.push(RedisModule);
|
||||
FunctionalityModules.push(RedisModule);
|
||||
}
|
||||
|
||||
@Module({
|
||||
@@ -36,7 +36,7 @@ if (AFFiNE.redis.enabled) {
|
||||
useClass: CacheInterceptor,
|
||||
},
|
||||
],
|
||||
imports: [...BasicModules, ...BusinessModules],
|
||||
imports: [...FunctionalityModules, ...BusinessModules],
|
||||
controllers: SERVER_FLAVOR === 'selfhosted' ? [] : [AppController],
|
||||
})
|
||||
export class AppModule {}
|
||||
|
||||
@@ -21,11 +21,12 @@ import { GQLLoggerPlugin } from './graphql/logger-plugin';
|
||||
csrfPrevention: {
|
||||
requestHeaders: ['content-type'],
|
||||
},
|
||||
autoSchemaFile: join(
|
||||
fileURLToPath(import.meta.url),
|
||||
'..',
|
||||
'schema.gql'
|
||||
),
|
||||
autoSchemaFile: config.node.test
|
||||
? join(
|
||||
fileURLToPath(import.meta.url),
|
||||
'../../node_modules/.cache/schema.gql'
|
||||
)
|
||||
: join(fileURLToPath(import.meta.url), '..', 'schema.gql'),
|
||||
context: ({ req, res }: { req: Request; res: Response }) => ({
|
||||
req,
|
||||
res,
|
||||
|
||||
@@ -12,6 +12,7 @@ import { QuotaManagementService } from './storage';
|
||||
* - quota statistics
|
||||
*/
|
||||
@Module({
|
||||
// FIXME: Quota really need to know `Storage`?
|
||||
imports: [StorageModule],
|
||||
providers: [PermissionService, QuotaService, QuotaManagementService],
|
||||
exports: [QuotaService, QuotaManagementService],
|
||||
|
||||
@@ -101,7 +101,7 @@ test('list recursively', async t => {
|
||||
t.is(r5.length, 20);
|
||||
});
|
||||
|
||||
test.only('delete', async t => {
|
||||
test('delete', async t => {
|
||||
const provider = createProvider();
|
||||
const key = 'testKey';
|
||||
const body = Buffer.from('testBody');
|
||||
|
||||
@@ -1,11 +1,18 @@
|
||||
import { Global, Module } from '@nestjs/common';
|
||||
import { Global, Module, Provider } from '@nestjs/common';
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
|
||||
import { PrismaService } from './service';
|
||||
|
||||
// both `PrismaService` and `PrismaClient` can be injected
|
||||
const clientProvider: Provider = {
|
||||
provide: PrismaClient,
|
||||
useExisting: PrismaService,
|
||||
};
|
||||
|
||||
@Global()
|
||||
@Module({
|
||||
providers: [PrismaService],
|
||||
exports: [PrismaService],
|
||||
providers: [PrismaService, clientProvider],
|
||||
exports: [PrismaService, clientProvider],
|
||||
})
|
||||
export class PrismaModule {}
|
||||
export { PrismaService } from './service';
|
||||
|
||||
Reference in New Issue
Block a user