mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-13 06:34:39 -04:00
refactor(api/private/media): return MediaUpload object instead of url
This ensures the private POST /media API behaves in the same way as /me/media Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
parent
4f10e17d40
commit
8e31f3a393
10 changed files with 50 additions and 43 deletions
|
@ -161,7 +161,7 @@ describe('Notes', () => {
|
|||
user,
|
||||
noteId,
|
||||
);
|
||||
const url = await testSetup.mediaService.saveFile(
|
||||
const upload = await testSetup.mediaService.saveFile(
|
||||
testImage,
|
||||
user,
|
||||
note,
|
||||
|
@ -182,7 +182,7 @@ describe('Notes', () => {
|
|||
await testSetup.mediaService.listUploadsByUser(user),
|
||||
).toHaveLength(1);
|
||||
// Remove /upload/ from path as we just need the filename.
|
||||
const fileName = url.replace('/uploads/', '');
|
||||
const fileName = upload.fileUrl.replace('/uploads/', '');
|
||||
// delete the file afterwards
|
||||
await fs.unlink(join(uploadPath, fileName));
|
||||
await fs.rmdir(uploadPath);
|
||||
|
@ -308,12 +308,12 @@ describe('Notes', () => {
|
|||
expect(response.body).toHaveLength(0);
|
||||
|
||||
const testImage = await fs.readFile('test/private-api/fixtures/test.png');
|
||||
const url0 = await testSetup.mediaService.saveFile(
|
||||
const upload0 = await testSetup.mediaService.saveFile(
|
||||
testImage,
|
||||
user,
|
||||
note1,
|
||||
);
|
||||
const url1 = await testSetup.mediaService.saveFile(
|
||||
const upload1 = await testSetup.mediaService.saveFile(
|
||||
testImage,
|
||||
user,
|
||||
note2,
|
||||
|
@ -324,10 +324,10 @@ describe('Notes', () => {
|
|||
.expect('Content-Type', /json/)
|
||||
.expect(200);
|
||||
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/', '');
|
||||
expect(responseAfter.body[0].url).toEqual(upload0.fileUrl);
|
||||
expect(responseAfter.body[0].url).not.toEqual(upload1.fileUrl);
|
||||
for (const upload of [upload0, upload1]) {
|
||||
const fileName = upload.fileUrl.replace('/uploads/', '');
|
||||
// delete the file afterwards
|
||||
await fs.unlink(join(uploadPath, fileName));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue