mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-03-24 14:01:28 +00:00
Fix various ESLint errors in unit tests
Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
parent
208ff1d039
commit
21403ba606
7 changed files with 53 additions and 21 deletions
src
auth
groups
history
media
monitoring
notes
permissions
|
@ -4,6 +4,12 @@
|
|||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
/* eslint-disable
|
||||
@typescript-eslint/no-unsafe-call,
|
||||
@typescript-eslint/no-unsafe-member-access,
|
||||
@typescript-eslint/no-unsafe-return,
|
||||
@typescript-eslint/require-await */
|
||||
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { AuthService } from './auth.service';
|
||||
import { PassportModule } from '@nestjs/passport';
|
||||
|
@ -64,17 +70,17 @@ describe('AuthService', () => {
|
|||
it('works', async () => {
|
||||
const testPassword = 'thisIsATestPassword';
|
||||
const hash = await service.hashPassword(testPassword);
|
||||
service
|
||||
void service
|
||||
.checkPassword(testPassword, hash)
|
||||
.then((result) => expect(result).toBeTruthy());
|
||||
});
|
||||
it('fails, if secret is too short', async () => {
|
||||
const secret = service.bufferToBase64Url(await service.randomString(54));
|
||||
const secret = service.bufferToBase64Url(service.randomString(54));
|
||||
const hash = await service.hashPassword(secret);
|
||||
service
|
||||
void service
|
||||
.checkPassword(secret, hash)
|
||||
.then((result) => expect(result).toBeTruthy());
|
||||
service
|
||||
void service
|
||||
.checkPassword(secret.substr(0, secret.length - 1), hash)
|
||||
.then((result) => expect(result).toBeFalsy());
|
||||
});
|
||||
|
@ -194,12 +200,12 @@ describe('AuthService', () => {
|
|||
});
|
||||
describe('fails:', () => {
|
||||
it('the secret is missing', () => {
|
||||
expect(
|
||||
void expect(
|
||||
service.validateToken(`${authToken.keyId}`),
|
||||
).rejects.toBeInstanceOf(TokenNotValidError);
|
||||
});
|
||||
it('the secret is too long', () => {
|
||||
expect(
|
||||
void expect(
|
||||
service.validateToken(`${authToken.keyId}.${'a'.repeat(73)}`),
|
||||
).rejects.toBeInstanceOf(TokenNotValidError);
|
||||
});
|
||||
|
@ -293,7 +299,7 @@ describe('AuthService', () => {
|
|||
authToken.keyId = 'testKeyId';
|
||||
authToken.label = 'testLabel';
|
||||
authToken.createdAt = new Date();
|
||||
const tokenDto = await service.toAuthTokenDto(authToken);
|
||||
const tokenDto = service.toAuthTokenDto(authToken);
|
||||
expect(tokenDto.keyId).toEqual(authToken.keyId);
|
||||
expect(tokenDto.lastUsed).toBeNull();
|
||||
expect(tokenDto.label).toEqual(authToken.label);
|
||||
|
|
|
@ -31,7 +31,7 @@ describe('GroupsService', () => {
|
|||
|
||||
service = module.get<GroupsService>(GroupsService);
|
||||
groupRepo = module.get<Repository<Group>>(getRepositoryToken(Group));
|
||||
group = Group.create('testGroup', 'Superheros') as Group;
|
||||
group = Group.create('testGroup', 'Superheros');
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
|
|
|
@ -4,6 +4,12 @@
|
|||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
/* eslint-disable
|
||||
@typescript-eslint/no-unsafe-call,
|
||||
@typescript-eslint/no-unsafe-member-access,
|
||||
@typescript-eslint/no-unsafe-return,
|
||||
@typescript-eslint/require-await */
|
||||
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { LoggerModule } from '../logger/logger.module';
|
||||
import { HistoryService } from './history.service';
|
||||
|
|
|
@ -4,6 +4,12 @@
|
|||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
/* eslint-disable
|
||||
@typescript-eslint/no-unsafe-call,
|
||||
@typescript-eslint/no-unsafe-member-access,
|
||||
@typescript-eslint/no-unsafe-return,
|
||||
@typescript-eslint/require-await */
|
||||
|
||||
import { ConfigModule } from '@nestjs/config';
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { getRepositoryToken } from '@nestjs/typeorm';
|
||||
|
@ -96,7 +102,7 @@ describe('MediaService', () => {
|
|||
});
|
||||
|
||||
describe('saveFile', () => {
|
||||
beforeEach(async () => {
|
||||
beforeEach(() => {
|
||||
const user = User.create('hardcoded', 'Testy') as User;
|
||||
const alias = 'alias';
|
||||
const note = Note.create(user, alias);
|
||||
|
|
|
@ -22,6 +22,8 @@ async function getServerVersionFromPackageJson() {
|
|||
joinPath(__dirname, '../../package.json'),
|
||||
{ encoding: 'utf8' },
|
||||
);
|
||||
// TODO: Should this be validated in more detail?
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
||||
const packageInfo: { version: string } = JSON.parse(rawFileContent);
|
||||
const versionParts: number[] = packageInfo.version
|
||||
.split('.')
|
||||
|
|
|
@ -4,6 +4,12 @@
|
|||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
/* eslint-disable @typescript-eslint/require-await */
|
||||
/* eslint-disable
|
||||
@typescript-eslint/no-unsafe-assignment,
|
||||
@typescript-eslint/no-unsafe-member-access
|
||||
*/
|
||||
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { getRepositoryToken } from '@nestjs/typeorm';
|
||||
import { LoggerModule } from '../logger/logger.module';
|
||||
|
@ -189,7 +195,7 @@ describe('NotesService', () => {
|
|||
const newNote = await service.createNote(content);
|
||||
const revisions = await newNote.revisions;
|
||||
jest.spyOn(revisionRepo, 'findOne').mockResolvedValueOnce(revisions[0]);
|
||||
service.getNoteContent(newNote).then((result) => {
|
||||
void service.getNoteContent(newNote).then((result) => {
|
||||
expect(result).toEqual(content);
|
||||
});
|
||||
});
|
||||
|
@ -204,7 +210,7 @@ describe('NotesService', () => {
|
|||
const newNote = await service.createNote(content);
|
||||
const revisions = await newNote.revisions;
|
||||
jest.spyOn(revisionRepo, 'findOne').mockResolvedValueOnce(revisions[0]);
|
||||
service.getLatestRevision(newNote).then((result) => {
|
||||
void service.getLatestRevision(newNote).then((result) => {
|
||||
expect(result).toEqual(revisions[0]);
|
||||
});
|
||||
});
|
||||
|
@ -221,7 +227,7 @@ describe('NotesService', () => {
|
|||
const newNote = await service.createNote(content);
|
||||
const revisions = await newNote.revisions;
|
||||
jest.spyOn(revisionRepo, 'findOne').mockResolvedValueOnce(revisions[0]);
|
||||
service.getLatestRevision(newNote).then((result) => {
|
||||
void service.getLatestRevision(newNote).then((result) => {
|
||||
expect(result).toEqual(revisions[0]);
|
||||
});
|
||||
});
|
||||
|
@ -594,7 +600,7 @@ describe('NotesService', () => {
|
|||
describe('toNotePermissionsDto', () => {
|
||||
it('works', async () => {
|
||||
const user = User.create('hardcoded', 'Testy') as User;
|
||||
const group = Group.create('testGroup', 'testGroup') as Group;
|
||||
const group = Group.create('testGroup', 'testGroup');
|
||||
const note = Note.create(user);
|
||||
note.userPermissions = [
|
||||
{
|
||||
|
@ -610,7 +616,7 @@ describe('NotesService', () => {
|
|||
canEdit: true,
|
||||
},
|
||||
];
|
||||
const permissions = await service.toNotePermissionsDto(note);
|
||||
const permissions = service.toNotePermissionsDto(note);
|
||||
expect(permissions.owner.userName).toEqual(user.userName);
|
||||
expect(permissions.sharedToUsers).toHaveLength(1);
|
||||
expect(permissions.sharedToUsers[0].user.userName).toEqual(user.userName);
|
||||
|
@ -627,7 +633,7 @@ describe('NotesService', () => {
|
|||
it('works', async () => {
|
||||
const user = User.create('hardcoded', 'Testy') as User;
|
||||
const otherUser = User.create('other hardcoded', 'Testy2') as User;
|
||||
const group = Group.create('testGroup', 'testGroup') as Group;
|
||||
const group = Group.create('testGroup', 'testGroup');
|
||||
const content = 'testContent';
|
||||
jest
|
||||
.spyOn(noteRepo, 'save')
|
||||
|
@ -718,7 +724,7 @@ describe('NotesService', () => {
|
|||
const user = User.create('hardcoded', 'Testy') as User;
|
||||
const otherUser = User.create('other hardcoded', 'Testy2') as User;
|
||||
otherUser.userName = 'other hardcoded user';
|
||||
const group = Group.create('testGroup', 'testGroup') as Group;
|
||||
const group = Group.create('testGroup', 'testGroup');
|
||||
const content = 'testContent';
|
||||
jest
|
||||
.spyOn(noteRepo, 'save')
|
||||
|
|
|
@ -4,6 +4,12 @@
|
|||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
/* eslint-disable
|
||||
@typescript-eslint/no-unsafe-call,
|
||||
@typescript-eslint/no-unsafe-member-access,
|
||||
@typescript-eslint/no-unsafe-return,
|
||||
@typescript-eslint/require-await */
|
||||
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { LoggerModule } from '../logger/logger.module';
|
||||
import { GuestPermission, PermissionsService } from './permissions.service';
|
||||
|
@ -350,7 +356,7 @@ describe('PermissionsService', () => {
|
|||
for (const group2 of noteGroupPermissions[2]) {
|
||||
for (const group3 of noteGroupPermissions[3]) {
|
||||
for (const group4 of noteGroupPermissions[4]) {
|
||||
const insert = [];
|
||||
const insert: NoteGroupPermission[] = [];
|
||||
let readPermission = false;
|
||||
let writePermission = false;
|
||||
if (group0 !== null) {
|
||||
|
@ -408,7 +414,7 @@ describe('PermissionsService', () => {
|
|||
): NoteGroupPermission[][] {
|
||||
const results = [];
|
||||
|
||||
function permute(arr, memo) {
|
||||
function permute(arr: NoteGroupPermission[], memo: NoteGroupPermission[]) {
|
||||
let cur;
|
||||
|
||||
for (let i = 0; i < arr.length; i++) {
|
||||
|
@ -456,15 +462,15 @@ describe('PermissionsService', () => {
|
|||
note.groupPermissions = permission.permissions;
|
||||
let permissionString = '';
|
||||
for (const perm of permission.permissions) {
|
||||
permissionString += ' ' + perm.group.name + ':' + perm.canEdit;
|
||||
permissionString += ` ${perm.group.name}:${String(perm.canEdit)}`;
|
||||
}
|
||||
it('mayWrite - test #' + i + ':' + permissionString, () => {
|
||||
it(`mayWrite - test #${i}:${permissionString}`, () => {
|
||||
permissionsService.guestPermission = guestPermission;
|
||||
expect(permissionsService.mayWrite(user1, note)).toEqual(
|
||||
permission.allowsWrite,
|
||||
);
|
||||
});
|
||||
it('mayRead - test #' + i + ':' + permissionString, () => {
|
||||
it(`mayRead - test #${i}:${permissionString}`, () => {
|
||||
permissionsService.guestPermission = guestPermission;
|
||||
expect(permissionsService.mayRead(user1, note)).toEqual(
|
||||
permission.allowsRead,
|
||||
|
|
Loading…
Reference in a new issue