mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-14 15:14:56 -04:00
chore(test): Change test to work with publicId
Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
parent
b7e52f8166
commit
0f58757858
5 changed files with 74 additions and 38 deletions
|
@ -684,7 +684,7 @@ describe('NotesService', () => {
|
||||||
];
|
];
|
||||||
revisions[0].createdAt = new Date(1549312452000);
|
revisions[0].createdAt = new Date(1549312452000);
|
||||||
jest.spyOn(revisionRepo, 'findOne').mockResolvedValue(revisions[0]);
|
jest.spyOn(revisionRepo, 'findOne').mockResolvedValue(revisions[0]);
|
||||||
note.id = 'testId';
|
note.publicId = 'testId';
|
||||||
note.alias = 'testAlias';
|
note.alias = 'testAlias';
|
||||||
note.title = 'testTitle';
|
note.title = 'testTitle';
|
||||||
note.description = 'testDescription';
|
note.description = 'testDescription';
|
||||||
|
@ -719,7 +719,7 @@ describe('NotesService', () => {
|
||||||
];
|
];
|
||||||
note.viewCount = 1337;
|
note.viewCount = 1337;
|
||||||
const metadataDto = await service.toNoteMetadataDto(note);
|
const metadataDto = await service.toNoteMetadataDto(note);
|
||||||
expect(metadataDto.id).toEqual(note.id);
|
expect(metadataDto.id).toEqual(note.publicId);
|
||||||
expect(metadataDto.alias).toEqual(note.alias);
|
expect(metadataDto.alias).toEqual(note.alias);
|
||||||
expect(metadataDto.title).toEqual(note.title);
|
expect(metadataDto.title).toEqual(note.title);
|
||||||
expect(metadataDto.createTime).toEqual(revisions[0].createdAt);
|
expect(metadataDto.createTime).toEqual(revisions[0].createdAt);
|
||||||
|
@ -778,7 +778,7 @@ describe('NotesService', () => {
|
||||||
.spyOn(revisionRepo, 'findOne')
|
.spyOn(revisionRepo, 'findOne')
|
||||||
.mockResolvedValue(revisions[0])
|
.mockResolvedValue(revisions[0])
|
||||||
.mockResolvedValue(revisions[0]);
|
.mockResolvedValue(revisions[0]);
|
||||||
note.id = 'testId';
|
note.publicId = 'testId';
|
||||||
note.alias = 'testAlias';
|
note.alias = 'testAlias';
|
||||||
note.title = 'testTitle';
|
note.title = 'testTitle';
|
||||||
note.description = 'testDescription';
|
note.description = 'testDescription';
|
||||||
|
@ -813,7 +813,7 @@ describe('NotesService', () => {
|
||||||
];
|
];
|
||||||
note.viewCount = 1337;
|
note.viewCount = 1337;
|
||||||
const noteDto = await service.toNoteDto(note);
|
const noteDto = await service.toNoteDto(note);
|
||||||
expect(noteDto.metadata.id).toEqual(note.id);
|
expect(noteDto.metadata.id).toEqual(note.publicId);
|
||||||
expect(noteDto.metadata.alias).toEqual(note.alias);
|
expect(noteDto.metadata.alias).toEqual(note.alias);
|
||||||
expect(noteDto.metadata.title).toEqual(note.title);
|
expect(noteDto.metadata.title).toEqual(note.title);
|
||||||
expect(noteDto.metadata.createTime).toEqual(revisions[0].createdAt);
|
expect(noteDto.metadata.createTime).toEqual(revisions[0].createdAt);
|
||||||
|
|
|
@ -111,10 +111,26 @@ describe('Me', () => {
|
||||||
expect(responseBefore.body).toHaveLength(0);
|
expect(responseBefore.body).toHaveLength(0);
|
||||||
|
|
||||||
const testImage = await fs.readFile('test/public-api/fixtures/test.png');
|
const testImage = await fs.readFile('test/public-api/fixtures/test.png');
|
||||||
const url0 = await mediaService.saveFile(testImage, 'hardcoded', note1.id);
|
const url0 = await mediaService.saveFile(
|
||||||
const url1 = await mediaService.saveFile(testImage, 'hardcoded', note1.id);
|
testImage,
|
||||||
const url2 = await mediaService.saveFile(testImage, 'hardcoded', note2.id);
|
'hardcoded',
|
||||||
const url3 = await mediaService.saveFile(testImage, 'hardcoded', note2.id);
|
note1.publicId,
|
||||||
|
);
|
||||||
|
const url1 = await mediaService.saveFile(
|
||||||
|
testImage,
|
||||||
|
'hardcoded',
|
||||||
|
note1.publicId,
|
||||||
|
);
|
||||||
|
const url2 = await mediaService.saveFile(
|
||||||
|
testImage,
|
||||||
|
'hardcoded',
|
||||||
|
note2.alias ?? '',
|
||||||
|
);
|
||||||
|
const url3 = await mediaService.saveFile(
|
||||||
|
testImage,
|
||||||
|
'hardcoded',
|
||||||
|
note2.alias ?? '',
|
||||||
|
);
|
||||||
|
|
||||||
const response = await request(httpServer)
|
const response = await request(httpServer)
|
||||||
.get('/me/media/')
|
.get('/me/media/')
|
||||||
|
@ -147,7 +163,11 @@ describe('Me', () => {
|
||||||
|
|
||||||
it('DELETE /me', async () => {
|
it('DELETE /me', async () => {
|
||||||
const testImage = await fs.readFile('test/public-api/fixtures/test.png');
|
const testImage = await fs.readFile('test/public-api/fixtures/test.png');
|
||||||
const url0 = await mediaService.saveFile(testImage, 'hardcoded', note1.id);
|
const url0 = await mediaService.saveFile(
|
||||||
|
testImage,
|
||||||
|
'hardcoded',
|
||||||
|
note1.publicId,
|
||||||
|
);
|
||||||
const dbUser = await userService.getUserByUsername('hardcoded');
|
const dbUser = await userService.getUserByUsername('hardcoded');
|
||||||
expect(dbUser).toBeInstanceOf(User);
|
expect(dbUser).toBeInstanceOf(User);
|
||||||
const mediaUploads = await mediaService.listUploadsByUser(dbUser);
|
const mediaUploads = await mediaService.listUploadsByUser(dbUser);
|
||||||
|
|
|
@ -261,25 +261,27 @@ describe('Notes', () => {
|
||||||
|
|
||||||
describe('GET /notes/{note}/media', () => {
|
describe('GET /notes/{note}/media', () => {
|
||||||
it('works', async () => {
|
it('works', async () => {
|
||||||
const note = await notesService.createNote(content, 'test6', user);
|
const alias = 'test6';
|
||||||
const extraNote = await notesService.createNote(content, 'test7', user);
|
const extraAlias = 'test7';
|
||||||
|
await notesService.createNote(content, alias, user);
|
||||||
|
await notesService.createNote(content, extraAlias, user);
|
||||||
const httpServer = app.getHttpServer();
|
const httpServer = app.getHttpServer();
|
||||||
const response = await request(httpServer)
|
const response = await request(httpServer)
|
||||||
.get(`/notes/${note.id}/media/`)
|
.get(`/notes/${alias}/media/`)
|
||||||
.expect('Content-Type', /json/)
|
.expect('Content-Type', /json/)
|
||||||
.expect(200);
|
.expect(200);
|
||||||
expect(response.body).toHaveLength(0);
|
expect(response.body).toHaveLength(0);
|
||||||
|
|
||||||
const testImage = await fs.readFile('test/private-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 url0 = await mediaService.saveFile(testImage, 'hardcoded', alias);
|
||||||
const url1 = await mediaService.saveFile(
|
const url1 = await mediaService.saveFile(
|
||||||
testImage,
|
testImage,
|
||||||
'hardcoded',
|
'hardcoded',
|
||||||
extraNote.id,
|
extraAlias,
|
||||||
);
|
);
|
||||||
|
|
||||||
const responseAfter = await request(httpServer)
|
const responseAfter = await request(httpServer)
|
||||||
.get(`/notes/${note.id}/media/`)
|
.get(`/notes/${alias}/media/`)
|
||||||
.expect('Content-Type', /json/)
|
.expect('Content-Type', /json/)
|
||||||
.expect(200);
|
.expect(200);
|
||||||
expect(responseAfter.body).toHaveLength(1);
|
expect(responseAfter.body).toHaveLength(1);
|
||||||
|
@ -299,13 +301,10 @@ describe('Notes', () => {
|
||||||
.expect(404);
|
.expect(404);
|
||||||
});
|
});
|
||||||
it("fails, when user can't read note", async () => {
|
it("fails, when user can't read note", async () => {
|
||||||
const note = await notesService.createNote(
|
const alias = 'test11';
|
||||||
'This is a test note.',
|
await notesService.createNote('This is a test note.', alias, user2);
|
||||||
'test11',
|
|
||||||
user2,
|
|
||||||
);
|
|
||||||
await request(app.getHttpServer())
|
await request(app.getHttpServer())
|
||||||
.get(`/notes/${note.id}/media/`)
|
.get(`/notes/${alias}/media/`)
|
||||||
.expect('Content-Type', /json/)
|
.expect('Content-Type', /json/)
|
||||||
.expect(401);
|
.expect(401);
|
||||||
});
|
});
|
||||||
|
|
|
@ -243,10 +243,26 @@ describe('Me', () => {
|
||||||
expect(response1.body).toHaveLength(0);
|
expect(response1.body).toHaveLength(0);
|
||||||
|
|
||||||
const testImage = await fs.readFile('test/public-api/fixtures/test.png');
|
const testImage = await fs.readFile('test/public-api/fixtures/test.png');
|
||||||
const url0 = await mediaService.saveFile(testImage, 'hardcoded', note1.id);
|
const url0 = await mediaService.saveFile(
|
||||||
const url1 = await mediaService.saveFile(testImage, 'hardcoded', note1.id);
|
testImage,
|
||||||
const url2 = await mediaService.saveFile(testImage, 'hardcoded', note2.id);
|
'hardcoded',
|
||||||
const url3 = await mediaService.saveFile(testImage, 'hardcoded', note2.id);
|
note1.publicId,
|
||||||
|
);
|
||||||
|
const url1 = await mediaService.saveFile(
|
||||||
|
testImage,
|
||||||
|
'hardcoded',
|
||||||
|
note1.publicId,
|
||||||
|
);
|
||||||
|
const url2 = await mediaService.saveFile(
|
||||||
|
testImage,
|
||||||
|
'hardcoded',
|
||||||
|
note2.publicId,
|
||||||
|
);
|
||||||
|
const url3 = await mediaService.saveFile(
|
||||||
|
testImage,
|
||||||
|
'hardcoded',
|
||||||
|
note2.publicId,
|
||||||
|
);
|
||||||
|
|
||||||
const response = await request(httpServer)
|
const response = await request(httpServer)
|
||||||
.get('/me/media/')
|
.get('/me/media/')
|
||||||
|
|
|
@ -204,7 +204,9 @@ describe('Notes', () => {
|
||||||
];
|
];
|
||||||
updateNotePermission.sharedToGroups = [];
|
updateNotePermission.sharedToGroups = [];
|
||||||
await notesService.updateNotePermissions(note, updateNotePermission);
|
await notesService.updateNotePermissions(note, updateNotePermission);
|
||||||
const updatedNote = await notesService.getNoteByIdOrAlias(note.alias);
|
const updatedNote = await notesService.getNoteByIdOrAlias(
|
||||||
|
note.alias ?? '',
|
||||||
|
);
|
||||||
expect(updatedNote.userPermissions).toHaveLength(1);
|
expect(updatedNote.userPermissions).toHaveLength(1);
|
||||||
expect(updatedNote.userPermissions[0].canEdit).toEqual(
|
expect(updatedNote.userPermissions[0].canEdit).toEqual(
|
||||||
updateNotePermission.sharedToUsers[0].canEdit,
|
updateNotePermission.sharedToUsers[0].canEdit,
|
||||||
|
@ -391,25 +393,27 @@ describe('Notes', () => {
|
||||||
|
|
||||||
describe('GET /notes/{note}/media', () => {
|
describe('GET /notes/{note}/media', () => {
|
||||||
it('works', async () => {
|
it('works', async () => {
|
||||||
const note = await notesService.createNote(content, 'test9', user);
|
const alias = 'test9';
|
||||||
const extraNote = await notesService.createNote(content, 'test10', user);
|
const extraAlias = 'test10';
|
||||||
|
await notesService.createNote(content, alias, user);
|
||||||
|
await notesService.createNote(content, extraAlias, user);
|
||||||
const httpServer = app.getHttpServer();
|
const httpServer = app.getHttpServer();
|
||||||
const response = await request(httpServer)
|
const response = await request(httpServer)
|
||||||
.get(`/notes/${note.id}/media/`)
|
.get(`/notes/${alias}/media/`)
|
||||||
.expect('Content-Type', /json/)
|
.expect('Content-Type', /json/)
|
||||||
.expect(200);
|
.expect(200);
|
||||||
expect(response.body).toHaveLength(0);
|
expect(response.body).toHaveLength(0);
|
||||||
|
|
||||||
const testImage = await fs.readFile('test/public-api/fixtures/test.png');
|
const testImage = await fs.readFile('test/public-api/fixtures/test.png');
|
||||||
const url0 = await mediaService.saveFile(testImage, 'hardcoded', note.id);
|
const url0 = await mediaService.saveFile(testImage, 'hardcoded', alias);
|
||||||
const url1 = await mediaService.saveFile(
|
const url1 = await mediaService.saveFile(
|
||||||
testImage,
|
testImage,
|
||||||
'hardcoded',
|
'hardcoded',
|
||||||
extraNote.id,
|
extraAlias,
|
||||||
);
|
);
|
||||||
|
|
||||||
const responseAfter = await request(httpServer)
|
const responseAfter = await request(httpServer)
|
||||||
.get(`/notes/${note.id}/media/`)
|
.get(`/notes/${alias}/media/`)
|
||||||
.expect('Content-Type', /json/)
|
.expect('Content-Type', /json/)
|
||||||
.expect(200);
|
.expect(200);
|
||||||
expect(responseAfter.body).toHaveLength(1);
|
expect(responseAfter.body).toHaveLength(1);
|
||||||
|
@ -429,13 +433,10 @@ describe('Notes', () => {
|
||||||
.expect(404);
|
.expect(404);
|
||||||
});
|
});
|
||||||
it("fails, when user can't read note", async () => {
|
it("fails, when user can't read note", async () => {
|
||||||
const note = await notesService.createNote(
|
const alias = 'test11';
|
||||||
'This is a test note.',
|
await notesService.createNote('This is a test note.', alias, user2);
|
||||||
'test11',
|
|
||||||
user2,
|
|
||||||
);
|
|
||||||
await request(app.getHttpServer())
|
await request(app.getHttpServer())
|
||||||
.get(`/notes/${note.id}/media/`)
|
.get(`/notes/${alias}/media/`)
|
||||||
.expect('Content-Type', /json/)
|
.expect('Content-Type', /json/)
|
||||||
.expect(401);
|
.expect(401);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue