mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-23 19:47:03 -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', () => {
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
/*
|
||||
* 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 { AliasUpdateDto } from '@hedgedoc/commons';
|
||||
import request from 'supertest';
|
||||
|
||||
import { AliasUpdateDto } from '../../src/notes/alias-update.dto';
|
||||
import { TestSetup, TestSetupBuilder } from '../test-setup';
|
||||
|
||||
describe('Alias', () => {
|
||||
|
@ -166,13 +166,13 @@ describe('Alias', () => {
|
|||
.expect(401);
|
||||
});
|
||||
it('if the property primaryAlias is false', async () => {
|
||||
changeAliasDto.primaryAlias = false;
|
||||
|
||||
await request(testSetup.app.getHttpServer())
|
||||
.put(`/api/v2/alias/${testAlias}`)
|
||||
.set('Authorization', `Bearer ${testSetup.authTokens[0].secret}`)
|
||||
.set('Content-Type', 'application/json')
|
||||
.send(changeAliasDto)
|
||||
.send({
|
||||
primaryAlias: false,
|
||||
})
|
||||
.expect(400);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
/*
|
||||
* 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 { NoteMetadataDto } from '@hedgedoc/commons';
|
||||
import { promises as fs } from 'fs';
|
||||
import { join } from 'path';
|
||||
import { HistoryEntryDto } from 'src/history/history-entry.dto';
|
||||
import request from 'supertest';
|
||||
|
||||
import { HistoryEntryUpdateDto } from '../../src/history/history-entry-update.dto';
|
||||
import { HistoryEntryDto } from '../../src/history/history-entry.dto';
|
||||
import { NoteMetadataDto } from '../../src/notes/note-metadata.dto';
|
||||
import { User } from '../../src/users/user.entity';
|
||||
import { TestSetup, TestSetupBuilder } from '../test-setup';
|
||||
|
||||
|
@ -25,7 +25,12 @@ describe('Me', () => {
|
|||
uploadPath =
|
||||
testSetup.configService.get('mediaConfig').backend.filesystem.uploadPath;
|
||||
|
||||
user = await testSetup.userService.createUser('hardcoded', 'Testy');
|
||||
user = await testSetup.userService.createUser(
|
||||
'hardcoded',
|
||||
'Testy',
|
||||
null,
|
||||
null,
|
||||
);
|
||||
await testSetup.app.init();
|
||||
});
|
||||
|
||||
|
|
|
@ -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 { NotePermissionsUpdateDto } from '@hedgedoc/commons';
|
||||
import { promises as fs } from 'fs';
|
||||
import { join } from 'path';
|
||||
import request from 'supertest';
|
||||
|
||||
import { NotInDBError } from '../../src/errors/errors';
|
||||
import { NotePermissionsUpdateDto } from '../../src/notes/note-permissions.dto';
|
||||
import { TestSetup, TestSetupBuilder } from '../test-setup';
|
||||
|
||||
describe('Notes', () => {
|
||||
|
@ -219,14 +219,15 @@ describe('Notes', () => {
|
|||
testSetup.users[0],
|
||||
'deleteTest3',
|
||||
);
|
||||
const updateNotePermission = new NotePermissionsUpdateDto();
|
||||
updateNotePermission.sharedToUsers = [
|
||||
{
|
||||
username: testSetup.users[0].username,
|
||||
canEdit: true,
|
||||
},
|
||||
];
|
||||
updateNotePermission.sharedToGroups = [];
|
||||
const updateNotePermission: NotePermissionsUpdateDto = {
|
||||
sharedToUsers: [
|
||||
{
|
||||
username: testSetup.users[0].username,
|
||||
canEdit: true,
|
||||
},
|
||||
],
|
||||
sharedToGroups: [],
|
||||
};
|
||||
await testSetup.permissionsService.updateNotePermissions(
|
||||
note,
|
||||
updateNotePermission,
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
/*
|
||||
* 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 { ApiTokenWithSecretDto } from '@hedgedoc/commons';
|
||||
import { ConfigModule, ConfigService } from '@nestjs/config';
|
||||
import { RouterModule, Routes } from '@nestjs/core';
|
||||
import { EventEmitterModule } from '@nestjs/event-emitter';
|
||||
|
@ -11,7 +12,6 @@ import { Test, TestingModule, TestingModuleBuilder } from '@nestjs/testing';
|
|||
import { TypeOrmModule, TypeOrmModuleOptions } from '@nestjs/typeorm';
|
||||
import { Connection, createConnection } from 'typeorm';
|
||||
|
||||
import { ApiTokenWithSecretDto } from '../src/api-token/api-token.dto';
|
||||
import { ApiTokenGuard } from '../src/api-token/api-token.guard';
|
||||
import { ApiTokenModule } from '../src/api-token/api-token.module';
|
||||
import { ApiTokenService } from '../src/api-token/api-token.service';
|
||||
|
@ -389,13 +389,28 @@ export class TestSetupBuilder {
|
|||
this.setupPostCompile.push(async () => {
|
||||
// Create users
|
||||
this.testSetup.users.push(
|
||||
await this.testSetup.userService.createUser(username1, 'Test User 1'),
|
||||
await this.testSetup.userService.createUser(
|
||||
username1,
|
||||
'Test User 1',
|
||||
null,
|
||||
null,
|
||||
),
|
||||
);
|
||||
this.testSetup.users.push(
|
||||
await this.testSetup.userService.createUser(username2, 'Test User 2'),
|
||||
await this.testSetup.userService.createUser(
|
||||
username2,
|
||||
'Test User 2',
|
||||
null,
|
||||
null,
|
||||
),
|
||||
);
|
||||
this.testSetup.users.push(
|
||||
await this.testSetup.userService.createUser(username3, 'Test User 3'),
|
||||
await this.testSetup.userService.createUser(
|
||||
username3,
|
||||
'Test User 3',
|
||||
null,
|
||||
null,
|
||||
),
|
||||
);
|
||||
|
||||
// Create identities for login
|
||||
|
@ -415,10 +430,12 @@ export class TestSetupBuilder {
|
|||
// create auth tokens
|
||||
this.testSetup.authTokens = await Promise.all(
|
||||
this.testSetup.users.map(async (user) => {
|
||||
const validUntil = new Date();
|
||||
validUntil.setTime(validUntil.getTime() + 60 * 60 * 1000);
|
||||
return await this.testSetup.publicAuthTokenService.addToken(
|
||||
user,
|
||||
'test',
|
||||
new Date().getTime() + 60 * 60 * 1000,
|
||||
validUntil,
|
||||
);
|
||||
}),
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue