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