mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-29 22:35:50 -04:00
refactor: replace TypeORM with knex.js
Co-authored-by: Philip Molares <philip.molares@udo.edu> Signed-off-by: Philip Molares <philip.molares@udo.edu> Signed-off-by: Erik Michelson <github@erik.michelson.eu>
This commit is contained in:
parent
6e151c8a1b
commit
4bd49085c6
241 changed files with 4577 additions and 6636 deletions
|
@ -6,8 +6,9 @@
|
|||
import { AliasCreateDto, AliasUpdateDto } from '@hedgedoc/commons';
|
||||
import request from 'supertest';
|
||||
|
||||
import { AliasCreateDto } from '../../src/alias/alias-create.dto';
|
||||
import { AliasUpdateDto } from '../../src/alias/alias-update.dto';
|
||||
import { User } from '../../src/database/user.entity';
|
||||
import { Note } from '../../src/notes/note.entity';
|
||||
import {
|
||||
password1,
|
||||
password2,
|
||||
|
@ -55,7 +56,7 @@ describe('Alias', () => {
|
|||
describe('POST /alias', () => {
|
||||
const testAlias = 'aliasTest';
|
||||
const newAliasDto: AliasCreateDto = {
|
||||
noteIdOrAlias: testAlias,
|
||||
alias: testAlias,
|
||||
newAlias: '',
|
||||
};
|
||||
let publicId = '';
|
||||
|
@ -87,7 +88,7 @@ describe('Alias', () => {
|
|||
primaryAlias: false,
|
||||
noteId: publicId,
|
||||
});
|
||||
expect(note.body.metadata.primaryAddress).toEqual(testAlias);
|
||||
expect(note.body.metadata.primaryAlias).toEqual(testAlias);
|
||||
expect(note.body.metadata.id).toEqual(publicId);
|
||||
});
|
||||
|
||||
|
@ -158,7 +159,7 @@ describe('Alias', () => {
|
|||
primaryAlias: true,
|
||||
noteId: publicId,
|
||||
});
|
||||
expect(note.body.metadata.primaryAddress).toEqual(newAlias);
|
||||
expect(note.body.metadata.primaryAlias).toEqual(newAlias);
|
||||
expect(note.body.metadata.id).toEqual(publicId);
|
||||
});
|
||||
|
||||
|
|
|
@ -53,9 +53,10 @@ describe('Auth', () => {
|
|||
.set('Content-Type', 'application/json')
|
||||
.send(JSON.stringify(registrationDto))
|
||||
.expect(201);
|
||||
const newUser = await testSetup.userService.getUserByUsername(username, [
|
||||
UserRelationEnum.IDENTITIES,
|
||||
]);
|
||||
const newUser = await testSetup.userService.getUserDtoByUsername(
|
||||
username,
|
||||
[UserRelationEnum.IDENTITIES],
|
||||
);
|
||||
expect(newUser.displayName).toEqual(displayName);
|
||||
await expect(newUser.identities).resolves.toHaveLength(1);
|
||||
await expect(
|
||||
|
@ -115,7 +116,7 @@ describe('Auth', () => {
|
|||
.expect(400);
|
||||
expect(response.text).toContain('PasswordTooWeakError');
|
||||
await expect(() =>
|
||||
testSetup.userService.getUserByUsername(username, [
|
||||
testSetup.userService.getUserDtoByUsername(username, [
|
||||
UserRelationEnum.IDENTITIES,
|
||||
]),
|
||||
).rejects.toThrow(NotInDBError);
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
import { GuestAccess, LoginDto } from '@hedgedoc/commons';
|
||||
import { LoginDto, PermissionLevel } from '@hedgedoc/commons';
|
||||
import request from 'supertest';
|
||||
|
||||
import { createDefaultMockNoteConfig } from '../../src/config/mock/note.config.mock';
|
||||
|
@ -66,7 +66,7 @@ describe('Groups', () => {
|
|||
|
||||
describe('API requires authentication', () => {
|
||||
beforeAll(() => {
|
||||
noteConfigMock.guestAccess = GuestAccess.DENY;
|
||||
noteConfigMock.guestAccess = PermissionLevel.DENY;
|
||||
});
|
||||
test('get group', async () => {
|
||||
const response = await request(testSetup.app.getHttpServer()).get(
|
||||
|
|
|
@ -11,7 +11,7 @@ import { HistoryEntryImportDto } from '../../src/history/history-entry-import.dt
|
|||
import { HistoryEntry } from '../../src/history/history-entry.entity';
|
||||
import { HistoryService } from '../../src/history/history.service';
|
||||
import { Note } from '../../src/notes/note.entity';
|
||||
import { NotesService } from '../../src/notes/notes.service';
|
||||
import { NoteService } from '../../src/notes/note.service';
|
||||
import { UsersService } from '../../src/users/users.service';
|
||||
import { TestSetup, TestSetupBuilder } from '../test-setup';
|
||||
|
||||
|
@ -43,7 +43,7 @@ describe('History', () => {
|
|||
localIdentityService = moduleRef.get(LocalService);
|
||||
user = await userService.createUser(username, 'Testy', null, null);
|
||||
await localIdentityService.createLocalIdentity(user, password);
|
||||
const notesService = moduleRef.get(NotesService);
|
||||
const notesService = moduleRef.get(NoteService);
|
||||
note = await notesService.createNote(content, user, 'note');
|
||||
note2 = await notesService.createNote(content, user, 'note2');
|
||||
agent = request.agent(testSetup.app.getHttpServer());
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
import { LoginUserInfoDto, ProviderType } from '@hedgedoc/commons';
|
||||
import { AuthProviderType, LoginUserInfoDto } from '@hedgedoc/commons';
|
||||
import { promises as fs } from 'fs';
|
||||
import request from 'supertest';
|
||||
|
||||
|
@ -58,7 +58,7 @@ describe('Me', () => {
|
|||
it('GET /me', async () => {
|
||||
const userInfo = testSetup.userService.toLoginUserInfoDto(
|
||||
user,
|
||||
ProviderType.LOCAL,
|
||||
AuthProviderType.LOCAL,
|
||||
);
|
||||
const response = await agent
|
||||
.get('/api/private/me')
|
||||
|
@ -127,7 +127,8 @@ describe('Me', () => {
|
|||
expect(imageIds).toContain(response.body[1].uuid);
|
||||
expect(imageIds).toContain(response.body[2].uuid);
|
||||
expect(imageIds).toContain(response.body[3].uuid);
|
||||
const mediaUploads = await testSetup.mediaService.listUploadsByUser(user);
|
||||
const mediaUploads =
|
||||
await testSetup.mediaService.getMediaUploadUuidsByUserId(user);
|
||||
for (const upload of mediaUploads) {
|
||||
await testSetup.mediaService.deleteFile(upload);
|
||||
}
|
||||
|
@ -143,7 +144,8 @@ describe('Me', () => {
|
|||
displayName: newDisplayName,
|
||||
})
|
||||
.expect(200);
|
||||
const dbUser = await testSetup.userService.getUserByUsername('hardcoded');
|
||||
const dbUser =
|
||||
await testSetup.userService.getUserDtoByUsername('hardcoded');
|
||||
expect(dbUser.displayName).toEqual(newDisplayName);
|
||||
});
|
||||
|
||||
|
@ -155,17 +157,19 @@ describe('Me', () => {
|
|||
user,
|
||||
note1,
|
||||
);
|
||||
const dbUser = await testSetup.userService.getUserByUsername('hardcoded');
|
||||
const dbUser =
|
||||
await testSetup.userService.getUserDtoByUsername('hardcoded');
|
||||
expect(dbUser).toBeInstanceOf(User);
|
||||
const mediaUploads = await testSetup.mediaService.listUploadsByUser(dbUser);
|
||||
const mediaUploads =
|
||||
await testSetup.mediaService.getMediaUploadUuidsByUserId(dbUser);
|
||||
expect(mediaUploads).toHaveLength(1);
|
||||
expect(mediaUploads[0].uuid).toEqual(upload.uuid);
|
||||
await agent.delete('/api/private/me').expect(204);
|
||||
await expect(
|
||||
testSetup.userService.getUserByUsername('hardcoded'),
|
||||
testSetup.userService.getUserDtoByUsername('hardcoded'),
|
||||
).rejects.toThrow(NotInDBError);
|
||||
const mediaUploadsAfter =
|
||||
await testSetup.mediaService.listUploadsByNote(note1);
|
||||
await testSetup.mediaService.getMediaUploadUuidsByNoteId(note1);
|
||||
expect(mediaUploadsAfter).toHaveLength(0);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -187,7 +187,7 @@ describe('Media', () => {
|
|||
// upload a file with the default test user
|
||||
const testNote = await testSetup.notesService.createNote(
|
||||
'test content',
|
||||
await testSetup.userService.getUserByUsername(username2),
|
||||
await testSetup.userService.getUserDtoByUsername(username2),
|
||||
'test_delete_media_note',
|
||||
);
|
||||
const testImage = await fs.readFile('test/private-api/fixtures/test.png');
|
||||
|
|
|
@ -81,7 +81,7 @@ describe('Notes', () => {
|
|||
expect(response.body.metadata?.id).toBeDefined();
|
||||
expect(
|
||||
await testSetup.notesService.getNoteContent(
|
||||
await testSetup.notesService.getNoteByIdOrAlias(
|
||||
await testSetup.notesService.getNoteIdByAlias(
|
||||
response.body.metadata.id,
|
||||
),
|
||||
),
|
||||
|
@ -108,7 +108,7 @@ describe('Notes', () => {
|
|||
});
|
||||
|
||||
describe('POST /notes/{note}', () => {
|
||||
it('works with a non-existing alias', async () => {
|
||||
it('works with a non-existing aliases', async () => {
|
||||
const response = await agent
|
||||
.post('/api/private/notes/test2')
|
||||
.set('Content-Type', 'text/markdown')
|
||||
|
@ -118,14 +118,14 @@ describe('Notes', () => {
|
|||
expect(response.body.metadata?.id).toBeDefined();
|
||||
return expect(
|
||||
await testSetup.notesService.getNoteContent(
|
||||
await testSetup.notesService.getNoteByIdOrAlias(
|
||||
await testSetup.notesService.getNoteIdByAlias(
|
||||
response.body.metadata?.id,
|
||||
),
|
||||
),
|
||||
).toEqual(content);
|
||||
});
|
||||
|
||||
it('fails with a forbidden alias', async () => {
|
||||
it('fails with a forbidden aliases', async () => {
|
||||
await agent
|
||||
.post(`/api/private/notes/${forbiddenNoteId}`)
|
||||
.set('Content-Type', 'text/markdown')
|
||||
|
@ -134,7 +134,7 @@ describe('Notes', () => {
|
|||
.expect(400);
|
||||
});
|
||||
|
||||
it('fails with a existing alias', async () => {
|
||||
it('fails with a existing aliases', async () => {
|
||||
await agent
|
||||
.post('/api/private/notes/test2')
|
||||
.set('Content-Type', 'text/markdown')
|
||||
|
@ -156,7 +156,7 @@ describe('Notes', () => {
|
|||
.expect(413);
|
||||
});
|
||||
|
||||
it('cannot create an alias equal to a note publicId', async () => {
|
||||
it('cannot create an aliases equal to a note publicId', async () => {
|
||||
await agent
|
||||
.post(`/api/private/notes/${testSetup.anonymousNotes[0].publicId}`)
|
||||
.set('Content-Type', 'text/markdown')
|
||||
|
@ -168,7 +168,7 @@ describe('Notes', () => {
|
|||
|
||||
describe('DELETE /notes/{note}', () => {
|
||||
describe('works', () => {
|
||||
it('with an existing alias and keepMedia false', async () => {
|
||||
it('with an existing aliases and keepMedia false', async () => {
|
||||
const noteId = 'test3';
|
||||
const note = await testSetup.notesService.createNote(
|
||||
content,
|
||||
|
@ -189,16 +189,16 @@ describe('Notes', () => {
|
|||
})
|
||||
.expect(204);
|
||||
await expect(
|
||||
testSetup.notesService.getNoteByIdOrAlias(noteId),
|
||||
testSetup.notesService.getNoteIdByAlias(noteId),
|
||||
).rejects.toEqual(
|
||||
new NotInDBError(`Note with id/alias '${noteId}' not found.`),
|
||||
);
|
||||
expect(
|
||||
await testSetup.mediaService.listUploadsByUser(user1),
|
||||
await testSetup.mediaService.getMediaUploadUuidsByUserId(user1),
|
||||
).toHaveLength(0);
|
||||
await fs.rmdir(uploadPath);
|
||||
});
|
||||
it('with an existing alias and keepMedia true', async () => {
|
||||
it('with an existing aliases and keepMedia true', async () => {
|
||||
const noteId = 'test3a';
|
||||
const note = await testSetup.notesService.createNote(
|
||||
content,
|
||||
|
@ -219,22 +219,22 @@ describe('Notes', () => {
|
|||
})
|
||||
.expect(204);
|
||||
await expect(
|
||||
testSetup.notesService.getNoteByIdOrAlias(noteId),
|
||||
testSetup.notesService.getNoteIdByAlias(noteId),
|
||||
).rejects.toEqual(
|
||||
new NotInDBError(`Note with id/alias '${noteId}' not found.`),
|
||||
);
|
||||
expect(
|
||||
await testSetup.mediaService.listUploadsByUser(user1),
|
||||
await testSetup.mediaService.getMediaUploadUuidsByUserId(user1),
|
||||
).toHaveLength(1);
|
||||
// delete the file afterwards
|
||||
await fs.unlink(join(uploadPath, upload.uuid + '.png'));
|
||||
await fs.rmdir(uploadPath);
|
||||
});
|
||||
});
|
||||
it('fails with a forbidden alias', async () => {
|
||||
it('fails with a forbidden aliases', async () => {
|
||||
await agent.delete(`/api/private/notes/${forbiddenNoteId}`).expect(400);
|
||||
});
|
||||
it('fails with a non-existing alias', async () => {
|
||||
it('fails with a non-existing aliases', async () => {
|
||||
await agent.delete('/api/private/notes/i_dont_exist').expect(404);
|
||||
});
|
||||
});
|
||||
|
@ -249,7 +249,7 @@ describe('Notes', () => {
|
|||
.expect(200);
|
||||
expect(typeof metadata.body.id).toEqual('string');
|
||||
expect(metadata.body.aliases[0].name).toEqual(noteAlias);
|
||||
expect(metadata.body.primaryAddress).toEqual(noteAlias);
|
||||
expect(metadata.body.primaryAlias).toEqual(noteAlias);
|
||||
expect(metadata.body.title).toEqual('');
|
||||
expect(metadata.body.description).toEqual('');
|
||||
expect(typeof metadata.body.createdAt).toEqual('string');
|
||||
|
@ -259,19 +259,19 @@ describe('Notes', () => {
|
|||
expect(metadata.body.permissions.sharedToUsers).toEqual([]);
|
||||
expect(metadata.body.tags).toEqual([]);
|
||||
expect(typeof metadata.body.updatedAt).toEqual('string');
|
||||
expect(typeof metadata.body.updateUsername).toEqual('string');
|
||||
expect(typeof metadata.body.lastUpdatedBy).toEqual('string');
|
||||
expect(typeof metadata.body.viewCount).toEqual('number');
|
||||
expect(metadata.body.editedBy).toEqual([]);
|
||||
});
|
||||
|
||||
it('fails with a forbidden alias', async () => {
|
||||
it('fails with a forbidden aliases', async () => {
|
||||
await agent
|
||||
.get(`/api/private/notes/${forbiddenNoteId}/metadata`)
|
||||
.expect('Content-Type', /json/)
|
||||
.expect(400);
|
||||
});
|
||||
|
||||
it('fails with non-existing alias', async () => {
|
||||
it('fails with non-existing aliases', async () => {
|
||||
// check if a missing note correctly returns 404
|
||||
await agent
|
||||
.get('/api/private/notes/i_dont_exist/metadata')
|
||||
|
@ -305,7 +305,7 @@ describe('Notes', () => {
|
|||
});
|
||||
|
||||
describe('GET /notes/{note}/revisions', () => {
|
||||
it('works with existing alias', async () => {
|
||||
it('works with existing aliases', async () => {
|
||||
await testSetup.notesService.createNote(content, user1, 'test4');
|
||||
// create a second note to check for a regression, where typeorm always returned
|
||||
// all revisions in the database
|
||||
|
@ -317,13 +317,13 @@ describe('Notes', () => {
|
|||
expect(response.body).toHaveLength(1);
|
||||
});
|
||||
|
||||
it('fails with a forbidden alias', async () => {
|
||||
it('fails with a forbidden aliases', async () => {
|
||||
await agent
|
||||
.get(`/api/private/notes/${forbiddenNoteId}/revisions`)
|
||||
.expect(400);
|
||||
});
|
||||
|
||||
it('fails with non-existing alias', async () => {
|
||||
it('fails with non-existing aliases', async () => {
|
||||
// check if a missing note correctly returns 404
|
||||
await agent
|
||||
.get('/api/private/notes/i_dont_exist/revisions')
|
||||
|
@ -333,7 +333,7 @@ describe('Notes', () => {
|
|||
});
|
||||
|
||||
describe('DELETE /notes/{note}/revisions', () => {
|
||||
it('works with an existing alias', async () => {
|
||||
it('works with an existing aliases', async () => {
|
||||
const noteId = 'test8';
|
||||
const note = await testSetup.notesService.createNote(
|
||||
content,
|
||||
|
@ -356,12 +356,12 @@ describe('Notes', () => {
|
|||
.expect(200);
|
||||
expect(responseAfterDeleting.body).toHaveLength(1);
|
||||
});
|
||||
it('fails with a forbidden alias', async () => {
|
||||
it('fails with a forbidden aliases', async () => {
|
||||
await agent
|
||||
.delete(`/api/private/notes/${forbiddenNoteId}/revisions`)
|
||||
.expect(400);
|
||||
});
|
||||
it('fails with non-existing alias', async () => {
|
||||
it('fails with non-existing aliases', async () => {
|
||||
// check if a missing note correctly returns 404
|
||||
await agent
|
||||
.delete('/api/private/notes/i_dont_exist/revisions')
|
||||
|
@ -371,7 +371,7 @@ describe('Notes', () => {
|
|||
});
|
||||
|
||||
describe('GET /notes/{note}/revisions/{revision-id}', () => {
|
||||
it('works with an existing alias', async () => {
|
||||
it('works with an existing aliases', async () => {
|
||||
const note = await testSetup.notesService.createNote(
|
||||
content,
|
||||
user1,
|
||||
|
@ -384,12 +384,12 @@ describe('Notes', () => {
|
|||
.expect(200);
|
||||
expect(response.body.content).toEqual(content);
|
||||
});
|
||||
it('fails with a forbidden alias', async () => {
|
||||
it('fails with a forbidden aliases', async () => {
|
||||
await agent
|
||||
.get(`/api/private/notes/${forbiddenNoteId}/revisions/1`)
|
||||
.expect(400);
|
||||
});
|
||||
it('fails with non-existing alias', async () => {
|
||||
it('fails with non-existing aliases', async () => {
|
||||
// check if a missing note correctly returns 404
|
||||
await agent
|
||||
.get('/api/private/notes/i_dont_exist/revisions/1')
|
||||
|
@ -459,7 +459,7 @@ describe('Notes', () => {
|
|||
alias,
|
||||
);
|
||||
// Redact default read permissions
|
||||
const note = await testSetup.notesService.getNoteByIdOrAlias(alias);
|
||||
const note = await testSetup.notesService.getNoteIdByAlias(alias);
|
||||
const everyone = await testSetup.groupService.getEveryoneGroup();
|
||||
const loggedin = await testSetup.groupService.getLoggedInGroup();
|
||||
await testSetup.permissionsService.removeGroupPermission(note, everyone);
|
||||
|
@ -510,7 +510,7 @@ describe('Notes', () => {
|
|||
|
||||
it("doesn't do anything if the user is the owner", async () => {
|
||||
const note =
|
||||
await testSetup.notesService.getNoteByIdOrAlias(user1NoteAlias);
|
||||
await testSetup.notesService.getNoteIdByAlias(user1NoteAlias);
|
||||
await testSetup.permissionsService.removeUserPermission(note, user2);
|
||||
|
||||
const response = await agent
|
||||
|
@ -557,7 +557,7 @@ describe('Notes', () => {
|
|||
|
||||
it('works', async () => {
|
||||
const note =
|
||||
await testSetup.notesService.getNoteByIdOrAlias(user1NoteAlias);
|
||||
await testSetup.notesService.getNoteIdByAlias(user1NoteAlias);
|
||||
await testSetup.permissionsService.setUserPermission(
|
||||
note,
|
||||
user2,
|
||||
|
@ -630,7 +630,7 @@ describe('Notes', () => {
|
|||
|
||||
it('works', async () => {
|
||||
const note =
|
||||
await testSetup.notesService.getNoteByIdOrAlias(user1NoteAlias);
|
||||
await testSetup.notesService.getNoteIdByAlias(user1NoteAlias);
|
||||
await testSetup.permissionsService.setGroupPermission(
|
||||
note,
|
||||
group1,
|
||||
|
|
|
@ -57,7 +57,7 @@ describe('Alias', () => {
|
|||
primaryAlias: false,
|
||||
noteId: publicId,
|
||||
});
|
||||
expect(note.body.metadata.primaryAddress).toEqual(testAlias);
|
||||
expect(note.body.metadata.primaryAlias).toEqual(testAlias);
|
||||
expect(note.body.metadata.id).toEqual(publicId);
|
||||
});
|
||||
|
||||
|
@ -136,7 +136,7 @@ describe('Alias', () => {
|
|||
primaryAlias: true,
|
||||
noteId: publicId,
|
||||
});
|
||||
expect(note.body.metadata.primaryAddress).toEqual(testAlias);
|
||||
expect(note.body.metadata.primaryAlias).toEqual(testAlias);
|
||||
expect(note.body.metadata.id).toEqual(publicId);
|
||||
});
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ describe('Me', () => {
|
|||
});
|
||||
|
||||
it(`GET /me`, async () => {
|
||||
const userInfo = testSetup.userService.toFullUserDto(user);
|
||||
const userInfo = testSetup.userService.toLoginUserInfoDto(user);
|
||||
const response = await request(testSetup.app.getHttpServer())
|
||||
.get('/api/v2/me')
|
||||
.expect('Content-Type', /json/)
|
||||
|
@ -181,19 +181,19 @@ describe('Me', () => {
|
|||
.expect(200);
|
||||
const noteMetaDtos = response.body as NoteMetadataDto[];
|
||||
expect(noteMetaDtos).toHaveLength(1);
|
||||
expect(noteMetaDtos[0].primaryAddress).toEqual(noteName);
|
||||
expect(noteMetaDtos[0].updateUsername).toEqual(user.username);
|
||||
expect(noteMetaDtos[0].primaryAlias).toEqual(noteName);
|
||||
expect(noteMetaDtos[0].lastUpdatedBy).toEqual(user.username);
|
||||
});
|
||||
|
||||
it('GET /me/media', async () => {
|
||||
const note1 = await testSetup.notesService.createNote(
|
||||
'This is a test note.',
|
||||
await testSetup.userService.getUserByUsername('hardcoded'),
|
||||
await testSetup.userService.getUserDtoByUsername('hardcoded'),
|
||||
'test8',
|
||||
);
|
||||
const note2 = await testSetup.notesService.createNote(
|
||||
'This is a test note.',
|
||||
await testSetup.userService.getUserByUsername('hardcoded'),
|
||||
await testSetup.userService.getUserDtoByUsername('hardcoded'),
|
||||
'test9',
|
||||
);
|
||||
const httpServer = testSetup.app.getHttpServer();
|
||||
|
|
|
@ -49,7 +49,7 @@ describe('Notes', () => {
|
|||
expect(response.body.metadata?.id).toBeDefined();
|
||||
expect(
|
||||
await testSetup.notesService.getNoteContent(
|
||||
await testSetup.notesService.getNoteByIdOrAlias(
|
||||
await testSetup.notesService.getNoteIdByAlias(
|
||||
response.body.metadata.id,
|
||||
),
|
||||
),
|
||||
|
@ -96,7 +96,7 @@ describe('Notes', () => {
|
|||
expect(response.body.metadata?.id).toBeDefined();
|
||||
return expect(
|
||||
await testSetup.notesService.getNoteContent(
|
||||
await testSetup.notesService.getNoteByIdOrAlias(
|
||||
await testSetup.notesService.getNoteIdByAlias(
|
||||
response.body.metadata?.id,
|
||||
),
|
||||
),
|
||||
|
@ -172,12 +172,14 @@ describe('Notes', () => {
|
|||
})
|
||||
.expect(204);
|
||||
await expect(
|
||||
testSetup.notesService.getNoteByIdOrAlias(noteId),
|
||||
testSetup.notesService.getNoteIdByAlias(noteId),
|
||||
).rejects.toEqual(
|
||||
new NotInDBError(`Note with id/alias '${noteId}' not found.`),
|
||||
);
|
||||
expect(
|
||||
await testSetup.mediaService.listUploadsByUser(testSetup.users[0]),
|
||||
await testSetup.mediaService.getMediaUploadUuidsByUserId(
|
||||
testSetup.users[0],
|
||||
),
|
||||
).toHaveLength(0);
|
||||
});
|
||||
it('with an existing alias and keepMedia true', async () => {
|
||||
|
@ -202,12 +204,14 @@ describe('Notes', () => {
|
|||
})
|
||||
.expect(204);
|
||||
await expect(
|
||||
testSetup.notesService.getNoteByIdOrAlias(noteId),
|
||||
testSetup.notesService.getNoteIdByAlias(noteId),
|
||||
).rejects.toEqual(
|
||||
new NotInDBError(`Note with id/alias '${noteId}' not found.`),
|
||||
);
|
||||
expect(
|
||||
await testSetup.mediaService.listUploadsByUser(testSetup.users[0]),
|
||||
await testSetup.mediaService.getMediaUploadUuidsByUserId(
|
||||
testSetup.users[0],
|
||||
),
|
||||
).toHaveLength(1);
|
||||
// delete the file afterwards
|
||||
await fs.unlink(join(uploadPath, upload.uuid + '.png'));
|
||||
|
@ -228,11 +232,11 @@ describe('Notes', () => {
|
|||
],
|
||||
sharedToGroups: [],
|
||||
};
|
||||
await testSetup.permissionsService.updateNotePermissions(
|
||||
await testSetup.permissionsService.replaceNotePermissions(
|
||||
note,
|
||||
updateNotePermission,
|
||||
);
|
||||
const updatedNote = await testSetup.notesService.getNoteByIdOrAlias(
|
||||
const updatedNote = await testSetup.notesService.getNoteIdByAlias(
|
||||
(await note.aliases).filter((alias) => alias.primary)[0].name,
|
||||
);
|
||||
expect(await updatedNote.userPermissions).toHaveLength(1);
|
||||
|
@ -249,7 +253,7 @@ describe('Notes', () => {
|
|||
.send({ keepMedia: false })
|
||||
.expect(204);
|
||||
await expect(
|
||||
testSetup.notesService.getNoteByIdOrAlias('deleteTest3'),
|
||||
testSetup.notesService.getNoteIdByAlias('deleteTest3'),
|
||||
).rejects.toEqual(
|
||||
new NotInDBError("Note with id/alias 'deleteTest3' not found."),
|
||||
);
|
||||
|
@ -284,7 +288,7 @@ describe('Notes', () => {
|
|||
.expect(200);
|
||||
expect(
|
||||
await testSetup.notesService.getNoteContent(
|
||||
await testSetup.notesService.getNoteByIdOrAlias('test4'),
|
||||
await testSetup.notesService.getNoteIdByAlias('test4'),
|
||||
),
|
||||
).toEqual(changedContent);
|
||||
expect(response.body.content).toEqual(changedContent);
|
||||
|
@ -320,7 +324,7 @@ describe('Notes', () => {
|
|||
.expect(200);
|
||||
expect(typeof metadata.body.id).toEqual('string');
|
||||
expect(metadata.body.aliases[0].name).toEqual('test5');
|
||||
expect(metadata.body.primaryAddress).toEqual('test5');
|
||||
expect(metadata.body.primaryAlias).toEqual('test5');
|
||||
expect(metadata.body.title).toEqual('');
|
||||
expect(metadata.body.description).toEqual('');
|
||||
expect(typeof metadata.body.createdAt).toEqual('string');
|
||||
|
@ -329,7 +333,7 @@ describe('Notes', () => {
|
|||
expect(metadata.body.permissions.sharedToUsers).toEqual([]);
|
||||
expect(metadata.body.tags).toEqual([]);
|
||||
expect(typeof metadata.body.updatedAt).toEqual('string');
|
||||
expect(typeof metadata.body.updateUsername).toEqual('string');
|
||||
expect(typeof metadata.body.lastUpdatedBy).toEqual('string');
|
||||
expect(typeof metadata.body.viewCount).toEqual('number');
|
||||
expect(metadata.body.editedBy).toEqual([]);
|
||||
});
|
||||
|
@ -530,7 +534,7 @@ describe('Notes', () => {
|
|||
alias,
|
||||
);
|
||||
// Redact default read permissions
|
||||
const note = await testSetup.notesService.getNoteByIdOrAlias(alias);
|
||||
const note = await testSetup.notesService.getNoteIdByAlias(alias);
|
||||
const everyone = await testSetup.groupService.getEveryoneGroup();
|
||||
const loggedin = await testSetup.groupService.getLoggedInGroup();
|
||||
await testSetup.permissionsService.removeGroupPermission(note, everyone);
|
||||
|
|
|
@ -12,12 +12,14 @@ import { Test, TestingModule, TestingModuleBuilder } from '@nestjs/testing';
|
|||
import { TypeOrmModule, TypeOrmModuleOptions } from '@nestjs/typeorm';
|
||||
import { Connection, createConnection } from 'typeorm';
|
||||
|
||||
import { ApiTokenGuard } from '../src/api-token/api-token.guard';
|
||||
import { AliasModule } from '../src/alias/alias.module';
|
||||
import { AliasService } from '../src/alias/alias.service';
|
||||
import { ApiTokenModule } from '../src/api-token/api-token.module';
|
||||
import { ApiTokenService } from '../src/api-token/api-token.service';
|
||||
import { MockApiTokenGuard } from '../src/api-token/mock-api-token.guard';
|
||||
import { PrivateApiModule } from '../src/api/private/private-api.module';
|
||||
import { PublicApiModule } from '../src/api/public/public-api.module';
|
||||
import { ApiTokenGuard } from '../src/api/utils/guards/api-token.guard';
|
||||
import { MockApiTokenGuard } from '../src/api/utils/guards/mock-api-token.guard';
|
||||
import { setupApp } from '../src/app-init';
|
||||
import { AuthModule } from '../src/auth/auth.module';
|
||||
import { IdentityService } from '../src/auth/identity.service';
|
||||
|
@ -73,12 +75,10 @@ import { LoggerModule } from '../src/logger/logger.module';
|
|||
import { MediaModule } from '../src/media/media.module';
|
||||
import { MediaService } from '../src/media/media.service';
|
||||
import { MonitoringModule } from '../src/monitoring/monitoring.module';
|
||||
import { AliasService } from '../src/notes/alias.service';
|
||||
import { Note } from '../src/notes/note.entity';
|
||||
import { NotesModule } from '../src/notes/notes.module';
|
||||
import { NotesService } from '../src/notes/notes.service';
|
||||
import { NoteService } from '../src/notes/note.service';
|
||||
import { PermissionService } from '../src/permissions/permission.service';
|
||||
import { PermissionsModule } from '../src/permissions/permissions.module';
|
||||
import { PermissionsService } from '../src/permissions/permissions.service';
|
||||
import { RevisionsModule } from '../src/revisions/revisions.module';
|
||||
import { RevisionsService } from '../src/revisions/revisions.service';
|
||||
import { SessionModule } from '../src/sessions/session.module';
|
||||
|
@ -107,7 +107,7 @@ export class TestSetup {
|
|||
localIdentityService: LocalService;
|
||||
ldapService: LdapService;
|
||||
oidcService: OidcService;
|
||||
notesService: NotesService;
|
||||
notesService: NoteService;
|
||||
mediaService: MediaService;
|
||||
historyService: HistoryService;
|
||||
aliasService: AliasService;
|
||||
|
@ -119,7 +119,7 @@ export class TestSetup {
|
|||
authTokens: ApiTokenWithSecretDto[] = [];
|
||||
anonymousNotes: Note[] = [];
|
||||
ownedNotes: Note[] = [];
|
||||
permissionsService: PermissionsService;
|
||||
permissionsService: PermissionService;
|
||||
|
||||
/**
|
||||
* Cleans up remnants from a test run from the database
|
||||
|
@ -282,7 +282,7 @@ export class TestSetupBuilder {
|
|||
),
|
||||
],
|
||||
}),
|
||||
NotesModule,
|
||||
AliasModule,
|
||||
UsersModule,
|
||||
RevisionsModule,
|
||||
AuthorsModule,
|
||||
|
@ -333,7 +333,7 @@ export class TestSetupBuilder {
|
|||
this.testSetup.localIdentityService =
|
||||
this.testSetup.moduleRef.get<LocalService>(LocalService);
|
||||
this.testSetup.notesService =
|
||||
this.testSetup.moduleRef.get<NotesService>(NotesService);
|
||||
this.testSetup.moduleRef.get<NoteService>(NoteService);
|
||||
this.testSetup.mediaService =
|
||||
this.testSetup.moduleRef.get<MediaService>(MediaService);
|
||||
this.testSetup.historyService =
|
||||
|
@ -343,7 +343,7 @@ export class TestSetupBuilder {
|
|||
this.testSetup.publicAuthTokenService =
|
||||
this.testSetup.moduleRef.get<ApiTokenService>(ApiTokenService);
|
||||
this.testSetup.permissionsService =
|
||||
this.testSetup.moduleRef.get<PermissionsService>(PermissionsService);
|
||||
this.testSetup.moduleRef.get<PermissionService>(PermissionService);
|
||||
this.testSetup.sessionService =
|
||||
this.testSetup.moduleRef.get<SessionService>(SessionService);
|
||||
this.testSetup.revisionsService =
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue