mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-12 04:18:54 +00:00
refactor(server): folder structure (#5573)
This commit is contained in:
@@ -4,14 +4,13 @@ import { randomUUID } from 'node:crypto';
|
||||
import { Transformer } from '@napi-rs/image';
|
||||
import type { INestApplication } from '@nestjs/common';
|
||||
import { hashSync } from '@node-rs/argon2';
|
||||
import { type User } from '@prisma/client';
|
||||
import { PrismaClient, type User } from '@prisma/client';
|
||||
import ava, { type TestFn } from 'ava';
|
||||
import type { Express } from 'express';
|
||||
import request from 'supertest';
|
||||
|
||||
import { AppModule } from '../src/app';
|
||||
import { FeatureManagementService } from '../src/modules/features';
|
||||
import { PrismaService } from '../src/prisma/service';
|
||||
import { createTestingApp } from './utils';
|
||||
|
||||
const gql = '/graphql';
|
||||
@@ -52,7 +51,7 @@ test.beforeEach(async t => {
|
||||
imports: [AppModule],
|
||||
tapModule(builder) {
|
||||
builder
|
||||
.overrideProvider(PrismaService)
|
||||
.overrideProvider(PrismaClient)
|
||||
.useClass(FakePrisma)
|
||||
.overrideProvider(FeatureManagementService)
|
||||
.useValue({ canEarlyAccess: () => true });
|
||||
|
||||
@@ -5,7 +5,7 @@ import {
|
||||
import type { INestApplication } from '@nestjs/common';
|
||||
import ava, { type TestFn } from 'ava';
|
||||
|
||||
import { MailService } from '../src/modules/auth/mailer';
|
||||
import { MailService } from '../src/fundamentals/mailer';
|
||||
import { AuthService } from '../src/modules/auth/service';
|
||||
import {
|
||||
changeEmail,
|
||||
|
||||
@@ -2,10 +2,13 @@
|
||||
import { TestingModule } from '@nestjs/testing';
|
||||
import test from 'ava';
|
||||
|
||||
import { ConfigModule } from '../src/config';
|
||||
import { ConfigModule } from '../src/fundamentals/config';
|
||||
import {
|
||||
mintChallengeResponse,
|
||||
verifyChallengeResponse,
|
||||
} from '../src/fundamentals/storage';
|
||||
import { AuthResolver } from '../src/modules/auth/resolver';
|
||||
import { AuthService } from '../src/modules/auth/service';
|
||||
import { mintChallengeResponse, verifyChallengeResponse } from '../src/storage';
|
||||
import { createTestingModule } from './utils';
|
||||
|
||||
let authService: AuthService;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import test from 'ava';
|
||||
|
||||
import { Cache, CacheModule } from '../src/cache';
|
||||
import { ConfigModule } from '../src/config';
|
||||
import { Cache, CacheModule } from '../src/fundamentals/cache';
|
||||
import { ConfigModule } from '../src/fundamentals/config';
|
||||
|
||||
let cache: Cache;
|
||||
let module: TestingModule;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import test from 'ava';
|
||||
|
||||
import { Config, ConfigModule } from '../src/config';
|
||||
import { Config, ConfigModule } from '../src/fundamentals/config';
|
||||
|
||||
let config: Config;
|
||||
let module: TestingModule;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { mock } from 'node:test';
|
||||
|
||||
import { TestingModule } from '@nestjs/testing';
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
import test from 'ava';
|
||||
import * as Sinon from 'sinon';
|
||||
import {
|
||||
@@ -10,11 +11,10 @@ import {
|
||||
encodeStateAsUpdate,
|
||||
} from 'yjs';
|
||||
|
||||
import { Config } from '../src/config';
|
||||
import { Config } from '../src/fundamentals/config';
|
||||
import { DocManager, DocModule } from '../src/modules/doc';
|
||||
import { QuotaModule } from '../src/modules/quota';
|
||||
import { StorageModule } from '../src/modules/storage';
|
||||
import { PrismaService } from '../src/prisma';
|
||||
import { createTestingModule, initTestingDB } from './utils';
|
||||
|
||||
const createModule = () => {
|
||||
@@ -33,7 +33,7 @@ test.beforeEach(async () => {
|
||||
});
|
||||
m = await createModule();
|
||||
await m.init();
|
||||
await initTestingDB(m.get(PrismaService));
|
||||
await initTestingDB(m.get(PrismaClient));
|
||||
});
|
||||
|
||||
test.afterEach.always(async () => {
|
||||
@@ -96,7 +96,7 @@ test('should poll when intervel due', async t => {
|
||||
});
|
||||
|
||||
test('should merge update when intervel due', async t => {
|
||||
const db = m.get(PrismaService);
|
||||
const db = m.get(PrismaClient);
|
||||
const manager = m.get(DocManager);
|
||||
|
||||
const doc = new YDoc();
|
||||
@@ -161,7 +161,7 @@ test('should merge update when intervel due', async t => {
|
||||
});
|
||||
|
||||
test('should have sequential update number', async t => {
|
||||
const db = m.get(PrismaService);
|
||||
const db = m.get(PrismaClient);
|
||||
const manager = m.get(DocManager);
|
||||
const doc = new YDoc();
|
||||
const text = doc.getText('content');
|
||||
@@ -278,7 +278,7 @@ test('should throw if meet max retry times', async t => {
|
||||
});
|
||||
|
||||
test('should not update snapshot if state is outdated', async t => {
|
||||
const db = m.get(PrismaService);
|
||||
const db = m.get(PrismaClient);
|
||||
const manager = m.get(DocManager);
|
||||
|
||||
await db.snapshot.create({
|
||||
|
||||
@@ -1,89 +0,0 @@
|
||||
import { Controller, Get, type INestApplication } from '@nestjs/common';
|
||||
import { Test } from '@nestjs/testing';
|
||||
import test from 'ava';
|
||||
import graphqlUploadExpress from 'graphql-upload/graphqlUploadExpress.mjs';
|
||||
import request from 'supertest';
|
||||
|
||||
import { AppModule } from '../src/app';
|
||||
import { ExceptionLogger } from '../src/middleware/exception-logger';
|
||||
import { FeatureManagementService } from '../src/modules/features';
|
||||
import { PrismaService } from '../src/prisma';
|
||||
|
||||
const gql = '/graphql';
|
||||
const rest = '/rest';
|
||||
|
||||
let app: INestApplication;
|
||||
|
||||
class FakePrisma {
|
||||
get workspace() {
|
||||
return {
|
||||
async findUnique() {
|
||||
throw new Error('exception from graphql');
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@Controller('rest')
|
||||
export class MockController {
|
||||
@Get()
|
||||
test(): string {
|
||||
throw new Error('exception from rest api');
|
||||
}
|
||||
}
|
||||
|
||||
test.beforeEach(async () => {
|
||||
const module = await Test.createTestingModule({
|
||||
imports: [AppModule],
|
||||
controllers: [MockController],
|
||||
})
|
||||
.overrideProvider(PrismaService)
|
||||
.useClass(FakePrisma)
|
||||
.overrideProvider(FeatureManagementService)
|
||||
.useValue({})
|
||||
.compile();
|
||||
app = module.createNestApplication({
|
||||
cors: true,
|
||||
bodyParser: true,
|
||||
});
|
||||
app.useGlobalFilters(new ExceptionLogger());
|
||||
app.use(
|
||||
graphqlUploadExpress({
|
||||
maxFileSize: 10 * 1024 * 1024,
|
||||
maxFiles: 5,
|
||||
})
|
||||
);
|
||||
await app.init();
|
||||
});
|
||||
|
||||
test.afterEach.always(async () => {
|
||||
await app.close();
|
||||
});
|
||||
|
||||
test('should get response from graphql', async t => {
|
||||
const id = 'workspace';
|
||||
|
||||
const response = await request(app.getHttpServer())
|
||||
.post(gql)
|
||||
.send({
|
||||
name: 'getPublicWorkspace',
|
||||
query: `
|
||||
query getPublicWorkspace($id: String!) {
|
||||
publicWorkspace(id: $id) {
|
||||
id
|
||||
}
|
||||
}
|
||||
`,
|
||||
variables: { id },
|
||||
});
|
||||
|
||||
t.is(response.status, 200);
|
||||
t.is(response.body.errors[0].message, 'exception from graphql');
|
||||
});
|
||||
|
||||
test('should get response from rest api', async t => {
|
||||
const response = await request(app.getHttpServer()).get(rest);
|
||||
|
||||
t.is(response.status, 500);
|
||||
t.is(response.body.error, 'exception from rest api');
|
||||
});
|
||||
@@ -1,9 +1,10 @@
|
||||
/// <reference types="../src/global.d.ts" />
|
||||
|
||||
import { INestApplication, Injectable } from '@nestjs/common';
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
import ava, { type TestFn } from 'ava';
|
||||
|
||||
import { ConfigModule } from '../src/config';
|
||||
import { ConfigModule } from '../src/fundamentals/config';
|
||||
import { AuthService } from '../src/modules/auth/service';
|
||||
import {
|
||||
FeatureManagementService,
|
||||
@@ -14,12 +15,11 @@ import {
|
||||
import { UserType } from '../src/modules/users/types';
|
||||
import { WorkspaceResolver } from '../src/modules/workspaces/resolvers';
|
||||
import { Permission } from '../src/modules/workspaces/types';
|
||||
import { PrismaService } from '../src/prisma';
|
||||
import { createTestingApp } from './utils';
|
||||
|
||||
@Injectable()
|
||||
class WorkspaceResolverMock {
|
||||
constructor(private readonly prisma: PrismaService) {}
|
||||
constructor(private readonly prisma: PrismaClient) {}
|
||||
|
||||
async createWorkspace(user: UserType, _init: null) {
|
||||
const workspace = await this.prisma.workspace.create({
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
import { TestingModule } from '@nestjs/testing';
|
||||
import type { Snapshot } from '@prisma/client';
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
import test from 'ava';
|
||||
import * as Sinon from 'sinon';
|
||||
|
||||
import { type EventPayload } from '../src/event';
|
||||
import { type EventPayload } from '../src/fundamentals/event';
|
||||
import { DocHistoryManager } from '../src/modules/doc';
|
||||
import { QuotaModule } from '../src/modules/quota';
|
||||
import { StorageModule } from '../src/modules/storage';
|
||||
import { PrismaService } from '../src/prisma';
|
||||
import { createTestingModule } from './utils';
|
||||
|
||||
let m: TestingModule;
|
||||
let manager: DocHistoryManager;
|
||||
let db: PrismaService;
|
||||
let db: PrismaClient;
|
||||
|
||||
// cleanup database before each test
|
||||
test.beforeEach(async () => {
|
||||
@@ -25,7 +25,7 @@ test.beforeEach(async () => {
|
||||
Sinon.stub(manager, 'getExpiredDateFromNow').resolves(
|
||||
new Date(Date.now() + 1000)
|
||||
);
|
||||
db = m.get(PrismaService);
|
||||
db = m.get(PrismaClient);
|
||||
});
|
||||
|
||||
test.afterEach.always(async () => {
|
||||
|
||||
@@ -10,7 +10,7 @@ import { TestingModule } from '@nestjs/testing';
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
import ava, { type TestFn } from 'ava';
|
||||
|
||||
import { ConfigModule } from '../src/config';
|
||||
import { ConfigModule } from '../src/fundamentals/config';
|
||||
import { AuthService } from '../src/modules/auth/service';
|
||||
import { createTestingModule } from './utils';
|
||||
|
||||
|
||||
@@ -3,13 +3,13 @@ import { randomUUID } from 'node:crypto';
|
||||
import type { INestApplication } from '@nestjs/common';
|
||||
import { hashSync } from '@node-rs/argon2';
|
||||
import { type User } from '@prisma/client';
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
import ava, { type TestFn } from 'ava';
|
||||
|
||||
import { AppModule } from '../src/app';
|
||||
import { MailService } from '../src/modules/auth/mailer';
|
||||
import { MailService } from '../src/fundamentals/mailer';
|
||||
import { FeatureKind, FeatureManagementService } from '../src/modules/features';
|
||||
import { Quotas } from '../src/modules/quota';
|
||||
import { PrismaService } from '../src/prisma';
|
||||
import {
|
||||
createTestingApp,
|
||||
createWorkspace,
|
||||
@@ -131,7 +131,7 @@ test.beforeEach(async t => {
|
||||
imports: [AppModule],
|
||||
tapModule: module => {
|
||||
module
|
||||
.overrideProvider(PrismaService)
|
||||
.overrideProvider(PrismaClient)
|
||||
.useValue(FakePrisma)
|
||||
.overrideProvider(FeatureManagementService)
|
||||
.useValue({
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
import { TestingModule } from '@nestjs/testing';
|
||||
import ava, { type TestFn } from 'ava';
|
||||
|
||||
import { AuthService } from '../src/modules/auth/service';
|
||||
import { AuthService } from '../src/modules/auth';
|
||||
import {
|
||||
QuotaManagementService,
|
||||
QuotaModule,
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
import { TestingModule } from '@nestjs/testing';
|
||||
import ava, { type TestFn } from 'ava';
|
||||
|
||||
import { CacheModule } from '../src/cache';
|
||||
import { ConfigModule } from '../src/config';
|
||||
import { SessionModule, SessionService } from '../src/session';
|
||||
import { CacheModule } from '../src/fundamentals/cache';
|
||||
import { ConfigModule } from '../src/fundamentals/config';
|
||||
import { SessionModule, SessionService } from '../src/fundamentals/session';
|
||||
import { createTestingModule } from './utils';
|
||||
|
||||
const test = ava as TestFn<{
|
||||
|
||||
@@ -6,7 +6,7 @@ import graphqlUploadExpress from 'graphql-upload/graphqlUploadExpress.mjs';
|
||||
|
||||
import { AppModule, FunctionalityModules } from '../../src/app';
|
||||
import { UserFeaturesInit1698652531198 } from '../../src/data/migrations/1698652531198-user-features-init';
|
||||
import { GqlModule } from '../../src/graphql.module';
|
||||
import { GqlModule } from '../../src/fundamentals/graphql';
|
||||
|
||||
async function flushDB(client: PrismaClient) {
|
||||
const result: { tablename: string }[] =
|
||||
|
||||
@@ -7,9 +7,8 @@ import { PrismaClient } from '@prisma/client';
|
||||
import ava, { type TestFn } from 'ava';
|
||||
|
||||
import { AppModule } from '../src/app';
|
||||
import { MailService } from '../src/modules/auth/mailer';
|
||||
import { MailService } from '../src/fundamentals/mailer';
|
||||
import { AuthService } from '../src/modules/auth/service';
|
||||
import { PrismaService } from '../src/prisma';
|
||||
import {
|
||||
acceptInviteById,
|
||||
createTestingApp,
|
||||
@@ -33,7 +32,7 @@ test.beforeEach(async t => {
|
||||
imports: [AppModule],
|
||||
});
|
||||
t.context.app = app;
|
||||
t.context.client = app.get(PrismaService);
|
||||
t.context.client = app.get(PrismaClient);
|
||||
t.context.auth = app.get(AuthService);
|
||||
t.context.mail = app.get(MailService);
|
||||
});
|
||||
|
||||
@@ -4,7 +4,6 @@ import ava, { type TestFn } from 'ava';
|
||||
import request from 'supertest';
|
||||
|
||||
import { AppModule } from '../src/app';
|
||||
import { PrismaService } from '../src/prisma';
|
||||
import {
|
||||
acceptInviteById,
|
||||
createTestingApp,
|
||||
@@ -29,7 +28,7 @@ test.beforeEach(async t => {
|
||||
imports: [AppModule],
|
||||
});
|
||||
|
||||
t.context.client = app.get(PrismaService);
|
||||
t.context.client = app.get(PrismaClient);
|
||||
t.context.app = app;
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user