feat(server): setup api for selfhost deployment (#7569)

This commit is contained in:
forehalo
2024-07-23 10:39:33 +00:00
parent 14fbeb7879
commit dddbfe6473
21 changed files with 243 additions and 136 deletions

View File

@@ -7,7 +7,7 @@ import { createTestingModule } from './utils';
let config: Config;
let module: TestingModule;
test.beforeEach(async () => {
module = await createTestingModule();
module = await createTestingModule({}, false);
config = module.get(Config);
});
@@ -33,4 +33,6 @@ test('should be able to override config', async t => {
const config = module.get(Config);
t.is(config.server.host, 'testing');
await module.close();
});

View File

@@ -13,9 +13,12 @@ import { Config } from '../src/fundamentals/config';
import { createTestingModule } from './utils';
const createModule = () => {
return createTestingModule({
imports: [QuotaModule, StorageModule, DocModule],
});
return createTestingModule(
{
imports: [QuotaModule, StorageModule, DocModule],
},
false
);
};
let m: TestingModule;

View File

@@ -1,5 +1,4 @@
import type { INestApplication } from '@nestjs/common';
import { hashSync } from '@node-rs/argon2';
import request, { type Response } from 'supertest';
import {
@@ -54,7 +53,7 @@ export async function signUp(
const user = await app.get(UserService).createUser({
name,
email,
password: hashSync(password),
password,
emailVerifiedAt: autoVerifyEmail ? new Date() : null,
});
const { sessionId } = await app.get(AuthService).createUserSession(user);

View File

@@ -11,7 +11,7 @@ import supertest from 'supertest';
import { AppModule, FunctionalityModules } from '../../src/app.module';
import { AuthGuard, AuthModule } from '../../src/core/auth';
import { UserFeaturesInit1698652531198 } from '../../src/data/migrations/1698652531198-user-features-init';
import { GlobalExceptionFilter } from '../../src/fundamentals';
import { Config, GlobalExceptionFilter } from '../../src/fundamentals';
import { GqlModule } from '../../src/fundamentals/graphql';
async function flushDB(client: PrismaClient) {
@@ -67,7 +67,8 @@ class MockResolver {
}
export async function createTestingModule(
moduleDef: TestingModuleMeatdata = {}
moduleDef: TestingModuleMeatdata = {},
init = true
) {
// setting up
let imports = moduleDef.imports ?? [];
@@ -105,11 +106,19 @@ export async function createTestingModule(
await initTestingDB(prisma);
}
if (init) {
await m.init();
const config = m.get(Config);
// by pass password min length validation
await config.runtime.set('auth/password.min', 1);
}
return m;
}
export async function createTestingApp(moduleDef: TestingModuleMeatdata = {}) {
const m = await createTestingModule(moduleDef);
const m = await createTestingModule(moduleDef, false);
const app = m.createNestApplication({
cors: true,
@@ -134,6 +143,10 @@ export async function createTestingApp(moduleDef: TestingModuleMeatdata = {}) {
await app.init();
const config = app.get(Config);
// by pass password min length validation
await config.runtime.set('auth/password.min', 1);
return {
module: m,
app,