From aaba113563efbe6eb2d302f21394c379b37ae03f Mon Sep 17 00:00:00 2001 From: Joachim Van Herwegen Date: Fri, 24 Jul 2020 14:59:41 +0200 Subject: [PATCH] fix: Set max-len to 120 --- .eslintrc.js | 1 + src/ldp/http/AcceptPreferenceParser.ts | 10 +++-- src/ldp/http/ResponseWriter.ts | 3 +- src/storage/LockingResourceStore.ts | 21 +++++++---- src/storage/PatchingStore.ts | 9 +++-- src/storage/SimpleResourceStore.ts | 3 +- .../patch/SimpleSparqlUpdatePatchHandler.ts | 6 ++- src/util/AcceptParser.ts | 37 ++++++++++++++----- src/util/CompositeAsyncHandler.ts | 3 +- .../AuthenticatedLdpHandler.test.ts | 3 +- test/unit/ldp/AuthenticatedLdpHandler.test.ts | 4 +- .../ldp/http/AcceptPreferenceParser.test.ts | 21 +++++++---- .../ldp/http/SimpleResponseWriter.test.ts | 9 +++-- .../http/SimpleSparqlUpdateBodyParser.test.ts | 9 +++-- .../ldp/http/SimpleTargetExtractor.test.ts | 5 ++- .../SimpleDeleteOperationHandler.test.ts | 3 +- .../SimplePostOperationHandler.test.ts | 9 +++-- test/unit/server/ExpressHttpServer.test.ts | 3 +- .../unit/storage/LockingResourceStore.test.ts | 15 +++++--- test/unit/storage/SimpleResourceStore.test.ts | 6 ++- .../SimpleSparqlUpdatePatchHandler.test.ts | 33 ++++++++++++----- test/unit/util/AcceptParser.test.ts | 8 +++- test/unit/util/CompositeAsyncHandler.test.ts | 2 +- 23 files changed, 152 insertions(+), 71 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 089e6a3ca..266a6a163 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -19,6 +19,7 @@ module.exports = { 'comma-dangle': ['error', 'always-multiline'], 'dot-location': ['error', 'property'], 'lines-between-class-members': ['error', 'always', { exceptAfterSingleLine: true }], + 'max-len': ['error', { code: 120, ignoreUrls: true }], 'no-underscore-dangle': 'off', // conflicts with external libraries 'padding-line-between-statements': 'off', 'tsdoc/syntax': 'error', diff --git a/src/ldp/http/AcceptPreferenceParser.ts b/src/ldp/http/AcceptPreferenceParser.ts index 09912818d..12a04ed97 100644 --- a/src/ldp/http/AcceptPreferenceParser.ts +++ b/src/ldp/http/AcceptPreferenceParser.ts @@ -25,14 +25,15 @@ export class AcceptPreferenceParser extends PreferenceParser { public async handle(input: HttpRequest): Promise { const result: RepresentationPreferences = {}; - const headers: { [T in keyof RepresentationPreferences]: { val?: string; func: (input: string) => AcceptHeader[] }} = { + const headers: + { [T in keyof RepresentationPreferences]: { val?: string; func: (input: string) => AcceptHeader[] }} = { type: { val: input.headers.accept, func: parseAccept }, charset: { val: input.headers['accept-charset'] as string, func: parseAcceptCharset }, encoding: { val: input.headers['accept-encoding'] as string, func: parseAcceptEncoding }, language: { val: input.headers['accept-language'], func: parseAcceptLanguage }, }; (Object.keys(headers) as (keyof RepresentationPreferences)[]).forEach((key): void => { - const preferences = this.parseHeader(headers[key]!.val, headers[key]!.func); + const preferences = this.parseHeader(headers[key]!.func, headers[key]!.val); if (preferences.length > 0) { result[key] = preferences; } @@ -53,10 +54,11 @@ export class AcceptPreferenceParser extends PreferenceParser { * * @returns A list of {@link RepresentationPreference}. Returns an empty list if input was not defined. */ - private parseHeader(input: string | undefined, parseFunction: (input: string) => AcceptHeader[]): RepresentationPreference[] { + private parseHeader(parseFunction: (input: string) => AcceptHeader[], input?: string): RepresentationPreference[] { if (!input) { return []; } - return parseFunction(input).map((accept): RepresentationPreference => ({ value: accept.range, weight: accept.weight })); + return parseFunction(input).map((accept): RepresentationPreference => + ({ value: accept.range, weight: accept.weight })); } } diff --git a/src/ldp/http/ResponseWriter.ts b/src/ldp/http/ResponseWriter.ts index 9dcee6c51..52b4db3ad 100644 --- a/src/ldp/http/ResponseWriter.ts +++ b/src/ldp/http/ResponseWriter.ts @@ -6,4 +6,5 @@ import { ResponseDescription } from '../operations/ResponseDescription'; * Writes to the HttpResponse. * Response depends on the operation result and potentially which errors was thrown. */ -export abstract class ResponseWriter extends AsyncHandler<{ response: HttpResponse; result: ResponseDescription | Error }> {} +export abstract class ResponseWriter + extends AsyncHandler<{ response: HttpResponse; result: ResponseDescription | Error }> {} diff --git a/src/storage/LockingResourceStore.ts b/src/storage/LockingResourceStore.ts index 8361d6f66..a84383358 100644 --- a/src/storage/LockingResourceStore.ts +++ b/src/storage/LockingResourceStore.ts @@ -20,24 +20,31 @@ export class LockingResourceStore implements AtomicResourceStore { this.locks = locks; } - public async addResource(container: ResourceIdentifier, representation: Representation, conditions?: Conditions): Promise { - return this.lockedRun(container, async(): Promise => this.source.addResource(container, representation, conditions)); + public async addResource(container: ResourceIdentifier, representation: Representation, + conditions?: Conditions): Promise { + return this.lockedRun(container, + async(): Promise => this.source.addResource(container, representation, conditions)); } public async deleteResource(identifier: ResourceIdentifier, conditions?: Conditions): Promise { return this.lockedRun(identifier, async(): Promise => this.source.deleteResource(identifier, conditions)); } - public async getRepresentation(identifier: ResourceIdentifier, preferences: RepresentationPreferences, conditions?: Conditions): Promise { - return this.lockedRun(identifier, async(): Promise => this.source.getRepresentation(identifier, preferences, conditions)); + public async getRepresentation(identifier: ResourceIdentifier, preferences: RepresentationPreferences, + conditions?: Conditions): Promise { + return this.lockedRun(identifier, + async(): Promise => this.source.getRepresentation(identifier, preferences, conditions)); } public async modifyResource(identifier: ResourceIdentifier, patch: Patch, conditions?: Conditions): Promise { - return this.lockedRun(identifier, async(): Promise => this.source.modifyResource(identifier, patch, conditions)); + return this.lockedRun(identifier, + async(): Promise => this.source.modifyResource(identifier, patch, conditions)); } - public async setRepresentation(identifier: ResourceIdentifier, representation: Representation, conditions?: Conditions): Promise { - return this.lockedRun(identifier, async(): Promise => this.source.setRepresentation(identifier, representation, conditions)); + public async setRepresentation(identifier: ResourceIdentifier, representation: Representation, + conditions?: Conditions): Promise { + return this.lockedRun(identifier, + async(): Promise => this.source.setRepresentation(identifier, representation, conditions)); } private async lockedRun(identifier: ResourceIdentifier, func: () => Promise): Promise { diff --git a/src/storage/PatchingStore.ts b/src/storage/PatchingStore.ts index ee03e3725..5767ff66c 100644 --- a/src/storage/PatchingStore.ts +++ b/src/storage/PatchingStore.ts @@ -20,7 +20,8 @@ export class PatchingStore implements ResourceStore { this.patcher = patcher; } - public async addResource(container: ResourceIdentifier, representation: Representation, conditions?: Conditions): Promise { + public async addResource(container: ResourceIdentifier, representation: Representation, + conditions?: Conditions): Promise { return this.source.addResource(container, representation, conditions); } @@ -28,11 +29,13 @@ export class PatchingStore implements ResourceStore { return this.source.deleteResource(identifier, conditions); } - public async getRepresentation(identifier: ResourceIdentifier, preferences: RepresentationPreferences, conditions?: Conditions): Promise { + public async getRepresentation(identifier: ResourceIdentifier, preferences: RepresentationPreferences, + conditions?: Conditions): Promise { return this.source.getRepresentation(identifier, preferences, conditions); } - public async setRepresentation(identifier: ResourceIdentifier, representation: Representation, conditions?: Conditions): Promise { + public async setRepresentation(identifier: ResourceIdentifier, representation: Representation, + conditions?: Conditions): Promise { return this.source.setRepresentation(identifier, representation, conditions); } diff --git a/src/storage/SimpleResourceStore.ts b/src/storage/SimpleResourceStore.ts index a57ad95f7..a4c0d1c83 100644 --- a/src/storage/SimpleResourceStore.ts +++ b/src/storage/SimpleResourceStore.ts @@ -64,7 +64,8 @@ export class SimpleResourceStore implements ResourceStore { * * @returns The corresponding Representation. */ - public async getRepresentation(identifier: ResourceIdentifier, preferences: RepresentationPreferences): Promise { + public async getRepresentation(identifier: ResourceIdentifier, + preferences: RepresentationPreferences): Promise { const path = this.parseIdentifier(identifier); return this.generateRepresentation(this.store[path], preferences); } diff --git a/src/storage/patch/SimpleSparqlUpdatePatchHandler.ts b/src/storage/patch/SimpleSparqlUpdatePatchHandler.ts index e65934b30..22e88937c 100644 --- a/src/storage/patch/SimpleSparqlUpdatePatchHandler.ts +++ b/src/storage/patch/SimpleSparqlUpdatePatchHandler.ts @@ -48,12 +48,14 @@ export class SimpleSparqlUpdatePatchHandler extends PatchHandler { if (!inserts.every((pattern): boolean => pattern.graph.equals(def))) { throw new UnsupportedHttpError('GRAPH statements are not supported.'); } - if (op.where ?? deletes.some((pattern): boolean => someTerms(pattern, (term): boolean => term.termType === 'Variable'))) { + if (op.where ?? deletes.some((pattern): boolean => + someTerms(pattern, (term): boolean => term.termType === 'Variable'))) { throw new UnsupportedHttpError('WHERE statements are not supported.'); } const lock = await this.locker.acquire(input.identifier); - const quads = await this.source.getRepresentation(input.identifier, { type: [{ value: 'internal/quads', weight: 1 }]}); + const quads = await this.source.getRepresentation(input.identifier, + { type: [{ value: 'internal/quads', weight: 1 }]}); const store = new Store(); const importEmitter = store.import(quads.data); await new Promise((resolve, reject): void => { diff --git a/src/util/AcceptParser.ts b/src/util/AcceptParser.ts index d8e854f2c..b442854b4 100644 --- a/src/util/AcceptParser.ts +++ b/src/util/AcceptParser.ts @@ -38,7 +38,8 @@ import { UnsupportedHttpError } from './errors/UnsupportedHttpError'; // language-range = (1*8ALPHA *("-" 1*8alphanum)) / "*" // alphanum = ALPHA / DIGIT // -// Delimiters are chosen from the set of US-ASCII visual characters not allowed in a token (DQUOTE and "(),/:;<=>?@[\]{}"). +// Delimiters are chosen from the set of US-ASCII visual characters +// not allowed in a token (DQUOTE and "(),/:;<=>?@[\]{}"). // token = 1*tchar // tchar = "!" / "#" / "$" / "%" / "&" / "'" / "*" // / "+" / "-" / "." / "^" / "_" / "`" / "|" / "~" @@ -65,7 +66,10 @@ export interface Accept extends AcceptHeader { parameters: { /** Media type parameters. These are the parameters that came before the q value. */ mediaType: { [key: string]: string }; - /** Extension parameters. These are the parameters that came after the q value. Value will be an empty string if there was none. */ + /** + * Extension parameters. These are the parameters that came after the q value. + * Value will be an empty string if there was none. + */ extension: { [key: string]: string }; }; } @@ -101,7 +105,9 @@ const transformQuotedStrings = (input: string): { result: string; replacements: const result = input.replace(/"(?:[^"\\]|\\.)*"/gu, (match): string => { // Not all characters allowed in quoted strings, see BNF above if (!/^"(?:[\t !\u0023-\u005b\u005d-\u007e\u0080-\u00ff]|(?:\\[\t\u0020-\u007e\u0080-\u00ff]))*"$/u.test(match)) { - throw new UnsupportedHttpError(`Invalid quoted string in Accept header: ${match}. Check which characters are allowed`); + throw new UnsupportedHttpError( + `Invalid quoted string in Accept header: ${match}. Check which characters are allowed`, + ); } const replacement = `"${idx}"`; replacements[replacement] = match; @@ -131,7 +137,9 @@ const splitAndClean = (input: string): string[] => */ const testQValue = (qvalue: string): void => { if (!/^q=(?:(?:0(?:\.\d{0,3})?)|(?:1(?:\.0{0,3})?))$/u.test(qvalue)) { - throw new UnsupportedHttpError(`Invalid q value: ${qvalue} does not match ("q=" ( "0" [ "." 0*3DIGIT ] ) / ( "1" [ "." 0*3("0") ] )).`); + throw new UnsupportedHttpError( + `Invalid q value: ${qvalue} does not match ("q=" ( "0" [ "." 0*3DIGIT ] ) / ( "1" [ "." 0*3("0") ] )).`, + ); } }; @@ -155,7 +163,9 @@ const parseAcceptPart = (part: string, replacements: { [id: string]: string }): // No reason to test differently for * since we don't check if the type exists const [ type, subtype ] = range.split('/'); if (!type || !subtype || !token.test(type) || !token.test(subtype)) { - throw new Error(`Invalid Accept range: ${range} does not match ( "*/*" / ( token "/" "*" ) / ( token "/" token ) )`); + throw new Error( + `Invalid Accept range: ${range} does not match ( "*/*" / ( token "/" "*" ) / ( token "/" token ) )`, + ); } let weight = 1; @@ -174,9 +184,12 @@ const parseAcceptPart = (part: string, replacements: { [id: string]: string }): // Test replaced string for easier check // parameter = token "=" ( token / quoted-string ) // second part is optional for extension parameters - if (!token.test(name) || !((map === extensionParams && !value) || (value && (/^"\d+"$/u.test(value) || token.test(value))))) { - throw new UnsupportedHttpError(`Invalid Accept parameter: ${param} does not match (token "=" ( token / quoted-string )). ` + - 'Second part optional for extension parameters.'); + if (!token.test(name) || + !((map === extensionParams && !value) || (value && (/^"\d+"$/u.test(value) || token.test(value))))) { + throw new UnsupportedHttpError( + `Invalid Accept parameter: ${param} does not match (token "=" ( token / quoted-string )). ` + + `Second part is optional for extension parameters.`, + ); } let actualValue = value; @@ -256,7 +269,9 @@ export const parseAcceptCharset = (input: string): AcceptCharset[] => { const results = parseNoParameters(input); results.forEach((result): void => { if (!token.test(result.range)) { - throw new UnsupportedHttpError(`Invalid Accept-Charset range: ${result.range} does not match (content-coding / "identity" / "*")`); + throw new UnsupportedHttpError( + `Invalid Accept-Charset range: ${result.range} does not match (content-coding / "identity" / "*")`, + ); } }); return results; @@ -297,7 +312,9 @@ export const parseAcceptLanguage = (input: string): AcceptLanguage[] => { results.forEach((result): void => { // (1*8ALPHA *("-" 1*8alphanum)) / "*" if (result.range !== '*' && !/^[a-zA-Z]{1,8}(?:-[a-zA-Z0-9]{1,8})*$/u.test(result.range)) { - throw new UnsupportedHttpError(`Invalid Accept-Language range: ${result.range} does not match ((1*8ALPHA *("-" 1*8alphanum)) / "*")`); + throw new UnsupportedHttpError( + `Invalid Accept-Language range: ${result.range} does not match ((1*8ALPHA *("-" 1*8alphanum)) / "*")`, + ); } }); return results; diff --git a/src/util/CompositeAsyncHandler.ts b/src/util/CompositeAsyncHandler.ts index 91f3fcbb9..f2221b0bd 100644 --- a/src/util/CompositeAsyncHandler.ts +++ b/src/util/CompositeAsyncHandler.ts @@ -46,7 +46,8 @@ export class CompositeAsyncHandler implements AsyncHandler } /** - * Identical to {@link AsyncHandler.handleSafe} but optimized for composite by only needing 1 canHandle call on members. + * Identical to {@link AsyncHandler.handleSafe} but optimized for composite + * by only needing 1 canHandle call on members. * @param input - The input data. * * @returns A promise corresponding to the handle call of a handler that supports the input. diff --git a/test/integration/AuthenticatedLdpHandler.test.ts b/test/integration/AuthenticatedLdpHandler.test.ts index e5a89d530..8d942571c 100644 --- a/test/integration/AuthenticatedLdpHandler.test.ts +++ b/test/integration/AuthenticatedLdpHandler.test.ts @@ -31,7 +31,8 @@ import { createResponse, MockResponse } from 'node-mocks-http'; import { namedNode, quad } from '@rdfjs/data-model'; import * as url from 'url'; -const call = async(handler: HttpHandler, requestUrl: url.URL, method: string, headers: IncomingHttpHeaders, data: string[]): Promise> => { +const call = async(handler: HttpHandler, requestUrl: url.URL, method: string, + headers: IncomingHttpHeaders, data: string[]): Promise> => { const request = streamifyArray(data) as HttpRequest; request.url = requestUrl.pathname; request.method = method; diff --git a/test/unit/ldp/AuthenticatedLdpHandler.test.ts b/test/unit/ldp/AuthenticatedLdpHandler.test.ts index 50ecf1f46..4f2709e30 100644 --- a/test/unit/ldp/AuthenticatedLdpHandler.test.ts +++ b/test/unit/ldp/AuthenticatedLdpHandler.test.ts @@ -39,7 +39,9 @@ describe('An AuthenticatedLdpHandler', (): void => { it('can check if it handles input.', async(): Promise => { const handler = new AuthenticatedLdpHandler(args); - await expect(handler.canHandle({ request: {} as HttpRequest, response: {} as HttpResponse })).resolves.toBeUndefined(); + await expect(handler.canHandle( + { request: {} as HttpRequest, response: {} as HttpResponse }, + )).resolves.toBeUndefined(); }); it('can handle input.', async(): Promise => { diff --git a/test/unit/ldp/http/AcceptPreferenceParser.test.ts b/test/unit/ldp/http/AcceptPreferenceParser.test.ts index 5189c662f..b3362751d 100644 --- a/test/unit/ldp/http/AcceptPreferenceParser.test.ts +++ b/test/unit/ldp/http/AcceptPreferenceParser.test.ts @@ -18,22 +18,29 @@ describe('An AcceptPreferenceParser', (): void => { }); it('parses accept-charset headers.', async(): Promise => { - await expect(preferenceParser.handle({ headers: { 'accept-charset': 'iso-8859-5, unicode-1-1;q=0.8' }} as unknown as HttpRequest)) - .resolves.toEqual({ charset: [{ value: 'iso-8859-5', weight: 1 }, { value: 'unicode-1-1', weight: 0.8 }]}); + await expect(preferenceParser.handle( + { headers: { 'accept-charset': 'iso-8859-5, unicode-1-1;q=0.8' }} as unknown as HttpRequest, + )).resolves.toEqual({ charset: [{ value: 'iso-8859-5', weight: 1 }, { value: 'unicode-1-1', weight: 0.8 }]}); }); it('parses accept-datetime headers.', async(): Promise => { - await expect(preferenceParser.handle({ headers: { 'accept-datetime': 'Tue, 20 Mar 2001 20:35:00 GMT' }} as unknown as HttpRequest)) - .resolves.toEqual({ datetime: [{ value: 'Tue, 20 Mar 2001 20:35:00 GMT', weight: 1 }]}); + await expect(preferenceParser.handle( + { headers: { 'accept-datetime': 'Tue, 20 Mar 2001 20:35:00 GMT' }} as unknown as HttpRequest, + )).resolves.toEqual({ datetime: [{ value: 'Tue, 20 Mar 2001 20:35:00 GMT', weight: 1 }]}); }); it('parses accept-encoding headers.', async(): Promise => { - await expect(preferenceParser.handle({ headers: { 'accept-encoding': 'gzip;q=1.0, identity; q=0.5, *;q=0' }} as unknown as HttpRequest)) - .resolves.toEqual({ encoding: [{ value: 'gzip', weight: 1 }, { value: 'identity', weight: 0.5 }, { value: '*', weight: 0 }]}); + await expect(preferenceParser.handle( + { headers: { 'accept-encoding': 'gzip;q=1.0, identity; q=0.5, *;q=0' }} as unknown as HttpRequest, + )).resolves.toEqual( + { encoding: [{ value: 'gzip', weight: 1 }, { value: 'identity', weight: 0.5 }, { value: '*', weight: 0 }]}, + ); }); it('parses accept-language headers.', async(): Promise => { await expect(preferenceParser.handle({ headers: { 'accept-language': 'da, en-gb;q=0.8, en;q=0.7' }} as HttpRequest)) - .resolves.toEqual({ language: [{ value: 'da', weight: 1 }, { value: 'en-gb', weight: 0.8 }, { value: 'en', weight: 0.7 }]}); + .resolves.toEqual( + { language: [{ value: 'da', weight: 1 }, { value: 'en-gb', weight: 0.8 }, { value: 'en', weight: 0.7 }]}, + ); }); }); diff --git a/test/unit/ldp/http/SimpleResponseWriter.test.ts b/test/unit/ldp/http/SimpleResponseWriter.test.ts index 75d4de496..15e0263be 100644 --- a/test/unit/ldp/http/SimpleResponseWriter.test.ts +++ b/test/unit/ldp/http/SimpleResponseWriter.test.ts @@ -15,9 +15,12 @@ describe('A SimpleResponseWriter', (): void => { }); it('requires the description body to be a string or binary stream if present.', async(): Promise => { - 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(); + 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 => { diff --git a/test/unit/ldp/http/SimpleSparqlUpdateBodyParser.test.ts b/test/unit/ldp/http/SimpleSparqlUpdateBodyParser.test.ts index 267de1410..e12375998 100644 --- a/test/unit/ldp/http/SimpleSparqlUpdateBodyParser.test.ts +++ b/test/unit/ldp/http/SimpleSparqlUpdateBodyParser.test.ts @@ -11,12 +11,15 @@ describe('A SimpleSparqlUpdateBodyParser', (): void => { it('only accepts application/sparql-update content.', async(): Promise => { await expect(bodyParser.canHandle({ headers: {}} as HttpRequest)).rejects.toThrow(UnsupportedMediaTypeHttpError); - await expect(bodyParser.canHandle({ headers: { 'content-type': 'text/plain' }} as HttpRequest)).rejects.toThrow(UnsupportedMediaTypeHttpError); - await expect(bodyParser.canHandle({ headers: { 'content-type': 'application/sparql-update' }} as HttpRequest)).resolves.toBeUndefined(); + await expect(bodyParser.canHandle({ headers: { 'content-type': 'text/plain' }} as HttpRequest)) + .rejects.toThrow(UnsupportedMediaTypeHttpError); + await expect(bodyParser.canHandle({ headers: { 'content-type': 'application/sparql-update' }} as HttpRequest)) + .resolves.toBeUndefined(); }); it('errors when handling invalid SPARQL updates.', async(): Promise => { - await expect(bodyParser.handle(streamifyArray([ 'VERY INVALID UPDATE' ]) as HttpRequest)).rejects.toThrow(UnsupportedHttpError); + await expect(bodyParser.handle(streamifyArray([ 'VERY INVALID UPDATE' ]) as HttpRequest)) + .rejects.toThrow(UnsupportedHttpError); }); it('converts SPARQL updates to algebra.', async(): Promise => { diff --git a/test/unit/ldp/http/SimpleTargetExtractor.test.ts b/test/unit/ldp/http/SimpleTargetExtractor.test.ts index 112db596e..c74d7ff6b 100644 --- a/test/unit/ldp/http/SimpleTargetExtractor.test.ts +++ b/test/unit/ldp/http/SimpleTargetExtractor.test.ts @@ -16,7 +16,8 @@ describe('A SimpleTargetExtractor', (): void => { }); it('uses https protocol if the connection is secure.', async(): Promise => { - await expect(extractor.handle({ url: 'url', headers: { host: 'test.com' }, connection: { encrypted: true } as any } as any)) - .resolves.toEqual({ path: 'https://test.com/url' }); + await expect(extractor.handle( + { url: 'url', headers: { host: 'test.com' }, connection: { encrypted: true } as any } as any, + )).resolves.toEqual({ path: 'https://test.com/url' }); }); }); diff --git a/test/unit/ldp/operations/SimpleDeleteOperationHandler.test.ts b/test/unit/ldp/operations/SimpleDeleteOperationHandler.test.ts index 9d9ebe7b2..8c359289e 100644 --- a/test/unit/ldp/operations/SimpleDeleteOperationHandler.test.ts +++ b/test/unit/ldp/operations/SimpleDeleteOperationHandler.test.ts @@ -17,7 +17,8 @@ describe('A SimpleDeleteOperationHandler', (): void => { }); it('deletes the resource from the store and returns its identifier.', async(): Promise => { - await expect(handler.handle({ target: { path: 'url' }} as Operation)).resolves.toEqual({ identifier: { path: 'url' }}); + await expect(handler.handle({ target: { path: 'url' }} as Operation)) + .resolves.toEqual({ identifier: { path: 'url' }}); expect(store.deleteResource).toHaveBeenCalledTimes(1); expect(store.deleteResource).toHaveBeenLastCalledWith({ path: 'url' }); }); diff --git a/test/unit/ldp/operations/SimplePostOperationHandler.test.ts b/test/unit/ldp/operations/SimplePostOperationHandler.test.ts index b6a6ececb..491d9c20b 100644 --- a/test/unit/ldp/operations/SimplePostOperationHandler.test.ts +++ b/test/unit/ldp/operations/SimplePostOperationHandler.test.ts @@ -11,8 +11,10 @@ describe('A SimplePostOperationHandler', (): void => { const handler = new SimplePostOperationHandler(store); it('only supports POST operations with a body.', async(): Promise => { - await expect(handler.canHandle({ method: 'POST', body: { dataType: 'test' }} as Operation)).resolves.toBeUndefined(); - await expect(handler.canHandle({ method: 'GET', body: { dataType: 'test' }} as Operation)).rejects.toThrow(UnsupportedHttpError); + await expect(handler.canHandle({ method: 'POST', body: { dataType: 'test' }} as Operation)) + .resolves.toBeUndefined(); + await expect(handler.canHandle({ method: 'GET', body: { dataType: 'test' }} as Operation)) + .rejects.toThrow(UnsupportedHttpError); await expect(handler.canHandle({ method: 'POST' } as Operation)).rejects.toThrow(UnsupportedHttpError); }); @@ -21,6 +23,7 @@ describe('A SimplePostOperationHandler', (): void => { }); it('adds the given representation to the store and returns the new identifier.', async(): Promise => { - await expect(handler.handle({ method: 'POST', body: { dataType: 'test' }} as Operation)).resolves.toEqual({ identifier: { path: 'newPath' }}); + await expect(handler.handle({ method: 'POST', body: { dataType: 'test' }} as Operation)) + .resolves.toEqual({ identifier: { path: 'newPath' }}); }); }); diff --git a/test/unit/server/ExpressHttpServer.test.ts b/test/unit/server/ExpressHttpServer.test.ts index 1c8cdcdef..3dbfda19b 100644 --- a/test/unit/server/ExpressHttpServer.test.ts +++ b/test/unit/server/ExpressHttpServer.test.ts @@ -53,7 +53,8 @@ describe('ExpressHttpServer', (): void => { 'access-control-allow-origin': '*', 'access-control-allow-headers': 'content-type', })); - const corsMethods = res.header['access-control-allow-methods'].split(',').map((method: string): string => method.trim()); + const corsMethods = res.header['access-control-allow-methods'].split(',') + .map((method: string): string => method.trim()); const allowedMethods = [ 'GET', 'HEAD', 'OPTIONS', 'POST', 'PUT', 'PATCH', 'DELETE' ]; expect(corsMethods).toEqual(expect.arrayContaining(allowedMethods)); expect(corsMethods.length).toBe(allowedMethods.length); diff --git a/test/unit/storage/LockingResourceStore.test.ts b/test/unit/storage/LockingResourceStore.test.ts index f3567bdb2..910a5191f 100644 --- a/test/unit/storage/LockingResourceStore.test.ts +++ b/test/unit/storage/LockingResourceStore.test.ts @@ -24,11 +24,16 @@ describe('A LockingResourceStore', (): void => { }; source = { - getRepresentation: jest.fn(async(): Promise => new Promise((resolve): any => delayedResolve(resolve, 'getRepresentation'))), - addResource: jest.fn(async(): Promise => new Promise((resolve): any => delayedResolve(resolve, 'addResource'))), - setRepresentation: jest.fn(async(): Promise => new Promise((resolve): any => delayedResolve(resolve, 'setRepresentation'))), - deleteResource: jest.fn(async(): Promise => new Promise((resolve): any => delayedResolve(resolve, 'deleteResource'))), - modifyResource: jest.fn(async(): Promise => new Promise((resolve): any => delayedResolve(resolve, 'modifyResource'))), + getRepresentation: jest.fn(async(): Promise => + new Promise((resolve): any => delayedResolve(resolve, 'getRepresentation'))), + addResource: jest.fn(async(): Promise => + new Promise((resolve): any => delayedResolve(resolve, 'addResource'))), + setRepresentation: jest.fn(async(): Promise => + new Promise((resolve): any => delayedResolve(resolve, 'setRepresentation'))), + deleteResource: jest.fn(async(): Promise => + new Promise((resolve): any => delayedResolve(resolve, 'deleteResource'))), + modifyResource: jest.fn(async(): Promise => + new Promise((resolve): any => delayedResolve(resolve, 'modifyResource'))), }; release = jest.fn(async(): Promise => order.push('release')); locker = { diff --git a/test/unit/storage/SimpleResourceStore.test.ts b/test/unit/storage/SimpleResourceStore.test.ts index feaeb0645..0b8f85e70 100644 --- a/test/unit/storage/SimpleResourceStore.test.ts +++ b/test/unit/storage/SimpleResourceStore.test.ts @@ -31,9 +31,11 @@ describe('A SimpleResourceStore', (): void => { it('errors if a resource was not found.', async(): Promise => { await expect(store.getRepresentation({ path: `${base}wrong` }, {})).rejects.toThrow(NotFoundHttpError); - await expect(store.addResource({ path: 'http://wrong.com/wrong' }, representation)).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/' }, representation)).rejects.toThrow(NotFoundHttpError); + await expect(store.setRepresentation({ path: 'http://wrong.com/' }, representation)) + .rejects.toThrow(NotFoundHttpError); }); it('errors when modifying resources.', async(): Promise => { diff --git a/test/unit/storage/patch/SimpleSparqlUpdatePatchHandler.test.ts b/test/unit/storage/patch/SimpleSparqlUpdatePatchHandler.test.ts index fc0ddd042..9e82356f5 100644 --- a/test/unit/storage/patch/SimpleSparqlUpdatePatchHandler.test.ts +++ b/test/unit/storage/patch/SimpleSparqlUpdatePatchHandler.test.ts @@ -63,7 +63,9 @@ describe('A SimpleSparqlUpdatePatchHandler', (): void => { const basicChecks = async(quads: Quad[]): Promise => { expect(source.getRepresentation).toHaveBeenCalledTimes(1); - expect(source.getRepresentation).toHaveBeenLastCalledWith({ path: 'path' }, { type: [{ value: 'internal/quads', weight: 1 }]}); + expect(source.getRepresentation).toHaveBeenLastCalledWith( + { path: 'path' }, { type: [{ value: 'internal/quads', weight: 1 }]}, + ); expect(source.setRepresentation).toHaveBeenCalledTimes(1); expect(order).toEqual([ 'acquire', 'getRepresentation', 'setRepresentation', 'release' ]); const setParams = (source.setRepresentation as jest.Mock).mock.calls[0]; @@ -76,7 +78,8 @@ describe('A SimpleSparqlUpdatePatchHandler', (): void => { }; it('only accepts SPARQL updates.', async(): Promise => { - const input = { identifier: { path: 'path' }, patch: { dataType: 'sparql-algebra', algebra: {}} as SparqlUpdatePatch }; + const input = { identifier: { path: 'path' }, + patch: { dataType: 'sparql-algebra', algebra: {}} as SparqlUpdatePatch }; await expect(handler.canHandle(input)).resolves.toBeUndefined(); input.patch.dataType = 'notAlgebra'; await expect(handler.canHandle(input)).rejects.toThrow(UnsupportedHttpError); @@ -102,7 +105,9 @@ describe('A SimpleSparqlUpdatePatchHandler', (): void => { { quads: true }, ) } as SparqlUpdatePatch }); await basicChecks( - [ quad(namedNode('http://test.com/startS2'), namedNode('http://test.com/startP2'), namedNode('http://test.com/startO2')) ], + [ quad(namedNode('http://test.com/startS2'), + namedNode('http://test.com/startP2'), + namedNode('http://test.com/startO2')) ], ); }); @@ -113,7 +118,9 @@ describe('A SimpleSparqlUpdatePatchHandler', (): void => { { quads: true }, ) } as SparqlUpdatePatch }); await basicChecks( - [ quad(namedNode('http://test.com/startS2'), namedNode('http://test.com/startP2'), namedNode('http://test.com/startO2')) ], + [ quad(namedNode('http://test.com/startS2'), + namedNode('http://test.com/startP2'), + namedNode('http://test.com/startO2')) ], ); }); @@ -125,16 +132,21 @@ describe('A SimpleSparqlUpdatePatchHandler', (): void => { 'WHERE {}', { quads: true }, ) } as SparqlUpdatePatch }); - await basicChecks( - [ quad(namedNode('http://test.com/startS2'), namedNode('http://test.com/startP2'), namedNode('http://test.com/startO2')), - quad(namedNode('http://test.com/s1'), namedNode('http://test.com/p1'), namedNode('http://test.com/o1')) ], - ); + await basicChecks([ + quad(namedNode('http://test.com/startS2'), + namedNode('http://test.com/startP2'), + namedNode('http://test.com/startO2')), + quad(namedNode('http://test.com/s1'), + namedNode('http://test.com/p1'), + namedNode('http://test.com/o1')), + ]); }); it('rejects GRAPH inserts.', async(): Promise => { const handle = handler.handle({ identifier: { path: 'path' }, patch: { algebra: translate( - 'INSERT DATA { GRAPH { } }', + 'INSERT DATA { GRAPH { ' + + ' } }', { quads: true }, ) } as SparqlUpdatePatch }); await expect(handle).rejects.toThrow('GRAPH statements are not supported.'); @@ -144,7 +156,8 @@ describe('A SimpleSparqlUpdatePatchHandler', (): void => { it('rejects GRAPH deletes.', async(): Promise => { const handle = handler.handle({ identifier: { path: 'path' }, patch: { algebra: translate( - 'DELETE DATA { GRAPH { } }', + 'DELETE DATA { GRAPH { ' + + ' } }', { quads: true }, ) } as SparqlUpdatePatch }); await expect(handle).rejects.toThrow('GRAPH statements are not supported.'); diff --git a/test/unit/util/AcceptParser.test.ts b/test/unit/util/AcceptParser.test.ts index 25a6c1d67..23a268294 100644 --- a/test/unit/util/AcceptParser.test.ts +++ b/test/unit/util/AcceptParser.test.ts @@ -25,7 +25,9 @@ describe('AcceptParser', (): void => { }); it('parses complex Accept headers.', async(): Promise => { - expect(parseAccept('text/html;q=0.7, text/html;level=1, text/html;level=2;q=0.4,text/x-dvi; q=0.8; mxb=100000; mxt')).toEqual([ + expect(parseAccept( + 'text/html;q=0.7, text/html;level=1, text/html;level=2;q=0.4,text/x-dvi; q=0.8; mxb=100000; mxt', + )).toEqual([ { range: 'text/html', weight: 1, parameters: { mediaType: { level: '1' }, extension: {}}}, { range: 'text/x-dvi', weight: 0.8, parameters: { mediaType: {}, extension: { mxb: '100000', mxt: '' }}}, { range: 'text/html', weight: 0.7, parameters: { mediaType: {}, extension: {}}}, @@ -35,7 +37,9 @@ describe('AcceptParser', (): void => { it('parses Accept headers with double quoted values.', async(): Promise => { expect(parseAccept('audio/basic; param1="val" ; q=0.5 ;param2="\\\\\\"valid"')).toEqual([ - { range: 'audio/basic', weight: 0.5, parameters: { mediaType: { param1: '"val"' }, extension: { param2: '"\\\\\\"valid"' }}}, + { range: 'audio/basic', + weight: 0.5, + parameters: { mediaType: { param1: '"val"' }, extension: { param2: '"\\\\\\"valid"' }}}, ]); }); diff --git a/test/unit/util/CompositeAsyncHandler.test.ts b/test/unit/util/CompositeAsyncHandler.test.ts index e4bc0d280..547fe65e4 100644 --- a/test/unit/util/CompositeAsyncHandler.test.ts +++ b/test/unit/util/CompositeAsyncHandler.test.ts @@ -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 => { + it('throws the canHandle error when calling handleSafe if the data is not supported.', async(): Promise => { const handler = new CompositeAsyncHandler([ handlerFalse, handlerFalse ]); await expect(handler.handleSafe(null)).rejects.toThrow('[Not supported., Not supported.]');