mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
fix: update eslint settings
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
describe('A basic test', (): void => {
|
||||
it('to have something pass.', async (): Promise<void> => {
|
||||
it('to have something pass.', async(): Promise<void> => {
|
||||
expect(true).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -11,7 +11,7 @@ describe('An AuthenticatedLdpHandler', (): void => {
|
||||
let args: AuthenticatedLdpHandlerArgs;
|
||||
let responseFn: jest.Mock<Promise<void>, [any]>;
|
||||
|
||||
beforeEach(async (): Promise<void> => {
|
||||
beforeEach(async(): Promise<void> => {
|
||||
const requestParser: RequestParser = new StaticAsyncHandler(true, 'parser' as any);
|
||||
const credentialsExtractor: CredentialsExtractor = new StaticAsyncHandler(true, 'credentials' as any);
|
||||
const permissionsExtractor: PermissionsExtractor = new StaticAsyncHandler(true, 'permissions' as any);
|
||||
@@ -19,7 +19,7 @@ describe('An AuthenticatedLdpHandler', (): void => {
|
||||
const operationHandler: OperationHandler = new StaticAsyncHandler(true, 'operation' as any);
|
||||
const responseWriter: ResponseWriter = new StaticAsyncHandler(true, 'response' as any);
|
||||
|
||||
responseFn = jest.fn(async (input: any): Promise<void> => {
|
||||
responseFn = jest.fn(async(input: any): Promise<void> => {
|
||||
if (!input) {
|
||||
throw new Error('error');
|
||||
}
|
||||
@@ -29,17 +29,17 @@ describe('An AuthenticatedLdpHandler', (): void => {
|
||||
args = { requestParser, credentialsExtractor, permissionsExtractor, authorizer, operationHandler, responseWriter };
|
||||
});
|
||||
|
||||
it('can be created.', async (): Promise<void> => {
|
||||
it('can be created.', async(): Promise<void> => {
|
||||
expect(new AuthenticatedLdpHandler(args)).toBeInstanceOf(AuthenticatedLdpHandler);
|
||||
});
|
||||
|
||||
it('can check if it handles input.', async (): Promise<void> => {
|
||||
it('can check if it handles input.', async(): Promise<void> => {
|
||||
const handler = new AuthenticatedLdpHandler(args);
|
||||
|
||||
await expect(handler.canHandle({ request: null, response: null })).resolves.toBeUndefined();
|
||||
});
|
||||
|
||||
it('can handle input.', async (): Promise<void> => {
|
||||
it('can handle input.', async(): Promise<void> => {
|
||||
const handler = new AuthenticatedLdpHandler(args);
|
||||
|
||||
await expect(handler.handle({ request: 'request' as any, response: 'response' as any })).resolves.toEqual('response');
|
||||
@@ -47,7 +47,7 @@ describe('An AuthenticatedLdpHandler', (): void => {
|
||||
expect(responseFn).toHaveBeenLastCalledWith({ response: 'response', operation: 'parser' as any });
|
||||
});
|
||||
|
||||
it('sends an error to the output if a handler does not support the input.', async (): Promise<void> => {
|
||||
it('sends an error to the output if a handler does not support the input.', async(): Promise<void> => {
|
||||
args.requestParser = new StaticAsyncHandler(false, null);
|
||||
const handler = new AuthenticatedLdpHandler(args);
|
||||
|
||||
@@ -56,7 +56,7 @@ describe('An AuthenticatedLdpHandler', (): void => {
|
||||
expect(responseFn.mock.calls[0][0].error).toBeInstanceOf(Error);
|
||||
});
|
||||
|
||||
it('errors if the response writer does not support the result.', async (): Promise< void> => {
|
||||
it('errors if the response writer does not support the result.', async(): Promise< void> => {
|
||||
args.responseWriter = new StaticAsyncHandler(false, null);
|
||||
const handler = new AuthenticatedLdpHandler(args);
|
||||
|
||||
|
||||
@@ -2,10 +2,10 @@ import { AsyncHandler } from '../../../src/util/AsyncHandler';
|
||||
import { StaticAsyncHandler } from '../../util/StaticAsyncHandler';
|
||||
|
||||
describe('An AsyncHandler', (): void => {
|
||||
it('calls canHandle and handle when handleSafe is called.', async (): Promise<void> => {
|
||||
it('calls canHandle and handle when handleSafe is called.', async(): Promise<void> => {
|
||||
const handlerTrue: AsyncHandler<any, any> = new StaticAsyncHandler(true, null);
|
||||
const canHandleFn = jest.fn(async (input: any): Promise<void> => input);
|
||||
const handleFn = jest.fn(async (input: any): Promise<any> => input);
|
||||
const canHandleFn = jest.fn(async(input: any): Promise<void> => input);
|
||||
const handleFn = jest.fn(async(input: any): Promise<any> => input);
|
||||
|
||||
handlerTrue.canHandle = canHandleFn;
|
||||
handlerTrue.handle = handleFn;
|
||||
@@ -14,12 +14,12 @@ describe('An AsyncHandler', (): void => {
|
||||
expect(handleFn).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('does not call handle when canHandle errors during a handleSafe call.', async (): Promise<void> => {
|
||||
it('does not call handle when canHandle errors during a handleSafe call.', async(): Promise<void> => {
|
||||
const handlerFalse: AsyncHandler<any, any> = new StaticAsyncHandler(false, null);
|
||||
const canHandleFn = jest.fn(async (): Promise<void> => {
|
||||
const canHandleFn = jest.fn(async(): Promise<void> => {
|
||||
throw new Error('test');
|
||||
});
|
||||
const handleFn = jest.fn(async (input: any): Promise<any> => input);
|
||||
const handleFn = jest.fn(async(input: any): Promise<any> => input);
|
||||
|
||||
handlerFalse.canHandle = canHandleFn;
|
||||
handlerFalse.handle = handleFn;
|
||||
|
||||
@@ -4,13 +4,13 @@ import { StaticAsyncHandler } from '../../util/StaticAsyncHandler';
|
||||
|
||||
describe('A CompositeAsyncHandler', (): void => {
|
||||
describe('with no handlers', (): void => {
|
||||
it('can never handle data.', async (): Promise<void> => {
|
||||
it('can never handle data.', async(): Promise<void> => {
|
||||
const handler = new CompositeAsyncHandler([]);
|
||||
|
||||
await expect(handler.canHandle(null)).rejects.toThrow(Error);
|
||||
});
|
||||
|
||||
it('errors if its handle function is called.', async (): Promise<void> => {
|
||||
it('errors if its handle function is called.', async(): Promise<void> => {
|
||||
const handler = new CompositeAsyncHandler([]);
|
||||
|
||||
await expect(handler.handle(null)).rejects.toThrow(Error);
|
||||
@@ -23,29 +23,29 @@ describe('A CompositeAsyncHandler', (): void => {
|
||||
let canHandleFn: jest.Mock<Promise<void>, [any]>;
|
||||
let handleFn: jest.Mock<Promise<void>, [any]>;
|
||||
|
||||
beforeEach(async (): Promise<void> => {
|
||||
beforeEach(async(): Promise<void> => {
|
||||
handlerTrue = new StaticAsyncHandler(true, null);
|
||||
handlerFalse = new StaticAsyncHandler(false, null);
|
||||
|
||||
canHandleFn = jest.fn(async (input: any): Promise<any> => input);
|
||||
handleFn = jest.fn(async (input: any): Promise<any> => input);
|
||||
canHandleFn = jest.fn(async(input: any): Promise<any> => input);
|
||||
handleFn = jest.fn(async(input: any): Promise<any> => input);
|
||||
handlerTrue.canHandle = canHandleFn;
|
||||
handlerTrue.handle = handleFn;
|
||||
});
|
||||
|
||||
it('can handle data if a handler supports it.', async (): Promise<void> => {
|
||||
it('can handle data if a handler supports it.', async(): Promise<void> => {
|
||||
const handler = new CompositeAsyncHandler([ handlerFalse, handlerTrue ]);
|
||||
|
||||
await expect(handler.canHandle(null)).resolves.toBeUndefined();
|
||||
});
|
||||
|
||||
it('can not handle data if no handler supports it.', async (): Promise<void> => {
|
||||
it('can not handle data if no handler supports it.', async(): Promise<void> => {
|
||||
const handler = new CompositeAsyncHandler([ handlerFalse, handlerFalse ]);
|
||||
|
||||
await expect(handler.canHandle(null)).rejects.toThrow('[Not supported., Not supported.]');
|
||||
});
|
||||
|
||||
it('handles data if a handler supports it.', async (): Promise<void> => {
|
||||
it('handles data if a handler supports it.', async(): Promise<void> => {
|
||||
const handler = new CompositeAsyncHandler([ handlerFalse, handlerTrue ]);
|
||||
|
||||
await expect(handler.handle('test')).resolves.toEqual('test');
|
||||
@@ -53,13 +53,13 @@ describe('A CompositeAsyncHandler', (): void => {
|
||||
expect(handleFn).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('errors if the handle function is called but no handler supports the data.', async (): Promise<void> => {
|
||||
it('errors if the handle function is called but no handler supports the data.', async(): Promise<void> => {
|
||||
const handler = new CompositeAsyncHandler([ handlerFalse, handlerFalse ]);
|
||||
|
||||
await expect(handler.handle('test')).rejects.toThrow('All handlers failed.');
|
||||
});
|
||||
|
||||
it('only calls the canHandle function once of its handlers when handleSafe is called.', async (): Promise<void> => {
|
||||
it('only calls the canHandle function once of its handlers when handleSafe is called.', async(): Promise<void> => {
|
||||
const handler = new CompositeAsyncHandler([ handlerFalse, handlerTrue ]);
|
||||
|
||||
await expect(handler.handleSafe('test')).resolves.toEqual('test');
|
||||
@@ -67,7 +67,7 @@ describe('A CompositeAsyncHandler', (): void => {
|
||||
expect(handleFn).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('throws the same error as canHandle when calling handleSafe if no handler supports the data.', async (): Promise<void> => {
|
||||
it('throws the same error as canHandle when calling handleSafe if no handler supports the data.', async(): Promise<void> => {
|
||||
const handler = new CompositeAsyncHandler([ handlerFalse, handlerFalse ]);
|
||||
|
||||
await expect(handler.handleSafe(null)).rejects.toThrow('[Not supported., Not supported.]');
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { UnsupportedHttpError } from '../../../../src/util/errors/UnsupportedHttpError';
|
||||
|
||||
describe('An UnsupportedHttpError', (): void => {
|
||||
it('has status code 400.', async (): Promise<void> => {
|
||||
it('has status code 400.', async(): Promise<void> => {
|
||||
const error = new UnsupportedHttpError('test');
|
||||
|
||||
expect(error.statusCode).toEqual(400);
|
||||
@@ -9,7 +9,7 @@ describe('An UnsupportedHttpError', (): void => {
|
||||
expect(error.name).toEqual('UnsupportedHttpError');
|
||||
});
|
||||
|
||||
it('has a default message if none was provided.', async (): Promise<void> => {
|
||||
it('has a default message if none was provided.', async(): Promise<void> => {
|
||||
const error = new UnsupportedHttpError();
|
||||
|
||||
expect(error.message).toEqual('The given input is not supported by the server configuration.');
|
||||
|
||||
@@ -2,23 +2,22 @@ import { AsyncHandler } from '../../src/util/AsyncHandler';
|
||||
|
||||
export class StaticAsyncHandler<TOut> extends AsyncHandler<any, TOut> {
|
||||
private readonly canHandleStatic: boolean;
|
||||
|
||||
private readonly handleStatic: TOut;
|
||||
|
||||
public constructor (canHandleStatic: boolean, handleStatic: TOut) {
|
||||
public constructor(canHandleStatic: boolean, handleStatic: TOut) {
|
||||
super();
|
||||
this.canHandleStatic = canHandleStatic;
|
||||
this.handleStatic = handleStatic;
|
||||
}
|
||||
|
||||
public async canHandle (): Promise<void> {
|
||||
public async canHandle(): Promise<void> {
|
||||
if (this.canHandleStatic) {
|
||||
return;
|
||||
}
|
||||
throw new Error('Not supported.');
|
||||
}
|
||||
|
||||
public async handle (): Promise<TOut> {
|
||||
public async handle(): Promise<TOut> {
|
||||
return this.handleStatic;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user