mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-19 17:55:17 -04:00
refactor(backend): use @hedgedoc/commons DTOs
Co-authored-by: Erik Michelson <github@erik.michelson.eu> Signed-off-by: Erik Michelson <github@erik.michelson.eu> Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
parent
7285c2bc50
commit
b11dbd51c8
94 changed files with 514 additions and 1642 deletions
|
@ -1,12 +1,12 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file)
|
||||
* SPDX-FileCopyrightText: 2025 The HedgeDoc developers (see AUTHORS file)
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
import { AliasCreateDto, AliasUpdateDto } from '@hedgedoc/commons';
|
||||
import request from 'supertest';
|
||||
|
||||
import { AliasCreateDto } from '../../src/notes/alias-create.dto';
|
||||
import { AliasUpdateDto } from '../../src/notes/alias-update.dto';
|
||||
import { Note } from '../../src/notes/note.entity';
|
||||
import { User } from '../../src/users/user.entity';
|
||||
import {
|
||||
password1,
|
||||
|
@ -183,11 +183,12 @@ describe('Alias', () => {
|
|||
});
|
||||
});
|
||||
it('if the property primaryAlias is false', async () => {
|
||||
changeAliasDto.primaryAlias = false;
|
||||
await agent1
|
||||
.put(`/api/private/alias/${newAlias}`)
|
||||
.set('Content-Type', 'application/json')
|
||||
.send(changeAliasDto)
|
||||
.send({
|
||||
primaryAlias: false,
|
||||
})
|
||||
.expect(400);
|
||||
});
|
||||
it('if the user is not an owner', async () => {
|
||||
|
@ -204,7 +205,7 @@ describe('Alias', () => {
|
|||
describe('DELETE /alias/{alias}', () => {
|
||||
const testAlias = 'aliasTest3';
|
||||
const newAlias = 'normalAlias3';
|
||||
let note;
|
||||
let note: Note;
|
||||
|
||||
beforeEach(async () => {
|
||||
note = await testSetup.notesService.createNote(
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2024 The HedgeDoc developers (see AUTHORS file)
|
||||
* SPDX-FileCopyrightText: 2025 The HedgeDoc developers (see AUTHORS file)
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
@ -8,21 +8,18 @@
|
|||
@typescript-eslint/no-unsafe-assignment,
|
||||
@typescript-eslint/no-unsafe-member-access
|
||||
*/
|
||||
import { LoginDto, RegisterDto, UpdatePasswordDto } from '@hedgedoc/commons';
|
||||
import request from 'supertest';
|
||||
|
||||
import { LoginDto } from '../../src/auth/local/login.dto';
|
||||
import { RegisterDto } from '../../src/auth/local/register.dto';
|
||||
import { UpdatePasswordDto } from '../../src/auth/local/update-password.dto';
|
||||
import { NotInDBError } from '../../src/errors/errors';
|
||||
import { UserRelationEnum } from '../../src/users/user-relation.enum';
|
||||
import { checkPassword } from '../../src/utils/password';
|
||||
import { Username } from '../../src/utils/username';
|
||||
import { TestSetup, TestSetupBuilder } from '../test-setup';
|
||||
|
||||
describe('Auth', () => {
|
||||
let testSetup: TestSetup;
|
||||
|
||||
let username: Username;
|
||||
let username: string;
|
||||
let displayName: string;
|
||||
let password: string;
|
||||
|
||||
|
@ -75,6 +72,8 @@ describe('Auth', () => {
|
|||
const conflictingUser = await testSetup.userService.createUser(
|
||||
conflictingUserName,
|
||||
displayName,
|
||||
null,
|
||||
null,
|
||||
);
|
||||
const registrationDto: RegisterDto = {
|
||||
displayName: displayName,
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2024 The HedgeDoc developers (see AUTHORS file)
|
||||
* SPDX-FileCopyrightText: 2025 The HedgeDoc developers (see AUTHORS file)
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
import { GuestAccess, LoginDto } from '@hedgedoc/commons';
|
||||
import request from 'supertest';
|
||||
|
||||
import { LoginDto } from '../../src/auth/local/login.dto';
|
||||
import { GuestAccess } from '../../src/config/guest_access.enum';
|
||||
import { createDefaultMockNoteConfig } from '../../src/config/mock/note.config.mock';
|
||||
import { NoteConfig } from '../../src/config/note.config';
|
||||
import {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2024 The HedgeDoc developers (see AUTHORS file)
|
||||
* SPDX-FileCopyrightText: 2025 The HedgeDoc developers (see AUTHORS file)
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
@ -41,7 +41,7 @@ describe('History', () => {
|
|||
historyService = moduleRef.get(HistoryService);
|
||||
const userService = moduleRef.get(UsersService);
|
||||
localIdentityService = moduleRef.get(LocalService);
|
||||
user = await userService.createUser(username, 'Testy');
|
||||
user = await userService.createUser(username, 'Testy', null, null);
|
||||
await localIdentityService.createLocalIdentity(user, password);
|
||||
const notesService = moduleRef.get(NotesService);
|
||||
note = await notesService.createNote(content, user, 'note');
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2024 The HedgeDoc developers (see AUTHORS file)
|
||||
* SPDX-FileCopyrightText: 2025 The HedgeDoc developers (see AUTHORS file)
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
import { LoginUserInfoDto, ProviderType } from '@hedgedoc/commons';
|
||||
import { promises as fs } from 'fs';
|
||||
import request from 'supertest';
|
||||
|
||||
import { NotInDBError } from '../../src/errors/errors';
|
||||
import { Note } from '../../src/notes/note.entity';
|
||||
import { UserLoginInfoDto } from '../../src/users/user-info.dto';
|
||||
import { User } from '../../src/users/user.entity';
|
||||
import { TestSetup, TestSetupBuilder } from '../test-setup';
|
||||
|
||||
|
@ -32,7 +32,12 @@ describe('Me', () => {
|
|||
const password = 'AHardcodedStrongP@ssword123';
|
||||
await testSetup.app.init();
|
||||
|
||||
user = await testSetup.userService.createUser(username, 'Testy');
|
||||
user = await testSetup.userService.createUser(
|
||||
username,
|
||||
'Testy',
|
||||
null,
|
||||
null,
|
||||
);
|
||||
await testSetup.localIdentityService.createLocalIdentity(user, password);
|
||||
|
||||
content = 'This is a test note.';
|
||||
|
@ -51,12 +56,15 @@ describe('Me', () => {
|
|||
});
|
||||
|
||||
it('GET /me', async () => {
|
||||
const userInfo = testSetup.userService.toUserLoginInfoDto(user, 'local');
|
||||
const userInfo = testSetup.userService.toLoginUserInfoDto(
|
||||
user,
|
||||
ProviderType.LOCAL,
|
||||
);
|
||||
const response = await agent
|
||||
.get('/api/private/me')
|
||||
.expect('Content-Type', /json/)
|
||||
.expect(200);
|
||||
const gotUser = response.body as UserLoginInfoDto;
|
||||
const gotUser = response.body as LoginUserInfoDto;
|
||||
expect(gotUser).toEqual(userInfo);
|
||||
});
|
||||
|
||||
|
@ -126,15 +134,15 @@ describe('Me', () => {
|
|||
await fs.rmdir(uploadPath);
|
||||
});
|
||||
|
||||
it('POST /me/profile', async () => {
|
||||
it('PUT /me/profile', async () => {
|
||||
const newDisplayName = 'Another name';
|
||||
expect(user.displayName).not.toEqual(newDisplayName);
|
||||
await agent
|
||||
.post('/api/private/me/profile')
|
||||
.put('/api/private/me/profile')
|
||||
.send({
|
||||
displayName: newDisplayName,
|
||||
})
|
||||
.expect(201);
|
||||
.expect(200);
|
||||
const dbUser = await testSetup.userService.getUserByUsername('hardcoded');
|
||||
expect(dbUser.displayName).toEqual(newDisplayName);
|
||||
});
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2024 The HedgeDoc developers (see AUTHORS file)
|
||||
* SPDX-FileCopyrightText: 2025 The HedgeDoc developers (see AUTHORS file)
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
@ -39,9 +39,19 @@ describe('Notes', () => {
|
|||
const password2 = 'AHardcodedStrongP@ssword12';
|
||||
const groupname1 = 'groupname1';
|
||||
|
||||
user1 = await testSetup.userService.createUser(username1, 'Testy');
|
||||
user1 = await testSetup.userService.createUser(
|
||||
username1,
|
||||
'Testy',
|
||||
null,
|
||||
null,
|
||||
);
|
||||
await testSetup.localIdentityService.createLocalIdentity(user1, password1);
|
||||
user2 = await testSetup.userService.createUser(username2, 'Max Mustermann');
|
||||
user2 = await testSetup.userService.createUser(
|
||||
username2,
|
||||
'Max Mustermann',
|
||||
null,
|
||||
null,
|
||||
);
|
||||
await testSetup.localIdentityService.createLocalIdentity(user2, password2);
|
||||
|
||||
group1 = await testSetup.groupService.createGroup(groupname1, 'Group 1');
|
||||
|
@ -668,7 +678,7 @@ describe('Notes', () => {
|
|||
.put(`/api/private/notes/${alias}/metadata/permissions/owner`)
|
||||
.expect('Content-Type', /json/)
|
||||
.expect(200)
|
||||
.send({ newOwner: user2.username });
|
||||
.send({ owner: user2.username });
|
||||
expect(response.body.metadata.permissions.owner).toBe(user2.username);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2024 The HedgeDoc developers (see AUTHORS file)
|
||||
* SPDX-FileCopyrightText: 2025 The HedgeDoc developers (see AUTHORS file)
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
import { LoginDto, RegisterDto } from '@hedgedoc/commons';
|
||||
import request from 'supertest';
|
||||
|
||||
import { LoginDto } from '../../src/auth/local/login.dto';
|
||||
import { RegisterDto } from '../../src/auth/local/register.dto';
|
||||
import { TestSetup, TestSetupBuilder } from '../test-setup';
|
||||
|
||||
describe('Register and Login', () => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue