mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
fix: Enable strict TypeScript settings
This commit is contained in:
@@ -118,7 +118,7 @@ describe('An AuthenticatedLdpHandler', (): void => {
|
||||
});
|
||||
|
||||
describe('with simple PATCH handlers', (): void => {
|
||||
const bodyParser: BodyParser = new CompositeAsyncHandler<HttpRequest, Representation>([
|
||||
const bodyParser: BodyParser = new CompositeAsyncHandler<HttpRequest, Representation | undefined>([
|
||||
new SimpleBodyParser(),
|
||||
new SimpleSparqlUpdateBodyParser(),
|
||||
]);
|
||||
|
||||
@@ -44,7 +44,7 @@ describe('A SimpleRequestParser with simple input parsers', (): void => {
|
||||
},
|
||||
});
|
||||
|
||||
await expect(arrayifyStream(result.body.data)).resolves.toEqualRdfQuadArray([ triple(
|
||||
await expect(arrayifyStream(result.body!.data)).resolves.toEqualRdfQuadArray([ triple(
|
||||
namedNode('http://test.com/s'),
|
||||
namedNode('http://test.com/p'),
|
||||
namedNode('http://test.com/o'),
|
||||
|
||||
@@ -9,7 +9,7 @@ describe('A SimpleCredentialsExtractor', (): void => {
|
||||
});
|
||||
|
||||
it('returns undefined if there is no input.', async(): Promise<void> => {
|
||||
await expect(extractor.handle({ headers: {}} as HttpRequest)).resolves.toBeUndefined();
|
||||
await expect(extractor.handle({ headers: {}} as HttpRequest)).resolves.toEqual({});
|
||||
});
|
||||
|
||||
it('returns the authorization header as webID if there is one.', async(): Promise<void> => {
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import { Authorizer } from '../../../src/authorization/Authorizer';
|
||||
import { CredentialsExtractor } from '../../../src/authentication/CredentialsExtractor';
|
||||
import { HttpRequest } from '../../../src/server/HttpRequest';
|
||||
import { HttpResponse } from '../../../src/server/HttpResponse';
|
||||
import { Operation } from '../../../src/ldp/operations/Operation';
|
||||
import { OperationHandler } from '../../../src/ldp/operations/OperationHandler';
|
||||
import { PermissionsExtractor } from '../../../src/ldp/permissions/PermissionsExtractor';
|
||||
import { RequestParser } from '../../../src/ldp/http/RequestParser';
|
||||
@@ -36,30 +39,30 @@ describe('An AuthenticatedLdpHandler', (): 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();
|
||||
await expect(handler.canHandle({ request: {} as HttpRequest, response: {} as HttpResponse })).resolves.toBeUndefined();
|
||||
});
|
||||
|
||||
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(undefined);
|
||||
await expect(handler.handle({ request: 'request' as any, response: 'response' as any })).resolves.toBeUndefined();
|
||||
expect(responseFn).toHaveBeenCalledTimes(1);
|
||||
expect(responseFn).toHaveBeenLastCalledWith({ response: 'response', description: 'operation' as any });
|
||||
expect(responseFn).toHaveBeenLastCalledWith({ response: 'response', result: 'operation' as any });
|
||||
});
|
||||
|
||||
it('sends an error to the output if a handler does not support the input.', async(): Promise<void> => {
|
||||
args.requestParser = new StaticAsyncHandler(false, null);
|
||||
args.requestParser = new StaticAsyncHandler(false, {} as Operation);
|
||||
const handler = new AuthenticatedLdpHandler(args);
|
||||
|
||||
await expect(handler.handle({ request: 'request' as any, response: null })).resolves.toEqual(undefined);
|
||||
await expect(handler.handle({ request: 'request' as any, response: {} as HttpResponse })).resolves.toBeUndefined();
|
||||
expect(responseFn).toHaveBeenCalledTimes(1);
|
||||
expect(responseFn.mock.calls[0][0].error).toBeInstanceOf(Error);
|
||||
expect(responseFn.mock.calls[0][0].result).toBeInstanceOf(Error);
|
||||
});
|
||||
|
||||
it('errors if the response writer does not support the result.', async(): Promise< void> => {
|
||||
args.responseWriter = new StaticAsyncHandler(false, null);
|
||||
args.responseWriter = new StaticAsyncHandler(false, undefined);
|
||||
const handler = new AuthenticatedLdpHandler(args);
|
||||
|
||||
await expect(handler.handle({ request: 'request' as any, response: null })).rejects.toThrow(Error);
|
||||
await expect(handler.handle({ request: 'request' as any, response: {} as HttpResponse })).rejects.toThrow(Error);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -41,7 +41,7 @@ describe('A SimpleBodyparser', (): void => {
|
||||
it('returns a stream of quads if there was data.', async(): Promise<void> => {
|
||||
const input = streamifyArray([ '<http://test.com/s> <http://test.com/p> <http://test.com/o>.' ]) as HttpRequest;
|
||||
input.headers = { 'content-type': 'text/turtle' };
|
||||
const result = await bodyParser.handle(input);
|
||||
const result = (await bodyParser.handle(input))!;
|
||||
expect(result).toEqual({
|
||||
data: expect.any(Readable),
|
||||
dataType: 'quad',
|
||||
@@ -61,7 +61,7 @@ describe('A SimpleBodyparser', (): void => {
|
||||
it('throws an UnsupportedHttpError on invalid triple data when reading the stream.', async(): Promise<void> => {
|
||||
const input = streamifyArray([ '<http://test.com/s> <http://test.com/p> <http://test.com/o>' ]) as HttpRequest;
|
||||
input.headers = { 'content-type': 'text/turtle' };
|
||||
const result = await bodyParser.handle(input);
|
||||
const result = (await bodyParser.handle(input))!;
|
||||
await expect(arrayifyStream(result.data)).rejects.toThrow(UnsupportedHttpError);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -29,6 +29,10 @@ describe('A SimpleRequestParser', (): void => {
|
||||
await expect(requestParser.canHandle({ url: 'url' } as any)).rejects.toThrow('Missing method.');
|
||||
});
|
||||
|
||||
it('errors if called without method.', async(): Promise<void> => {
|
||||
await expect(requestParser.handle({ url: 'url' } as any)).rejects.toThrow('Missing method.');
|
||||
});
|
||||
|
||||
it('returns the output of all input parsers after calling handle.', async(): Promise<void> => {
|
||||
await expect(requestParser.handle({ url: 'url', method: 'GET' } as any)).resolves.toEqual({
|
||||
method: 'GET',
|
||||
|
||||
@@ -14,20 +14,14 @@ describe('A SimpleResponseWriter', (): void => {
|
||||
response = createResponse({ eventEmitter: EventEmitter });
|
||||
});
|
||||
|
||||
it('can handle input that has at least a description or an error.', async(): Promise<void> => {
|
||||
await expect(writer.canHandle({ response, description: {} as ResponseDescription })).resolves.toBeUndefined();
|
||||
await expect(writer.canHandle({ response, error: {} as Error })).resolves.toBeUndefined();
|
||||
await expect(writer.canHandle({ response })).rejects.toThrow(UnsupportedHttpError);
|
||||
});
|
||||
|
||||
it('requires the description body to be a string or binary stream if present.', async(): Promise<void> => {
|
||||
await expect(writer.canHandle({ response, description: { body: { dataType: 'quad' }} as ResponseDescription })).rejects.toThrow(UnsupportedHttpError);
|
||||
await expect(writer.canHandle({ response, description: { body: { dataType: 'string' }} as ResponseDescription })).resolves.toBeUndefined();
|
||||
await expect(writer.canHandle({ response, description: { body: { dataType: 'binary' }} as ResponseDescription })).resolves.toBeUndefined();
|
||||
await expect(writer.canHandle({ response, result: { body: { dataType: 'quad' }} as ResponseDescription })).rejects.toThrow(UnsupportedHttpError);
|
||||
await expect(writer.canHandle({ response, result: { body: { dataType: 'string' }} as ResponseDescription })).resolves.toBeUndefined();
|
||||
await expect(writer.canHandle({ response, result: { body: { dataType: 'binary' }} as ResponseDescription })).resolves.toBeUndefined();
|
||||
});
|
||||
|
||||
it('responds with status code 200 and a location header if there is a description.', async(): Promise<void> => {
|
||||
await writer.handle({ response, description: { identifier: { path: 'path' }}});
|
||||
await writer.handle({ response, result: { identifier: { path: 'path' }}});
|
||||
expect(response._isEndCalled()).toBeTruthy();
|
||||
expect(response._getStatusCode()).toBe(200);
|
||||
expect(response._getHeaders()).toMatchObject({ location: 'path' });
|
||||
@@ -51,7 +45,7 @@ describe('A SimpleResponseWriter', (): void => {
|
||||
done();
|
||||
});
|
||||
|
||||
await writer.handle({ response, description: { identifier: { path: 'path' }, body }});
|
||||
await writer.handle({ response, result: { identifier: { path: 'path' }, body }});
|
||||
});
|
||||
|
||||
it('responds with a content-type if the metadata has it.', async(done): Promise<void> => {
|
||||
@@ -73,11 +67,11 @@ describe('A SimpleResponseWriter', (): void => {
|
||||
done();
|
||||
});
|
||||
|
||||
await writer.handle({ response, description: { identifier: { path: 'path' }, body }});
|
||||
await writer.handle({ response, result: { identifier: { path: 'path' }, body }});
|
||||
});
|
||||
|
||||
it('responds with 500 if an error if there is an error.', async(): Promise<void> => {
|
||||
await writer.handle({ response, error: new Error('error') });
|
||||
await writer.handle({ response, result: new Error('error') });
|
||||
expect(response._isEndCalled()).toBeTruthy();
|
||||
expect(response._getStatusCode()).toBe(500);
|
||||
expect(response._getData()).toMatch('Error: error');
|
||||
@@ -85,7 +79,7 @@ describe('A SimpleResponseWriter', (): void => {
|
||||
|
||||
it('responds with the given statuscode if there is an HttpError.', async(): Promise<void> => {
|
||||
const error = new UnsupportedHttpError('error');
|
||||
await writer.handle({ response, error });
|
||||
await writer.handle({ response, result: error });
|
||||
expect(response._isEndCalled()).toBeTruthy();
|
||||
expect(response._getStatusCode()).toBe(error.statusCode);
|
||||
expect(response._getData()).toMatch('UnsupportedHttpError: error');
|
||||
|
||||
@@ -16,6 +16,10 @@ describe('A SimplePostOperationHandler', (): void => {
|
||||
await expect(handler.canHandle({ method: 'POST' } as Operation)).rejects.toThrow(UnsupportedHttpError);
|
||||
});
|
||||
|
||||
it('errors if no body is present.', async(): Promise<void> => {
|
||||
await expect(handler.handle({ method: 'POST' } as Operation)).rejects.toThrow(UnsupportedHttpError);
|
||||
});
|
||||
|
||||
it('adds the given representation to the store and returns the new identifier.', async(): Promise<void> => {
|
||||
await expect(handler.handle({ method: 'POST', body: { dataType: 'test' }} as Operation)).resolves.toEqual({ identifier: { path: 'newPath' }});
|
||||
});
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import { Lock } from '../../../src/storage/Lock';
|
||||
import { LockingResourceStore } from '../../../src/storage/LockingResourceStore';
|
||||
import { Patch } from '../../../src/ldp/http/Patch';
|
||||
import { Representation } from '../../../src/ldp/representation/Representation';
|
||||
import { ResourceLocker } from '../../../src/storage/ResourceLocker';
|
||||
import { ResourceStore } from '../../../src/storage/ResourceStore';
|
||||
|
||||
@@ -40,7 +42,7 @@ describe('A LockingResourceStore', (): void => {
|
||||
});
|
||||
|
||||
it('acquires a lock on the resource when getting it.', async(): Promise<void> => {
|
||||
await store.getRepresentation({ path: 'path' }, null);
|
||||
await store.getRepresentation({ path: 'path' }, {});
|
||||
expect(locker.acquire).toHaveBeenCalledTimes(1);
|
||||
expect(locker.acquire).toHaveBeenLastCalledWith({ path: 'path' });
|
||||
expect(source.getRepresentation).toHaveBeenCalledTimes(1);
|
||||
@@ -49,7 +51,7 @@ describe('A LockingResourceStore', (): void => {
|
||||
});
|
||||
|
||||
it('acquires a lock on the container when adding a representation.', async(): Promise<void> => {
|
||||
await store.addResource({ path: 'path' }, null);
|
||||
await store.addResource({ path: 'path' }, {} as Representation);
|
||||
expect(locker.acquire).toHaveBeenCalledTimes(1);
|
||||
expect(locker.acquire).toHaveBeenLastCalledWith({ path: 'path' });
|
||||
expect(source.addResource).toHaveBeenCalledTimes(1);
|
||||
@@ -58,7 +60,7 @@ describe('A LockingResourceStore', (): void => {
|
||||
});
|
||||
|
||||
it('acquires a lock on the resource when setting its representation.', async(): Promise<void> => {
|
||||
await store.setRepresentation({ path: 'path' }, null);
|
||||
await store.setRepresentation({ path: 'path' }, {} as Representation);
|
||||
expect(locker.acquire).toHaveBeenCalledTimes(1);
|
||||
expect(locker.acquire).toHaveBeenLastCalledWith({ path: 'path' });
|
||||
expect(source.setRepresentation).toHaveBeenCalledTimes(1);
|
||||
@@ -76,7 +78,7 @@ describe('A LockingResourceStore', (): void => {
|
||||
});
|
||||
|
||||
it('acquires a lock on the resource when modifying its representation.', async(): Promise<void> => {
|
||||
await store.modifyResource({ path: 'path' }, null);
|
||||
await store.modifyResource({ path: 'path' }, {} as Patch);
|
||||
expect(locker.acquire).toHaveBeenCalledTimes(1);
|
||||
expect(locker.acquire).toHaveBeenLastCalledWith({ path: 'path' });
|
||||
expect(source.modifyResource).toHaveBeenCalledTimes(1);
|
||||
@@ -88,7 +90,7 @@ describe('A LockingResourceStore', (): void => {
|
||||
source.getRepresentation = async(): Promise<any> => {
|
||||
throw new Error('dummy');
|
||||
};
|
||||
await expect(store.getRepresentation({ path: 'path' }, null)).rejects.toThrow('dummy');
|
||||
await expect(store.getRepresentation({ path: 'path' }, {})).rejects.toThrow('dummy');
|
||||
expect(locker.acquire).toHaveBeenCalledTimes(1);
|
||||
expect(locker.acquire).toHaveBeenLastCalledWith({ path: 'path' });
|
||||
expect(lock.release).toHaveBeenCalledTimes(1);
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import { Patch } from '../../../src/ldp/http/Patch';
|
||||
import { PatchHandler } from '../../../src/storage/patch/PatchHandler';
|
||||
import { PatchingStore } from '../../../src/storage/PatchingStore';
|
||||
import { Representation } from '../../../src/ldp/representation/Representation';
|
||||
import { ResourceStore } from '../../../src/storage/ResourceStore';
|
||||
|
||||
describe('A PatchingStore', (): void => {
|
||||
@@ -24,44 +26,44 @@ describe('A PatchingStore', (): void => {
|
||||
});
|
||||
|
||||
it('calls getRepresentation directly from the source.', async(): Promise<void> => {
|
||||
await expect(store.getRepresentation({ path: 'getPath' }, null)).resolves.toBe('get');
|
||||
await expect(store.getRepresentation({ path: 'getPath' }, {})).resolves.toBe('get');
|
||||
expect(source.getRepresentation).toHaveBeenCalledTimes(1);
|
||||
expect(source.getRepresentation).toHaveBeenLastCalledWith({ path: 'getPath' }, null, undefined);
|
||||
expect(source.getRepresentation).toHaveBeenLastCalledWith({ path: 'getPath' }, {}, undefined);
|
||||
});
|
||||
|
||||
it('calls addResource directly from the source.', async(): Promise<void> => {
|
||||
await expect(store.addResource({ path: 'addPath' }, null)).resolves.toBe('add');
|
||||
await expect(store.addResource({ path: 'addPath' }, {} as Representation)).resolves.toBe('add');
|
||||
expect(source.addResource).toHaveBeenCalledTimes(1);
|
||||
expect(source.addResource).toHaveBeenLastCalledWith({ path: 'addPath' }, null, undefined);
|
||||
expect(source.addResource).toHaveBeenLastCalledWith({ path: 'addPath' }, {}, undefined);
|
||||
});
|
||||
|
||||
it('calls setRepresentation directly from the source.', async(): Promise<void> => {
|
||||
await expect(store.setRepresentation({ path: 'setPath' }, null)).resolves.toBe('set');
|
||||
await expect(store.setRepresentation({ path: 'setPath' }, {} as Representation)).resolves.toBe('set');
|
||||
expect(source.setRepresentation).toHaveBeenCalledTimes(1);
|
||||
expect(source.setRepresentation).toHaveBeenLastCalledWith({ path: 'setPath' }, null, undefined);
|
||||
expect(source.setRepresentation).toHaveBeenLastCalledWith({ path: 'setPath' }, {}, undefined);
|
||||
});
|
||||
|
||||
it('calls deleteResource directly from the source.', async(): Promise<void> => {
|
||||
await expect(store.deleteResource({ path: 'deletePath' }, null)).resolves.toBe('delete');
|
||||
await expect(store.deleteResource({ path: 'deletePath' })).resolves.toBe('delete');
|
||||
expect(source.deleteResource).toHaveBeenCalledTimes(1);
|
||||
expect(source.deleteResource).toHaveBeenLastCalledWith({ path: 'deletePath' }, null);
|
||||
expect(source.deleteResource).toHaveBeenLastCalledWith({ path: 'deletePath' }, undefined);
|
||||
});
|
||||
|
||||
it('calls modifyResource directly from the source if available.', async(): Promise<void> => {
|
||||
await expect(store.modifyResource({ path: 'modifyPath' }, null)).resolves.toBe('modify');
|
||||
await expect(store.modifyResource({ path: 'modifyPath' }, {} as Patch)).resolves.toBe('modify');
|
||||
expect(source.modifyResource).toHaveBeenCalledTimes(1);
|
||||
expect(source.modifyResource).toHaveBeenLastCalledWith({ path: 'modifyPath' }, null, undefined);
|
||||
expect(source.modifyResource).toHaveBeenLastCalledWith({ path: 'modifyPath' }, {}, undefined);
|
||||
});
|
||||
|
||||
it('calls its patcher if modifyResource failed.', async(): Promise<void> => {
|
||||
source.modifyResource = jest.fn(async(): Promise<any> => {
|
||||
throw new Error('dummy');
|
||||
});
|
||||
await expect(store.modifyResource({ path: 'modifyPath' }, null)).resolves.toBe('patcher');
|
||||
await expect(store.modifyResource({ path: 'modifyPath' }, {} as Patch)).resolves.toBe('patcher');
|
||||
expect(source.modifyResource).toHaveBeenCalledTimes(1);
|
||||
expect(source.modifyResource).toHaveBeenLastCalledWith({ path: 'modifyPath' }, null, undefined);
|
||||
expect(source.modifyResource).toHaveBeenLastCalledWith({ path: 'modifyPath' }, {}, undefined);
|
||||
await expect((source.modifyResource as jest.Mock).mock.results[0].value).rejects.toThrow('dummy');
|
||||
expect(handleSafeFn).toHaveBeenCalledTimes(1);
|
||||
expect(handleSafeFn).toHaveBeenLastCalledWith({ identifier: { path: 'modifyPath' }, patch: null });
|
||||
expect(handleSafeFn).toHaveBeenLastCalledWith({ identifier: { path: 'modifyPath' }, patch: {}});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -2,6 +2,7 @@ import arrayifyStream from 'arrayify-stream';
|
||||
import { NotFoundHttpError } from '../../../src/util/errors/NotFoundHttpError';
|
||||
import { QuadRepresentation } from '../../../src/ldp/representation/QuadRepresentation';
|
||||
import { Readable } from 'stream';
|
||||
import { RepresentationMetadata } from '../../../src/ldp/representation/RepresentationMetadata';
|
||||
import { SimpleResourceStore } from '../../../src/storage/SimpleResourceStore';
|
||||
import streamifyArray from 'streamify-array';
|
||||
import { UnsupportedMediaTypeHttpError } from '../../../src/util/errors/UnsupportedMediaTypeHttpError';
|
||||
@@ -24,15 +25,15 @@ describe('A SimpleResourceStore', (): void => {
|
||||
representation = {
|
||||
data: streamifyArray([ quad ]),
|
||||
dataType: 'quad',
|
||||
metadata: null,
|
||||
metadata: {} as RepresentationMetadata,
|
||||
};
|
||||
});
|
||||
|
||||
it('errors if a resource was not found.', async(): Promise<void> => {
|
||||
await expect(store.getRepresentation({ path: `${base}wrong` }, {})).rejects.toThrow(NotFoundHttpError);
|
||||
await expect(store.addResource({ path: 'http://wrong.com/wrong' }, null)).rejects.toThrow(NotFoundHttpError);
|
||||
await expect(store.addResource({ path: 'http://wrong.com/wrong' }, representation)).rejects.toThrow(NotFoundHttpError);
|
||||
await expect(store.deleteResource({ path: 'wrong' })).rejects.toThrow(NotFoundHttpError);
|
||||
await expect(store.setRepresentation({ path: 'http://wrong.com/' }, null)).rejects.toThrow(NotFoundHttpError);
|
||||
await expect(store.setRepresentation({ path: 'http://wrong.com/' }, representation)).rejects.toThrow(NotFoundHttpError);
|
||||
});
|
||||
|
||||
it('errors when modifying resources.', async(): Promise<void> => {
|
||||
|
||||
@@ -41,15 +41,13 @@ describe('A SimpleSparqlUpdatePatchHandler', (): void => {
|
||||
metadata: null,
|
||||
};
|
||||
}),
|
||||
addResource: null,
|
||||
setRepresentation: jest.fn(async(): Promise<any> => {
|
||||
order.push('setRepresentation');
|
||||
}),
|
||||
deleteResource: null,
|
||||
modifyResource: jest.fn(async(): Promise<any> => {
|
||||
throw new Error('noModify');
|
||||
}),
|
||||
};
|
||||
} as unknown as ResourceStore;
|
||||
|
||||
release = jest.fn(async(): Promise<any> => order.push('release'));
|
||||
locker = {
|
||||
|
||||
Reference in New Issue
Block a user