mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-18 09:04:44 -04:00
Merge pull request #1092 from hedgedoc/fix/e2eTests
This commit is contained in:
commit
ee5a587bcc
10 changed files with 33 additions and 23 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -41,3 +41,4 @@ dist
|
|||
public/uploads/*
|
||||
!public/uploads/.gitkeep
|
||||
uploads
|
||||
test_uploads
|
||||
|
|
|
@ -13,6 +13,5 @@
|
|||
"^.+\\.(t|j)s$": "ts-jest"
|
||||
},
|
||||
"coverageDirectory": "./coverage-e2e",
|
||||
"testTimeout": 10000,
|
||||
"maxConcurrency": 1
|
||||
"testTimeout": 10000
|
||||
}
|
||||
|
|
|
@ -20,8 +20,8 @@
|
|||
"test:watch": "jest --watch",
|
||||
"test:cov": "jest --coverage",
|
||||
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
|
||||
"test:e2e": "jest --config jest-e2e.json",
|
||||
"test:e2e:cov": "jest --config jest-e2e.json --coverage"
|
||||
"test:e2e": "jest --config jest-e2e.json --runInBand",
|
||||
"test:e2e:cov": "jest --config jest-e2e.json --coverage --runInBand"
|
||||
},
|
||||
"dependencies": {
|
||||
"@azure/storage-blob": "12.5.0",
|
||||
|
|
|
@ -10,7 +10,7 @@ export default registerAs('mediaConfig', () => ({
|
|||
backend: {
|
||||
use: 'filesystem',
|
||||
filesystem: {
|
||||
uploadPath: 'uploads',
|
||||
uploadPath: 'test_uploads',
|
||||
},
|
||||
},
|
||||
}));
|
||||
|
|
|
@ -36,7 +36,7 @@ export class FilesystemBackend implements MediaBackend {
|
|||
await this.ensureDirectory();
|
||||
try {
|
||||
await fs.writeFile(filePath, buffer, null);
|
||||
return ['/' + filePath, null];
|
||||
return ['/uploads/' + fileName, null];
|
||||
} catch (e) {
|
||||
this.logger.error((e as Error).message, (e as Error).stack, 'saveFile');
|
||||
throw new MediaBackendError(`Could not save '${filePath}'`);
|
||||
|
|
|
@ -93,19 +93,22 @@ describe('Media', () => {
|
|||
const testImage = await fs.readFile('test/private-api/fixtures/test.png');
|
||||
const downloadResponse = await request(app.getHttpServer()).get(path);
|
||||
expect(downloadResponse.body).toEqual(testImage);
|
||||
// Remove /upload/ from path as we just need the filename.
|
||||
// Remove /uploads/ from path as we just need the filename.
|
||||
const fileName = path.replace('/uploads/', '');
|
||||
// delete the file afterwards
|
||||
await fs.unlink(join(uploadPath, fileName));
|
||||
});
|
||||
describe('fails:', () => {
|
||||
beforeEach(async () => {
|
||||
await fs.rmdir(uploadPath, { recursive: true });
|
||||
});
|
||||
it('MIME type not supported', async () => {
|
||||
await request(app.getHttpServer())
|
||||
.post('/media')
|
||||
.attach('file', 'test/private-api/fixtures/test.zip')
|
||||
.set('HedgeDoc-Note', 'test_upload_media')
|
||||
.expect(400);
|
||||
expect(await fs.access(uploadPath)).toBeFalsy();
|
||||
await expect(fs.access(uploadPath)).rejects.toBeDefined();
|
||||
});
|
||||
it('note does not exist', async () => {
|
||||
await request(app.getHttpServer())
|
||||
|
@ -113,10 +116,9 @@ describe('Media', () => {
|
|||
.attach('file', 'test/private-api/fixtures/test.zip')
|
||||
.set('HedgeDoc-Note', 'i_dont_exist')
|
||||
.expect(400);
|
||||
expect(await fs.access(uploadPath)).toBeFalsy();
|
||||
await expect(fs.access(uploadPath)).rejects.toBeDefined();
|
||||
});
|
||||
it('mediaBackend error', async () => {
|
||||
await fs.rmdir(uploadPath);
|
||||
await fs.mkdir(uploadPath, {
|
||||
mode: '444',
|
||||
});
|
||||
|
@ -126,13 +128,16 @@ describe('Media', () => {
|
|||
.set('HedgeDoc-Note', 'test_upload_media')
|
||||
.expect('Content-Type', /json/)
|
||||
.expect(500);
|
||||
await fs.rmdir(uploadPath);
|
||||
});
|
||||
afterEach(async () => {
|
||||
await fs.rmdir(uploadPath, { recursive: true });
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
// Delete the upload folder
|
||||
await fs.rmdir(uploadPath);
|
||||
await fs.rmdir(uploadPath, { recursive: true });
|
||||
await app.close();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -63,7 +63,7 @@ describe('Notes', () => {
|
|||
GroupsModule,
|
||||
TypeOrmModule.forRoot({
|
||||
type: 'sqlite',
|
||||
database: './hedgedoc-e2e-notes.sqlite',
|
||||
database: './hedgedoc-e2e-private-notes.sqlite',
|
||||
autoLoadEntities: true,
|
||||
synchronize: true,
|
||||
dropSchema: true,
|
||||
|
@ -236,7 +236,7 @@ describe('Notes', () => {
|
|||
.expect(200);
|
||||
expect(response.body).toHaveLength(0);
|
||||
|
||||
const testImage = await fs.readFile('test/public-api/fixtures/test.png');
|
||||
const testImage = await fs.readFile('test/private-api/fixtures/test.png');
|
||||
const url0 = await mediaService.saveFile(testImage, 'hardcoded', note.id);
|
||||
const url1 = await mediaService.saveFile(
|
||||
testImage,
|
||||
|
@ -256,7 +256,7 @@ describe('Notes', () => {
|
|||
// delete the file afterwards
|
||||
await fs.unlink(join(uploadPath, fileName));
|
||||
}
|
||||
await fs.rmdir(uploadPath);
|
||||
await fs.rmdir(uploadPath, { recursive: true });
|
||||
});
|
||||
it('fails, when note does not exist', async () => {
|
||||
await request(app.getHttpServer())
|
||||
|
|
|
@ -270,7 +270,7 @@ describe('Me', () => {
|
|||
// delete the file afterwards
|
||||
await fs.unlink(join(uploadPath, fileName));
|
||||
}
|
||||
await fs.rmdir(uploadPath);
|
||||
await fs.rmdir(uploadPath, { recursive: true });
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
|
|
|
@ -89,19 +89,22 @@ describe('Media', () => {
|
|||
const testImage = await fs.readFile('test/public-api/fixtures/test.png');
|
||||
const downloadResponse = await request(app.getHttpServer()).get(path);
|
||||
expect(downloadResponse.body).toEqual(testImage);
|
||||
// Remove /upload/ from path as we just need the filename.
|
||||
// Remove /uploads/ from path as we just need the filename.
|
||||
const fileName = path.replace('/uploads/', '');
|
||||
// delete the file afterwards
|
||||
await fs.unlink(join(uploadPath, fileName));
|
||||
});
|
||||
describe('fails:', () => {
|
||||
beforeEach(async () => {
|
||||
await fs.rmdir(uploadPath, { recursive: true });
|
||||
});
|
||||
it('MIME type not supported', async () => {
|
||||
await request(app.getHttpServer())
|
||||
.post('/media')
|
||||
.attach('file', 'test/public-api/fixtures/test.zip')
|
||||
.set('HedgeDoc-Note', 'test_upload_media')
|
||||
.expect(400);
|
||||
expect(await fs.access(uploadPath)).toBeFalsy();
|
||||
await expect(fs.access(uploadPath)).rejects.toBeDefined();
|
||||
});
|
||||
it('note does not exist', async () => {
|
||||
await request(app.getHttpServer())
|
||||
|
@ -109,10 +112,9 @@ describe('Media', () => {
|
|||
.attach('file', 'test/public-api/fixtures/test.zip')
|
||||
.set('HedgeDoc-Note', 'i_dont_exist')
|
||||
.expect(400);
|
||||
expect(await fs.access(uploadPath)).toBeFalsy();
|
||||
await expect(fs.access(uploadPath)).rejects.toBeDefined();
|
||||
});
|
||||
it('mediaBackend error', async () => {
|
||||
await fs.rmdir(uploadPath);
|
||||
await fs.mkdir(uploadPath, {
|
||||
mode: '444',
|
||||
});
|
||||
|
@ -122,7 +124,9 @@ describe('Media', () => {
|
|||
.set('HedgeDoc-Note', 'test_upload_media')
|
||||
.expect('Content-Type', /json/)
|
||||
.expect(500);
|
||||
await fs.rmdir(uploadPath);
|
||||
});
|
||||
afterEach(async () => {
|
||||
await fs.rmdir(uploadPath, { recursive: true });
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -142,6 +146,7 @@ describe('Media', () => {
|
|||
|
||||
afterAll(async () => {
|
||||
// Delete the upload folder
|
||||
await fs.rmdir(uploadPath);
|
||||
await fs.rmdir(uploadPath, { recursive: true });
|
||||
await app.close();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -362,7 +362,7 @@ describe('Notes', () => {
|
|||
// delete the file afterwards
|
||||
await fs.unlink(join(uploadPath, fileName));
|
||||
}
|
||||
await fs.rmdir(uploadPath);
|
||||
await fs.rmdir(uploadPath, { recursive: true });
|
||||
});
|
||||
it('fails, when note does not exist', async () => {
|
||||
await request(app.getHttpServer())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue