mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-03-21 03:24:19 +00:00
Merge pull request #1133 from hedgedoc/eslint/tests
This commit is contained in:
commit
2192153c30
17 changed files with 140 additions and 212 deletions
21
.eslintrc.js
21
.eslintrc.js
|
@ -8,7 +8,26 @@ module.exports = {
|
|||
project: 'tsconfig.json',
|
||||
sourceType: 'module',
|
||||
},
|
||||
plugins: ['@typescript-eslint'],
|
||||
overrides: [
|
||||
{
|
||||
files: ['test/**', 'src/**/*.spec.ts'],
|
||||
extends: ['plugin:jest/recommended'],
|
||||
rules: {
|
||||
'@typescript-eslint/unbound-method': 'off',
|
||||
'@typescript-eslint/no-unsafe-assignment': 'off',
|
||||
'@typescript-eslint/no-unsafe-member-access': 'off',
|
||||
'@typescript-eslint/require-await': 'off',
|
||||
'jest/unbound-method': 'error',
|
||||
'jest/expect-expect': [
|
||||
'error',
|
||||
{
|
||||
assertFunctionNames: ['expect', 'request.**.expect'],
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
plugins: ['@typescript-eslint', 'jest'],
|
||||
extends: [
|
||||
'eslint:recommended',
|
||||
'plugin:@typescript-eslint/recommended',
|
||||
|
|
|
@ -35,14 +35,15 @@
|
|||
"@nestjs/typeorm": "7.1.5",
|
||||
"@types/bcrypt": "3.0.1",
|
||||
"@types/cron": "1.7.2",
|
||||
"@types/node-fetch": "2.5.10",
|
||||
"@types/minio": "7.0.7",
|
||||
"@types/node-fetch": "2.5.10",
|
||||
"@types/passport-http-bearer": "1.0.36",
|
||||
"bcrypt": "5.0.1",
|
||||
"class-transformer": "0.4.0",
|
||||
"class-validator": "0.13.1",
|
||||
"cli-color": "2.0.0",
|
||||
"connect-typeorm": "1.1.4",
|
||||
"eslint-plugin-jest": "^24.3.5",
|
||||
"file-type": "16.3.0",
|
||||
"joi": "17.4.0",
|
||||
"minio": "7.0.18",
|
||||
|
|
|
@ -4,12 +4,6 @@
|
|||
* 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';
|
||||
|
@ -70,17 +64,17 @@ describe('AuthService', () => {
|
|||
it('works', async () => {
|
||||
const testPassword = 'thisIsATestPassword';
|
||||
const hash = await service.hashPassword(testPassword);
|
||||
void service
|
||||
await service
|
||||
.checkPassword(testPassword, hash)
|
||||
.then((result) => expect(result).toBeTruthy());
|
||||
});
|
||||
it('fails, if secret is too short', async () => {
|
||||
const secret = service.bufferToBase64Url(service.randomString(54));
|
||||
const hash = await service.hashPassword(secret);
|
||||
void service
|
||||
await service
|
||||
.checkPassword(secret, hash)
|
||||
.then((result) => expect(result).toBeTruthy());
|
||||
void service
|
||||
await service
|
||||
.checkPassword(secret.substr(0, secret.length - 1), hash)
|
||||
.then((result) => expect(result).toBeFalsy());
|
||||
});
|
||||
|
@ -119,11 +113,9 @@ describe('AuthService', () => {
|
|||
describe('fails:', () => {
|
||||
it('AuthToken could not be found', async () => {
|
||||
jest.spyOn(authTokenRepo, 'findOne').mockResolvedValueOnce(undefined);
|
||||
try {
|
||||
await service.getAuthTokenAndValidate(authToken.keyId, token);
|
||||
} catch (e) {
|
||||
expect(e).toBeInstanceOf(NotInDBError);
|
||||
}
|
||||
await expect(
|
||||
service.getAuthTokenAndValidate(authToken.keyId, token),
|
||||
).rejects.toThrow(NotInDBError);
|
||||
});
|
||||
it('AuthToken has wrong hash', async () => {
|
||||
jest.spyOn(authTokenRepo, 'findOne').mockResolvedValueOnce({
|
||||
|
@ -131,11 +123,9 @@ describe('AuthService', () => {
|
|||
user: user,
|
||||
accessTokenHash: 'the wrong hash',
|
||||
});
|
||||
try {
|
||||
await service.getAuthTokenAndValidate(authToken.keyId, token);
|
||||
} catch (e) {
|
||||
expect(e).toBeInstanceOf(TokenNotValidError);
|
||||
}
|
||||
await expect(
|
||||
service.getAuthTokenAndValidate(authToken.keyId, token),
|
||||
).rejects.toThrow(TokenNotValidError);
|
||||
});
|
||||
it('AuthToken has wrong validUntil Date', async () => {
|
||||
const accessTokenHash = await service.hashPassword(token);
|
||||
|
@ -145,11 +135,9 @@ describe('AuthService', () => {
|
|||
accessTokenHash: accessTokenHash,
|
||||
validUntil: new Date(1549312452000),
|
||||
});
|
||||
try {
|
||||
await service.getAuthTokenAndValidate(authToken.keyId, token);
|
||||
} catch (e) {
|
||||
expect(e).toBeInstanceOf(TokenNotValidError);
|
||||
}
|
||||
await expect(
|
||||
service.getAuthTokenAndValidate(authToken.keyId, token),
|
||||
).rejects.toThrow(TokenNotValidError);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -161,13 +149,13 @@ describe('AuthService', () => {
|
|||
user: user,
|
||||
lastUsed: new Date(1549312452000),
|
||||
});
|
||||
jest
|
||||
.spyOn(authTokenRepo, 'save')
|
||||
.mockImplementationOnce(async (authTokenSaved, _) => {
|
||||
jest.spyOn(authTokenRepo, 'save').mockImplementationOnce(
|
||||
async (authTokenSaved, _): Promise<AuthToken> => {
|
||||
expect(authTokenSaved.keyId).toEqual(authToken.keyId);
|
||||
expect(authTokenSaved.lastUsed).not.toEqual(1549312452000);
|
||||
return authToken;
|
||||
});
|
||||
},
|
||||
);
|
||||
await service.setLastUsedToken(authToken.keyId);
|
||||
});
|
||||
});
|
||||
|
@ -185,11 +173,11 @@ describe('AuthService', () => {
|
|||
user: user,
|
||||
accessTokenHash: accessTokenHash,
|
||||
});
|
||||
jest
|
||||
.spyOn(authTokenRepo, 'save')
|
||||
.mockImplementationOnce(async (_, __) => {
|
||||
jest.spyOn(authTokenRepo, 'save').mockImplementationOnce(
|
||||
async (_, __): Promise<AuthToken> => {
|
||||
return authToken;
|
||||
});
|
||||
},
|
||||
);
|
||||
const userByToken = await service.validateToken(
|
||||
`${authToken.keyId}.${token}`,
|
||||
);
|
||||
|
@ -199,15 +187,15 @@ describe('AuthService', () => {
|
|||
});
|
||||
});
|
||||
describe('fails:', () => {
|
||||
it('the secret is missing', () => {
|
||||
void expect(
|
||||
it('the secret is missing', async () => {
|
||||
await expect(
|
||||
service.validateToken(`${authToken.keyId}`),
|
||||
).rejects.toBeInstanceOf(TokenNotValidError);
|
||||
).rejects.toThrow(TokenNotValidError);
|
||||
});
|
||||
it('the secret is too long', () => {
|
||||
void expect(
|
||||
it('the secret is too long', async () => {
|
||||
await expect(
|
||||
service.validateToken(`${authToken.keyId}.${'a'.repeat(73)}`),
|
||||
).rejects.toBeInstanceOf(TokenNotValidError);
|
||||
).rejects.toThrow(TokenNotValidError);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -218,15 +206,15 @@ describe('AuthService', () => {
|
|||
...authToken,
|
||||
user: user,
|
||||
});
|
||||
jest
|
||||
.spyOn(authTokenRepo, 'remove')
|
||||
.mockImplementationOnce(async (token, __) => {
|
||||
jest.spyOn(authTokenRepo, 'remove').mockImplementationOnce(
|
||||
async (token, __): Promise<AuthToken> => {
|
||||
expect(token).toEqual({
|
||||
...authToken,
|
||||
user: user,
|
||||
});
|
||||
return authToken;
|
||||
});
|
||||
},
|
||||
);
|
||||
await service.removeToken(authToken.keyId);
|
||||
});
|
||||
});
|
||||
|
@ -239,12 +227,12 @@ describe('AuthService', () => {
|
|||
...user,
|
||||
authTokens: [authToken],
|
||||
});
|
||||
jest
|
||||
.spyOn(authTokenRepo, 'save')
|
||||
.mockImplementationOnce(async (authTokenSaved: AuthToken, _) => {
|
||||
jest.spyOn(authTokenRepo, 'save').mockImplementationOnce(
|
||||
async (authTokenSaved: AuthToken, _): Promise<AuthToken> => {
|
||||
expect(authTokenSaved.lastUsed).toBeUndefined();
|
||||
return authTokenSaved;
|
||||
});
|
||||
},
|
||||
);
|
||||
const token = await service.createTokenForUser(
|
||||
user.userName,
|
||||
identifier,
|
||||
|
@ -263,12 +251,12 @@ describe('AuthService', () => {
|
|||
...user,
|
||||
authTokens: [authToken],
|
||||
});
|
||||
jest
|
||||
.spyOn(authTokenRepo, 'save')
|
||||
.mockImplementationOnce(async (authTokenSaved: AuthToken, _) => {
|
||||
jest.spyOn(authTokenRepo, 'save').mockImplementationOnce(
|
||||
async (authTokenSaved: AuthToken, _): Promise<AuthToken> => {
|
||||
expect(authTokenSaved.lastUsed).toBeUndefined();
|
||||
return authTokenSaved;
|
||||
});
|
||||
},
|
||||
);
|
||||
const validUntil = new Date().getTime() + 30000;
|
||||
const token = await service.createTokenForUser(
|
||||
user.userName,
|
||||
|
@ -294,7 +282,7 @@ describe('AuthService', () => {
|
|||
});
|
||||
|
||||
describe('toAuthTokenDto', () => {
|
||||
it('works', async () => {
|
||||
it('works', () => {
|
||||
const authToken = new AuthToken();
|
||||
authToken.keyId = 'testKeyId';
|
||||
authToken.label = 'testLabel';
|
||||
|
|
|
@ -4,12 +4,6 @@
|
|||
* 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 {
|
||||
replaceAuthErrorsWithEnvironmentVariables,
|
||||
toArrayConfig,
|
||||
|
@ -34,7 +28,7 @@ describe('config utils', () => {
|
|||
]);
|
||||
});
|
||||
});
|
||||
describe('toArrayConfig', () => {
|
||||
describe('replaceAuthErrorsWithEnvironmentVariables', () => {
|
||||
it('"gitlab[0].scope', () => {
|
||||
expect(
|
||||
replaceAuthErrorsWithEnvironmentVariables(
|
||||
|
|
|
@ -16,6 +16,10 @@ import { AppConfig } from '../config/app.config';
|
|||
import { ExternalServicesConfig } from '../config/external-services.config';
|
||||
import { Loglevel } from '../config/loglevel.enum';
|
||||
|
||||
/* eslint-disable
|
||||
jest/no-conditional-expect
|
||||
*/
|
||||
|
||||
describe('FrontendConfigService', () => {
|
||||
const emptyAuthConfig: AuthConfig = {
|
||||
email: {
|
||||
|
|
|
@ -48,11 +48,9 @@ describe('GroupsService', () => {
|
|||
});
|
||||
it('fails with non-existing group', async () => {
|
||||
jest.spyOn(groupRepo, 'findOne').mockResolvedValueOnce(undefined);
|
||||
try {
|
||||
await service.getGroupByName('i_dont_exist');
|
||||
} catch (e) {
|
||||
expect(e).toBeInstanceOf(NotInDBError);
|
||||
}
|
||||
await expect(service.getGroupByName('i_dont_exist')).rejects.toThrow(
|
||||
NotInDBError,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -4,12 +4,6 @@
|
|||
* 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';
|
||||
|
@ -138,11 +132,9 @@ describe('HistoryService', () => {
|
|||
describe('fails', () => {
|
||||
it('with an non-existing note', async () => {
|
||||
jest.spyOn(noteRepo, 'findOne').mockResolvedValueOnce(undefined);
|
||||
try {
|
||||
await service.getEntryByNoteIdOrAlias(alias, {} as User);
|
||||
} catch (e) {
|
||||
expect(e).toBeInstanceOf(NotInDBError);
|
||||
}
|
||||
await expect(
|
||||
service.getEntryByNoteIdOrAlias(alias, {} as User),
|
||||
).rejects.toThrow(NotInDBError);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -229,13 +221,11 @@ describe('HistoryService', () => {
|
|||
const note = Note.create(user, alias);
|
||||
jest.spyOn(historyRepo, 'findOne').mockResolvedValueOnce(undefined);
|
||||
jest.spyOn(noteRepo, 'findOne').mockResolvedValueOnce(note);
|
||||
try {
|
||||
await service.updateHistoryEntry(alias, user, {
|
||||
await expect(
|
||||
service.updateHistoryEntry(alias, user, {
|
||||
pinStatus: true,
|
||||
});
|
||||
} catch (e) {
|
||||
expect(e).toBeInstanceOf(NotInDBError);
|
||||
}
|
||||
}),
|
||||
).rejects.toThrow(NotInDBError);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -282,6 +272,7 @@ describe('HistoryService', () => {
|
|||
it('without an entry', async () => {
|
||||
jest.spyOn(historyRepo, 'find').mockResolvedValueOnce([]);
|
||||
await service.deleteHistory(user);
|
||||
expect(true).toBeTruthy();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -311,19 +302,15 @@ describe('HistoryService', () => {
|
|||
const note = Note.create(user, alias);
|
||||
jest.spyOn(historyRepo, 'findOne').mockResolvedValueOnce(undefined);
|
||||
jest.spyOn(noteRepo, 'findOne').mockResolvedValueOnce(note);
|
||||
try {
|
||||
await service.deleteHistoryEntry(alias, user);
|
||||
} catch (e) {
|
||||
expect(e).toBeInstanceOf(NotInDBError);
|
||||
}
|
||||
await expect(service.deleteHistoryEntry(alias, user)).rejects.toThrow(
|
||||
NotInDBError,
|
||||
);
|
||||
});
|
||||
it('without a note', async () => {
|
||||
jest.spyOn(noteRepo, 'findOne').mockResolvedValueOnce(undefined);
|
||||
try {
|
||||
await service.getEntryByNoteIdOrAlias(alias, {} as User);
|
||||
} catch (e) {
|
||||
expect(e).toBeInstanceOf(NotInDBError);
|
||||
}
|
||||
await expect(
|
||||
service.getEntryByNoteIdOrAlias(alias, {} as User),
|
||||
).rejects.toThrow(NotInDBError);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -4,12 +4,6 @@
|
|||
* 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';
|
||||
|
@ -135,24 +129,16 @@ describe('MediaService', () => {
|
|||
|
||||
describe('fails:', () => {
|
||||
it('MIME type not identifiable', async () => {
|
||||
try {
|
||||
await service.saveFile(Buffer.alloc(1), 'hardcoded', 'test');
|
||||
} catch (e) {
|
||||
expect(e).toBeInstanceOf(ClientError);
|
||||
expect(e.message).toContain('detect');
|
||||
}
|
||||
await expect(
|
||||
service.saveFile(Buffer.alloc(1), 'hardcoded', 'test'),
|
||||
).rejects.toThrow(ClientError);
|
||||
});
|
||||
|
||||
it('MIME type not supported', async () => {
|
||||
try {
|
||||
const testText = await fs.readFile(
|
||||
'test/public-api/fixtures/test.zip',
|
||||
);
|
||||
await service.saveFile(testText, 'hardcoded', 'test');
|
||||
} catch (e) {
|
||||
expect(e).toBeInstanceOf(ClientError);
|
||||
expect(e.message).not.toContain('detect');
|
||||
}
|
||||
const testText = await fs.readFile('test/public-api/fixtures/test.zip');
|
||||
await expect(
|
||||
service.saveFile(testText, 'hardcoded', 'test'),
|
||||
).rejects.toThrow(ClientError);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -197,36 +183,36 @@ describe('MediaService', () => {
|
|||
jest
|
||||
.spyOn(mediaRepo, 'findOne')
|
||||
.mockResolvedValueOnce(mockMediaUploadEntry);
|
||||
try {
|
||||
await service.deleteFile(testFileName, 'hardcoded');
|
||||
} catch (e) {
|
||||
expect(e).toBeInstanceOf(PermissionError);
|
||||
}
|
||||
await expect(
|
||||
service.deleteFile(testFileName, 'hardcoded'),
|
||||
).rejects.toThrow(PermissionError);
|
||||
});
|
||||
});
|
||||
describe('findUploadByFilename', () => {
|
||||
it('works', async () => {
|
||||
const testFileName = 'testFilename';
|
||||
const userName = 'hardcoded';
|
||||
const backendData = 'testBackendData';
|
||||
const mockMediaUploadEntry = {
|
||||
id: 'testMediaUpload',
|
||||
backendData: 'testBackendData',
|
||||
backendData: backendData,
|
||||
user: {
|
||||
userName: 'hardcoded',
|
||||
userName: userName,
|
||||
} as User,
|
||||
} as MediaUpload;
|
||||
jest
|
||||
.spyOn(mediaRepo, 'findOne')
|
||||
.mockResolvedValueOnce(mockMediaUploadEntry);
|
||||
await service.findUploadByFilename(testFileName);
|
||||
const mediaUpload = await service.findUploadByFilename(testFileName);
|
||||
expect(mediaUpload.user.userName).toEqual(userName);
|
||||
expect(mediaUpload.backendData).toEqual(backendData);
|
||||
});
|
||||
it("fails: can't find mediaUpload", async () => {
|
||||
const testFileName = 'testFilename';
|
||||
jest.spyOn(mediaRepo, 'findOne').mockResolvedValueOnce(undefined);
|
||||
try {
|
||||
await service.findUploadByFilename(testFileName);
|
||||
} catch (e) {
|
||||
expect(e).toBeInstanceOf(NotInDBError);
|
||||
}
|
||||
await expect(service.findUploadByFilename(testFileName)).rejects.toThrow(
|
||||
NotInDBError,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -4,12 +4,6 @@
|
|||
* 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';
|
||||
|
@ -202,22 +196,18 @@ describe('NotesService', () => {
|
|||
});
|
||||
describe('fails:', () => {
|
||||
it('alias is forbidden', async () => {
|
||||
try {
|
||||
await service.createNote(content, forbiddenNoteId);
|
||||
} catch (e) {
|
||||
expect(e).toBeInstanceOf(ForbiddenIdError);
|
||||
}
|
||||
await expect(
|
||||
service.createNote(content, forbiddenNoteId),
|
||||
).rejects.toThrow(ForbiddenIdError);
|
||||
});
|
||||
|
||||
it('alias is already used', async () => {
|
||||
jest.spyOn(noteRepo, 'save').mockImplementationOnce(async () => {
|
||||
throw new Error();
|
||||
});
|
||||
try {
|
||||
await service.createNote(content, alias);
|
||||
} catch (e) {
|
||||
expect(e).toBeInstanceOf(AlreadyInDBError);
|
||||
}
|
||||
await expect(service.createNote(content, alias)).rejects.toThrow(
|
||||
AlreadyInDBError,
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -231,7 +221,7 @@ describe('NotesService', () => {
|
|||
const newNote = await service.createNote(content);
|
||||
const revisions = await newNote.revisions;
|
||||
jest.spyOn(revisionRepo, 'findOne').mockResolvedValueOnce(revisions[0]);
|
||||
void service.getNoteContent(newNote).then((result) => {
|
||||
await service.getNoteContent(newNote).then((result) => {
|
||||
expect(result).toEqual(content);
|
||||
});
|
||||
});
|
||||
|
@ -246,7 +236,7 @@ describe('NotesService', () => {
|
|||
const newNote = await service.createNote(content);
|
||||
const revisions = await newNote.revisions;
|
||||
jest.spyOn(revisionRepo, 'findOne').mockResolvedValueOnce(revisions[0]);
|
||||
void service.getLatestRevision(newNote).then((result) => {
|
||||
await service.getLatestRevision(newNote).then((result) => {
|
||||
expect(result).toEqual(revisions[0]);
|
||||
});
|
||||
});
|
||||
|
@ -263,7 +253,7 @@ describe('NotesService', () => {
|
|||
const newNote = await service.createNote(content);
|
||||
const revisions = await newNote.revisions;
|
||||
jest.spyOn(revisionRepo, 'findOne').mockResolvedValueOnce(revisions[0]);
|
||||
void service.getLatestRevision(newNote).then((result) => {
|
||||
await service.getLatestRevision(newNote).then((result) => {
|
||||
expect(result).toEqual(revisions[0]);
|
||||
});
|
||||
});
|
||||
|
@ -280,19 +270,15 @@ describe('NotesService', () => {
|
|||
describe('fails:', () => {
|
||||
it('no note found', async () => {
|
||||
jest.spyOn(noteRepo, 'findOne').mockResolvedValueOnce(undefined);
|
||||
try {
|
||||
await service.getNoteByIdOrAlias('noteThatDoesNoteExist');
|
||||
} catch (e) {
|
||||
expect(e).toBeInstanceOf(NotInDBError);
|
||||
}
|
||||
await expect(
|
||||
service.getNoteByIdOrAlias('noteThatDoesNoteExist'),
|
||||
).rejects.toThrow(NotInDBError);
|
||||
});
|
||||
it('id is forbidden', async () => {
|
||||
jest.spyOn(noteRepo, 'findOne').mockResolvedValueOnce(undefined);
|
||||
try {
|
||||
await service.getNoteByIdOrAlias(forbiddenNoteId);
|
||||
} catch (e) {
|
||||
expect(e).toBeInstanceOf(ForbiddenIdError);
|
||||
}
|
||||
await expect(
|
||||
service.getNoteByIdOrAlias(forbiddenNoteId),
|
||||
).rejects.toThrow(ForbiddenIdError);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -593,36 +579,30 @@ describe('NotesService', () => {
|
|||
});
|
||||
describe('fails:', () => {
|
||||
it('userPermissions has duplicate entries', async () => {
|
||||
try {
|
||||
await service.updateNotePermissions(note, {
|
||||
await expect(
|
||||
service.updateNotePermissions(note, {
|
||||
sharedToUsers: [userPermissionUpdate, userPermissionUpdate],
|
||||
sharedToGroups: [],
|
||||
});
|
||||
} catch (e) {
|
||||
expect(e).toBeInstanceOf(PermissionsUpdateInconsistentError);
|
||||
}
|
||||
}),
|
||||
).rejects.toThrow(PermissionsUpdateInconsistentError);
|
||||
});
|
||||
|
||||
it('groupPermissions has duplicate entries', async () => {
|
||||
try {
|
||||
await service.updateNotePermissions(note, {
|
||||
await expect(
|
||||
service.updateNotePermissions(note, {
|
||||
sharedToUsers: [],
|
||||
sharedToGroups: [groupPermissionUpate, groupPermissionUpate],
|
||||
});
|
||||
} catch (e) {
|
||||
expect(e).toBeInstanceOf(PermissionsUpdateInconsistentError);
|
||||
}
|
||||
}),
|
||||
).rejects.toThrow(PermissionsUpdateInconsistentError);
|
||||
});
|
||||
|
||||
it('userPermissions and groupPermissions have duplicate entries', async () => {
|
||||
try {
|
||||
await service.updateNotePermissions(note, {
|
||||
await expect(
|
||||
service.updateNotePermissions(note, {
|
||||
sharedToUsers: [userPermissionUpdate, userPermissionUpdate],
|
||||
sharedToGroups: [groupPermissionUpate, groupPermissionUpate],
|
||||
});
|
||||
} catch (e) {
|
||||
expect(e).toBeInstanceOf(PermissionsUpdateInconsistentError);
|
||||
}
|
||||
}),
|
||||
).rejects.toThrow(PermissionsUpdateInconsistentError);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -4,12 +4,6 @@
|
|||
* 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 { getRepositoryToken } from '@nestjs/typeorm';
|
||||
import { AuthToken } from '../auth/auth-token.entity';
|
||||
|
@ -425,13 +419,13 @@ describe('PermissionsService', () => {
|
|||
function permutator(
|
||||
inputArr: NoteGroupPermission[],
|
||||
): NoteGroupPermission[][] {
|
||||
const results = [];
|
||||
const results: NoteGroupPermission[][] = [];
|
||||
|
||||
function permute(
|
||||
arr: NoteGroupPermission[],
|
||||
memo: NoteGroupPermission[],
|
||||
): NoteGroupPermission[][] {
|
||||
let cur;
|
||||
let cur: NoteGroupPermission[];
|
||||
|
||||
for (let i = 0; i < arr.length; i++) {
|
||||
cur = arr.splice(i, 1);
|
||||
|
|
|
@ -4,11 +4,6 @@
|
|||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
/* eslint-disable
|
||||
@typescript-eslint/no-unsafe-assignment,
|
||||
@typescript-eslint/no-unsafe-member-access
|
||||
*/
|
||||
|
||||
import { INestApplication } from '@nestjs/common';
|
||||
import { ConfigModule } from '@nestjs/config';
|
||||
import { Test } from '@nestjs/testing';
|
||||
|
|
|
@ -4,11 +4,6 @@
|
|||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
/* eslint-disable
|
||||
@typescript-eslint/no-unsafe-assignment,
|
||||
@typescript-eslint/no-unsafe-member-access
|
||||
*/
|
||||
|
||||
import { ConfigModule, ConfigService } from '@nestjs/config';
|
||||
import { NestExpressApplication } from '@nestjs/platform-express';
|
||||
import { Test } from '@nestjs/testing';
|
||||
|
|
|
@ -4,11 +4,6 @@
|
|||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
/* eslint-disable
|
||||
@typescript-eslint/no-unsafe-assignment,
|
||||
@typescript-eslint/no-unsafe-member-access
|
||||
*/
|
||||
|
||||
import { INestApplication } from '@nestjs/common';
|
||||
import { ConfigModule, ConfigService } from '@nestjs/config';
|
||||
import { Test } from '@nestjs/testing';
|
||||
|
|
|
@ -4,11 +4,6 @@
|
|||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
/* eslint-disable
|
||||
@typescript-eslint/no-unsafe-assignment,
|
||||
@typescript-eslint/no-unsafe-member-access
|
||||
*/
|
||||
|
||||
import { INestApplication } from '@nestjs/common';
|
||||
import { Test } from '@nestjs/testing';
|
||||
import * as request from 'supertest';
|
||||
|
|
|
@ -4,11 +4,6 @@
|
|||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
/* eslint-disable
|
||||
@typescript-eslint/no-unsafe-assignment,
|
||||
@typescript-eslint/no-unsafe-member-access
|
||||
*/
|
||||
|
||||
import { ConfigModule, ConfigService } from '@nestjs/config';
|
||||
import { NestExpressApplication } from '@nestjs/platform-express';
|
||||
import { Test } from '@nestjs/testing';
|
||||
|
|
|
@ -4,11 +4,6 @@
|
|||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
/* eslint-disable
|
||||
@typescript-eslint/no-unsafe-assignment,
|
||||
@typescript-eslint/no-unsafe-member-access
|
||||
*/
|
||||
|
||||
import { INestApplication } from '@nestjs/common';
|
||||
import { ConfigModule, ConfigService } from '@nestjs/config';
|
||||
import { Test } from '@nestjs/testing';
|
||||
|
|
|
@ -1309,7 +1309,7 @@
|
|||
semver "^7.3.2"
|
||||
tsutils "^3.17.1"
|
||||
|
||||
"@typescript-eslint/experimental-utils@4.22.0":
|
||||
"@typescript-eslint/experimental-utils@4.22.0", "@typescript-eslint/experimental-utils@^4.0.1":
|
||||
version "4.22.0"
|
||||
resolved "https://registry.yarnpkg.com/@typescript-eslint/experimental-utils/-/experimental-utils-4.22.0.tgz#68765167cca531178e7b650a53456e6e0bef3b1f"
|
||||
integrity sha512-xJXHHl6TuAxB5AWiVrGhvbGL8/hbiCQ8FiWwObO3r0fnvBdrbWEDy1hlvGQOAWc6qsCWuWMKdVWlLAEMpxnddg==
|
||||
|
@ -2940,6 +2940,13 @@ eslint-plugin-import@2.22.1:
|
|||
resolve "^1.17.0"
|
||||
tsconfig-paths "^3.9.0"
|
||||
|
||||
eslint-plugin-jest@^24.3.5:
|
||||
version "24.3.5"
|
||||
resolved "https://registry.yarnpkg.com/eslint-plugin-jest/-/eslint-plugin-jest-24.3.5.tgz#71f0b580f87915695c286c3f0eb88cf23664d044"
|
||||
integrity sha512-XG4rtxYDuJykuqhsOqokYIR84/C8pRihRtEpVskYLbIIKGwPNW2ySxdctuVzETZE+MbF/e7wmsnbNVpzM0rDug==
|
||||
dependencies:
|
||||
"@typescript-eslint/experimental-utils" "^4.0.1"
|
||||
|
||||
eslint-scope@^5.0.0, eslint-scope@^5.1.1:
|
||||
version "5.1.1"
|
||||
resolved "https://registry.yarnpkg.com/eslint-scope/-/eslint-scope-5.1.1.tgz#e786e59a66cb92b3f6c1fb0d508aab174848f48c"
|
||||
|
|
Loading…
Reference in a new issue