mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-23 02:06:29 -05:00
PublicE2E: Remove uploaded files after test
This way the tests can run in any order as some of the media tests rely on an empty (or non-existing) uploads directory. Also the me e2e test was renamed to the correct name. Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
parent
6e03f876db
commit
69550a8243
2 changed files with 21 additions and 2 deletions
|
@ -29,7 +29,7 @@ import { LoggerModule } from '../../src/logger/logger.module';
|
|||
import { AuthModule } from '../../src/auth/auth.module';
|
||||
import { UsersModule } from '../../src/users/users.module';
|
||||
import { HistoryModule } from '../../src/history/history.module';
|
||||
import { ConfigModule } from '@nestjs/config';
|
||||
import { ConfigModule, ConfigService } from '@nestjs/config';
|
||||
import mediaConfigMock from '../../src/config/mock/media.config.mock';
|
||||
import appConfigMock from '../../src/config/mock/app.config.mock';
|
||||
import { User } from '../../src/users/user.entity';
|
||||
|
@ -37,15 +37,17 @@ import { MediaService } from '../../src/media/media.service';
|
|||
import { MediaModule } from '../../src/media/media.module';
|
||||
import { promises as fs } from 'fs';
|
||||
import { NoteMetadataDto } from '../../src/notes/note-metadata.dto';
|
||||
import { join } from 'path';
|
||||
|
||||
// TODO Tests have to be reworked using UserService functions
|
||||
|
||||
describe('Notes', () => {
|
||||
describe('Me', () => {
|
||||
let app: INestApplication;
|
||||
let historyService: HistoryService;
|
||||
let notesService: NotesService;
|
||||
let userService: UsersService;
|
||||
let mediaService: MediaService;
|
||||
let uploadPath: string;
|
||||
let user: User;
|
||||
|
||||
beforeAll(async () => {
|
||||
|
@ -76,6 +78,8 @@ describe('Notes', () => {
|
|||
.overrideGuard(TokenAuthGuard)
|
||||
.useClass(MockAuthGuard)
|
||||
.compile();
|
||||
const config = moduleRef.get<ConfigService>(ConfigService);
|
||||
uploadPath = config.get('mediaConfig').backend.filesystem.uploadPath;
|
||||
app = moduleRef.createNestApplication();
|
||||
notesService = moduleRef.get(NotesService);
|
||||
historyService = moduleRef.get(HistoryService);
|
||||
|
@ -261,6 +265,12 @@ describe('Notes', () => {
|
|||
expect(response.body[1].url).toEqual(url1);
|
||||
expect(response.body[2].url).toEqual(url2);
|
||||
expect(response.body[3].url).toEqual(url3);
|
||||
for (const fileUrl of [url0, url1, url2, url3]) {
|
||||
const fileName = fileUrl.replace('/uploads/', '');
|
||||
// delete the file afterwards
|
||||
await fs.unlink(join(uploadPath, fileName));
|
||||
}
|
||||
await fs.rmdir(uploadPath);
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
|
|
|
@ -31,6 +31,7 @@ import { User } from '../../src/users/user.entity';
|
|||
import { UsersModule } from '../../src/users/users.module';
|
||||
import { promises as fs } from 'fs';
|
||||
import { MediaService } from '../../src/media/media.service';
|
||||
import { join } from 'path';
|
||||
|
||||
describe('Notes', () => {
|
||||
let app: INestApplication;
|
||||
|
@ -40,6 +41,7 @@ describe('Notes', () => {
|
|||
let user2: User;
|
||||
let content: string;
|
||||
let forbiddenNoteId: string;
|
||||
let uploadPath: string;
|
||||
|
||||
beforeAll(async () => {
|
||||
const moduleRef = await Test.createTestingModule({
|
||||
|
@ -70,6 +72,7 @@ describe('Notes', () => {
|
|||
|
||||
const config = moduleRef.get<ConfigService>(ConfigService);
|
||||
forbiddenNoteId = config.get('appConfig').forbiddenNoteIds[0];
|
||||
uploadPath = config.get('mediaConfig').backend.filesystem.uploadPath;
|
||||
app = moduleRef.createNestApplication();
|
||||
await app.init();
|
||||
notesService = moduleRef.get(NotesService);
|
||||
|
@ -354,6 +357,12 @@ describe('Notes', () => {
|
|||
expect(responseAfter.body).toHaveLength(1);
|
||||
expect(responseAfter.body[0].url).toEqual(url0);
|
||||
expect(responseAfter.body[0].url).not.toEqual(url1);
|
||||
for (const fileUrl of [url0, url1]) {
|
||||
const fileName = fileUrl.replace('/uploads/', '');
|
||||
// delete the file afterwards
|
||||
await fs.unlink(join(uploadPath, fileName));
|
||||
}
|
||||
await fs.rmdir(uploadPath);
|
||||
});
|
||||
it('fails, when note does not exist', async () => {
|
||||
await request(app.getHttpServer())
|
||||
|
|
Loading…
Reference in a new issue