MediaService: Refactor saveFile

The function now expects a `Note` object instead of a noteId
and a `User` instead of a username to
make it more consistent with other functions.

Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
David Mehren 2021-08-29 22:28:21 +02:00
parent 341e3a3e5a
commit fe26f1689c
No known key found for this signature in database
GPG key ID: 185982BA4C42B7C3
9 changed files with 72 additions and 118 deletions

View file

@ -161,8 +161,8 @@ describe('Notes', () => {
describe('works', () => {
it('with an existing alias and keepMedia false', async () => {
const noteId = 'test3';
await notesService.createNote(content, noteId, user);
await mediaService.saveFile(testImage, user.userName, noteId);
const note = await notesService.createNote(content, noteId, user);
await mediaService.saveFile(testImage, user, note);
await request(app.getHttpServer())
.delete(`/notes/${noteId}`)
.set('Content-Type', 'application/json')
@ -177,12 +177,8 @@ describe('Notes', () => {
});
it('with an existing alias and keepMedia true', async () => {
const noteId = 'test3a';
await notesService.createNote(content, noteId, user);
const url = await mediaService.saveFile(
testImage,
user.userName,
noteId,
);
const note = await notesService.createNote(content, noteId, user);
const url = await mediaService.saveFile(testImage, user, note);
await request(app.getHttpServer())
.delete(`/notes/${noteId}`)
.set('Content-Type', 'application/json')
@ -402,8 +398,8 @@ describe('Notes', () => {
it('works', async () => {
const alias = 'test9';
const extraAlias = 'test10';
await notesService.createNote(content, alias, user);
await notesService.createNote(content, extraAlias, user);
const note1 = await notesService.createNote(content, alias, user);
const note2 = await notesService.createNote(content, extraAlias, user);
const httpServer = app.getHttpServer();
const response = await request(httpServer)
.get(`/notes/${alias}/media/`)
@ -412,12 +408,8 @@ describe('Notes', () => {
expect(response.body).toHaveLength(0);
const testImage = await fs.readFile('test/public-api/fixtures/test.png');
const url0 = await mediaService.saveFile(testImage, 'hardcoded', alias);
const url1 = await mediaService.saveFile(
testImage,
'hardcoded',
extraAlias,
);
const url0 = await mediaService.saveFile(testImage, user, note1);
const url1 = await mediaService.saveFile(testImage, user, note2);
const responseAfter = await request(httpServer)
.get(`/notes/${alias}/media/`)