mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-23 02:06:29 -05:00
Separate private and public API in TestSetup
Including both PublicApiModule and PrivateApiModule in the test setup lead to the API routes overwriting each other. This adds a router to separate the APIs as they are in the normal app. Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
parent
0bb333ca69
commit
4428f3fb39
2 changed files with 26 additions and 12 deletions
|
@ -30,7 +30,7 @@ describe('Tokens', () => {
|
|||
|
||||
agent = request.agent(testSetup.app.getHttpServer());
|
||||
await agent
|
||||
.post('/auth/local/login')
|
||||
.post('/api/private/auth/local/login')
|
||||
.send({ username: 'hardcoded', password: 'test' })
|
||||
.expect(201);
|
||||
});
|
||||
|
@ -38,7 +38,7 @@ describe('Tokens', () => {
|
|||
it(`POST /tokens`, async () => {
|
||||
const tokenName = 'testToken';
|
||||
const response = await agent
|
||||
.post('/tokens')
|
||||
.post('/api/private/tokens')
|
||||
.send({
|
||||
label: tokenName,
|
||||
})
|
||||
|
@ -54,7 +54,7 @@ describe('Tokens', () => {
|
|||
it(`GET /tokens`, async () => {
|
||||
const tokenName = 'testToken';
|
||||
const response = await agent
|
||||
.get('/tokens/')
|
||||
.get('/api/private/tokens/')
|
||||
.expect('Content-Type', /json/)
|
||||
.expect(200);
|
||||
expect(response.body[0].label).toBe(tokenName);
|
||||
|
@ -63,12 +63,14 @@ describe('Tokens', () => {
|
|||
expect(response.body[0].secret).not.toBeDefined();
|
||||
});
|
||||
it(`DELETE /tokens/:keyid`, async () => {
|
||||
const response = await agent.delete('/tokens/' + keyId).expect(204);
|
||||
const response = await agent
|
||||
.delete('/api/private/tokens/' + keyId)
|
||||
.expect(204);
|
||||
expect(response.body).toStrictEqual({});
|
||||
});
|
||||
it(`GET /tokens 2`, async () => {
|
||||
const response = await agent
|
||||
.get('/tokens/')
|
||||
.get('/api/private/tokens/')
|
||||
.expect('Content-Type', /json/)
|
||||
.expect(200);
|
||||
expect(response.body).toStrictEqual([]);
|
|
@ -7,6 +7,7 @@ import { ConfigModule, ConfigService } from '@nestjs/config';
|
|||
import { NestExpressApplication } from '@nestjs/platform-express';
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { RouterModule, Routes } from 'nest-router';
|
||||
|
||||
import { PrivateApiModule } from '../src/api/private/private-api.module';
|
||||
import { PublicApiModule } from '../src/api/public/public-api.module';
|
||||
|
@ -46,9 +47,27 @@ export class TestSetup {
|
|||
|
||||
public static async create(): Promise<TestSetup> {
|
||||
const testSetup = new TestSetup();
|
||||
const routes: Routes = [
|
||||
{
|
||||
path: '/api/v2',
|
||||
module: PublicApiModule,
|
||||
},
|
||||
{
|
||||
path: '/api/private',
|
||||
module: PrivateApiModule,
|
||||
},
|
||||
];
|
||||
|
||||
testSetup.moduleRef = await Test.createTestingModule({
|
||||
imports: [
|
||||
RouterModule.forRoutes(routes),
|
||||
TypeOrmModule.forRoot({
|
||||
type: 'sqlite',
|
||||
database: ':memory:',
|
||||
autoLoadEntities: true,
|
||||
synchronize: true,
|
||||
dropSchema: true,
|
||||
}),
|
||||
ConfigModule.forRoot({
|
||||
isGlobal: true,
|
||||
load: [
|
||||
|
@ -64,13 +83,6 @@ export class TestSetup {
|
|||
NotesModule,
|
||||
PermissionsModule,
|
||||
GroupsModule,
|
||||
TypeOrmModule.forRoot({
|
||||
type: 'sqlite',
|
||||
database: ':memory:',
|
||||
autoLoadEntities: true,
|
||||
synchronize: true,
|
||||
dropSchema: true,
|
||||
}),
|
||||
LoggerModule,
|
||||
AuthModule,
|
||||
UsersModule,
|
||||
|
|
Loading…
Reference in a new issue