mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-17 16:44:49 -04:00
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:
parent
341e3a3e5a
commit
fe26f1689c
9 changed files with 72 additions and 118 deletions
|
@ -22,15 +22,20 @@ import { ConsoleLoggerService } from '../../src/logger/console-logger.service';
|
|||
import { LoggerModule } from '../../src/logger/logger.module';
|
||||
import { MediaModule } from '../../src/media/media.module';
|
||||
import { MediaService } from '../../src/media/media.service';
|
||||
import { Note } from '../../src/notes/note.entity';
|
||||
import { NotesModule } from '../../src/notes/notes.module';
|
||||
import { NotesService } from '../../src/notes/notes.service';
|
||||
import { PermissionsModule } from '../../src/permissions/permissions.module';
|
||||
import { User } from '../../src/users/user.entity';
|
||||
import { UsersService } from '../../src/users/users.service';
|
||||
import { ensureDeleted } from '../utils';
|
||||
|
||||
describe('Media', () => {
|
||||
let app: NestExpressApplication;
|
||||
let mediaService: MediaService;
|
||||
let uploadPath: string;
|
||||
let testNote: Note;
|
||||
let user: User;
|
||||
|
||||
beforeAll(async () => {
|
||||
const moduleRef = await Test.createTestingModule({
|
||||
|
@ -69,7 +74,12 @@ describe('Media', () => {
|
|||
logger.log('Switching logger', 'AppBootstrap');
|
||||
app.useLogger(logger);
|
||||
const notesService: NotesService = moduleRef.get(NotesService);
|
||||
await notesService.createNote('test content', 'test_upload_media');
|
||||
const userService = moduleRef.get(UsersService);
|
||||
user = await userService.createUser('hardcoded', 'Testy');
|
||||
testNote = await notesService.createNote(
|
||||
'test content',
|
||||
'test_upload_media',
|
||||
);
|
||||
mediaService = moduleRef.get(MediaService);
|
||||
});
|
||||
|
||||
|
@ -129,11 +139,7 @@ describe('Media', () => {
|
|||
|
||||
it('DELETE /media/{filename}', async () => {
|
||||
const testImage = await fs.readFile('test/public-api/fixtures/test.png');
|
||||
const url = await mediaService.saveFile(
|
||||
testImage,
|
||||
'hardcoded',
|
||||
'test_upload_media',
|
||||
);
|
||||
const url = await mediaService.saveFile(testImage, user, testNote);
|
||||
const filename = url.split('/').pop() || '';
|
||||
await request(app.getHttpServer())
|
||||
.delete('/media/' + filename)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue