From 5dc8afa6eae4d415a396abfcb2e649aef703c76f Mon Sep 17 00:00:00 2001 From: elf Pavlik Date: Sat, 13 Apr 2024 09:36:03 -0600 Subject: [PATCH] fix linting erros --- .../notifications/streaming-http/http.json | 38 ++-- src/index.ts | 10 +- .../StreamingHttp2023Emitter.ts} | 18 +- .../StreamingHttpListeningActivityHandler.ts} | 20 +- .../StreamingHttpMap.ts} | 6 +- .../StreamingHttpMetadataWriter.ts} | 14 +- .../StreamingHttpRequestHandler.ts} | 50 +++-- ...st.ts => StreamingHttpChannel2023.test.ts} | 182 +++++++++--------- .../StreamingHttp2023Emitter.test.ts} | 38 ++-- ...amingHttpListeningActivityHandler.test.ts} | 15 +- .../StreamingHttpMetadataWriter.test.ts} | 14 +- .../StreamingHttpRequestHandler.test.ts} | 37 ++-- 12 files changed, 224 insertions(+), 218 deletions(-) rename src/server/notifications/{StreamingHTTPChannel2023/StreamingHTTP2023Emitter.ts => StreamingHttpChannel2023/StreamingHttp2023Emitter.ts} (63%) rename src/server/notifications/{StreamingHTTPChannel2023/StreamingHTTPListeningActivityHandler.ts => StreamingHttpChannel2023/StreamingHttpListeningActivityHandler.ts} (76%) rename src/server/notifications/{StreamingHTTPChannel2023/StreamingHTTPMap.ts => StreamingHttpChannel2023/StreamingHttpMap.ts} (77%) rename src/server/notifications/{StreamingHTTPChannel2023/StreamingHTTPMetadataWriter.ts => StreamingHttpChannel2023/StreamingHttpMetadataWriter.ts} (75%) rename src/server/notifications/{StreamingHTTPChannel2023/StreamingHTTPRequestHandler.ts => StreamingHttpChannel2023/StreamingHttpRequestHandler.ts} (74%) rename test/integration/{StreamingHTTPChannel2023.test.ts => StreamingHttpChannel2023.test.ts} (64%) rename test/unit/server/notifications/{StreamingHTTPChannel2023/StreamingHTTP2023Emitter.test.ts => StreamingHttpChannel2023/StreamingHttp2023Emitter.test.ts} (68%) rename test/unit/server/notifications/{StreamingHTTPChannel2023/StreamingHTTPListeningActivityHandler.test.ts => StreamingHttpChannel2023/StreamingHttpListeningActivityHandler.test.ts} (87%) rename test/unit/server/notifications/{StreamingHTTPChannel2023/StreamingHTTPMetadataWriter.test.ts => StreamingHttpChannel2023/StreamingHttpMetadataWriter.test.ts} (66%) rename test/unit/server/notifications/{StreamingHTTPChannel2023/StreamingHTTPRequestHandler.test.ts => StreamingHttpChannel2023/StreamingHttpRequestHandler.test.ts} (85%) diff --git a/config/http/notifications/streaming-http/http.json b/config/http/notifications/streaming-http/http.json index acf49ac91..b75a6d596 100644 --- a/config/http/notifications/streaming-http/http.json +++ b/config/http/notifications/streaming-http/http.json @@ -7,9 +7,9 @@ "valueRaw": ".notifications/StreamingHTTPChannel2023/" }, { - "comment": "Creates updatesViaStreamingHTTP2023 Link relations", - "@id": "urn:solid-server:default:StreamingHTTPMetadataWriter", - "@type": "StreamingHTTPMetadataWriter", + "comment": "Creates updatesViaStreamingHttp2023 Link relations", + "@id": "urn:solid-server:default:StreamingHttpMetadataWriter", + "@type": "StreamingHttpMetadataWriter", "baseUrl": { "@id": "urn:solid-server:default:variable:baseUrl" }, "pathPrefix": { "@id": "urn:solid-server:default:variable:streamingHTTPReceiveFromPrefix" } }, @@ -18,20 +18,20 @@ "@id": "urn:solid-server:default:MetadataWriter", "@type": "ParallelHandler", "handlers": [ - { "@id": "urn:solid-server:default:StreamingHTTPMetadataWriter" } + { "@id": "urn:solid-server:default:StreamingHttpMetadataWriter" } ] }, { "comment": "Handles the request targeting a StreamingHTTPChannel2023 receiveFrom endpoint.", - "@id": "urn:solid-server:default:StreamingHTTP2023Router", + "@id": "urn:solid-server:default:StreamingHttp2023Router", "@type": "OperationRouterHandler", "baseUrl": { "@id": "urn:solid-server:default:variable:baseUrl" }, "allowedMethods": [ "GET" ], "allowedPathNames": [ "/StreamingHTTPChannel2023/" ], "handler": { - "@id": "urn:solid-server:default:StreamingHTTP2023RequestHandler", - "@type": "StreamingHTTPRequestHandler", - "streamMap": { "@id": "urn:solid-server:default:StreamingHTTPMap" }, + "@id": "urn:solid-server:default:StreamingHttp2023RequestHandler", + "@type": "StreamingHttpRequestHandler", + "streamMap": { "@id": "urn:solid-server:default:StreamingHttpMap" }, "pathPrefix": { "@id": "urn:solid-server:default:variable:streamingHTTPReceiveFromPrefix" }, "generator": { "@id": "urn:solid-server:default:BaseNotificationGenerator" }, "serializer": { "@id": "urn:solid-server:default:BaseNotificationSerializer" }, @@ -45,31 +45,31 @@ "@id": "urn:solid-server:default:NotificationTypeHandler", "@type": "WaterfallHandler", "handlers": [ - { "@id": "urn:solid-server:default:StreamingHTTP2023Router" } + { "@id": "urn:solid-server:default:StreamingHttp2023Router" } ] }, { "comment": "Opened response streams will be stored in this Map.", - "@id": "urn:solid-server:default:StreamingHTTPMap", - "@type": "StreamingHTTPMap" + "@id": "urn:solid-server:default:StreamingHttpMap", + "@type": "StreamingHttpMap" }, { - "comment": "Emits serialized notifications through StreamingHTTP.", - "@id": "urn:solid-server:default:StreamingHTTP2023Emitter", - "@type": "StreamingHTTP2023Emitter", - "streamMap": { "@id": "urn:solid-server:default:StreamingHTTPMap" } + "comment": "Emits serialized notifications through Streaming HTTP.", + "@id": "urn:solid-server:default:StreamingHttp2023Emitter", + "@type": "StreamingHttp2023Emitter", + "streamMap": { "@id": "urn:solid-server:default:StreamingHttpMap" } }, { "comment": "Listens to the activities emitted by the MonitoringStore.", - "@id": "urn:solid-server:default:StreamingHTTPListeningActivityHandler", - "@type": "StreamingHTTPListeningActivityHandler", + "@id": "urn:solid-server:default:StreamingHttpListeningActivityHandler", + "@type": "StreamingHttpListeningActivityHandler", "emitter": { "@id": "urn:solid-server:default:ResourceStore" }, "source": { "comment": "Handles the generation and serialization of notifications for StreamingHTTPChannel2023", "@type": "ComposedNotificationHandler", "generator": { "@id": "urn:solid-server:default:BaseNotificationGenerator" }, "serializer": { "@id": "urn:solid-server:default:BaseNotificationSerializer" }, - "emitter": { "@id": "urn:solid-server:default:StreamingHTTP2023Emitter" }, + "emitter": { "@id": "urn:solid-server:default:StreamingHttp2023Emitter" }, "eTagHandler": { "@id": "urn:solid-server:default:ETagHandler" } } }, @@ -78,7 +78,7 @@ "@id": "urn:solid-server:default:PrimaryParallelInitializer", "@type": "ParallelHandler", "handlers": [ - { "@id": "urn:solid-server:default:StreamingHTTPListeningActivityHandler" } + { "@id": "urn:solid-server:default:StreamingHttpListeningActivityHandler" } ] } ] diff --git a/src/index.ts b/src/index.ts index e63a088f7..57f6b4185 100644 --- a/src/index.ts +++ b/src/index.ts @@ -404,11 +404,11 @@ export * from './server/notifications/WebSocketChannel2023/WebSocketMap'; export * from './server/notifications/WebSocketChannel2023/WebSocketChannel2023Type'; // Server/Notifications/StreamingHTTPChannel2023 -export * from './server/notifications/StreamingHTTPChannel2023/StreamingHTTPRequestHandler'; -export * from './server/notifications/StreamingHTTPChannel2023/StreamingHTTPMap'; -export * from './server/notifications/StreamingHTTPChannel2023/StreamingHTTPListeningActivityHandler'; -export * from './server/notifications/StreamingHTTPChannel2023/StreamingHTTP2023Emitter'; -export * from './server/notifications/StreamingHTTPChannel2023/StreamingHTTPMetadataWriter'; +export * from './server/notifications/StreamingHttpChannel2023/StreamingHttpRequestHandler'; +export * from './server/notifications/StreamingHttpChannel2023/StreamingHttpMap'; +export * from './server/notifications/StreamingHttpChannel2023/StreamingHttpListeningActivityHandler'; +export * from './server/notifications/StreamingHttpChannel2023/StreamingHttp2023Emitter'; +export * from './server/notifications/StreamingHttpChannel2023/StreamingHttpMetadataWriter'; // Server/Notifications export * from './server/notifications/ActivityEmitter'; diff --git a/src/server/notifications/StreamingHTTPChannel2023/StreamingHTTP2023Emitter.ts b/src/server/notifications/StreamingHttpChannel2023/StreamingHttp2023Emitter.ts similarity index 63% rename from src/server/notifications/StreamingHTTPChannel2023/StreamingHTTP2023Emitter.ts rename to src/server/notifications/StreamingHttpChannel2023/StreamingHttp2023Emitter.ts index 1be9ad6c0..b47b479c1 100644 --- a/src/server/notifications/StreamingHTTPChannel2023/StreamingHTTP2023Emitter.ts +++ b/src/server/notifications/StreamingHttpChannel2023/StreamingHttp2023Emitter.ts @@ -1,11 +1,11 @@ import { getLoggerFor } from '../../../logging/LogUtil'; -import { StreamingHTTPMap } from './StreamingHTTPMap'; import type { Representation } from '../../../http/representation/Representation'; import { AsyncHandler } from '../../../util/handlers/AsyncHandler'; -import { NotificationChannel } from '../NotificationChannel'; +import type { NotificationChannel } from '../NotificationChannel'; +import type { StreamingHttpMap } from './StreamingHttpMap'; -export interface StreamingHTTPEmitterInput { +export interface StreamingHttpEmitterInput { channel: NotificationChannel; representation: Representation; } @@ -15,21 +15,21 @@ export interface StreamingHTTPEmitterInput { * Uses the StreamingHTTPs found in the provided map. * The key should be the identifier of the topic resource. */ -export class StreamingHTTP2023Emitter extends AsyncHandler { +export class StreamingHttp2023Emitter extends AsyncHandler { protected readonly logger = getLoggerFor(this); - constructor( - private readonly streamMap: StreamingHTTPMap + public constructor( + private readonly streamMap: StreamingHttpMap, ) { - super() + super(); } - public async handle({ channel, representation }: StreamingHTTPEmitterInput): Promise { + public async handle({ channel, representation }: StreamingHttpEmitterInput): Promise { // Called as a NotificationEmitter: emit the notification const streams = this.streamMap.get(channel.topic); if (streams) { for (const stream of streams) { - representation.data.pipe(stream, { end: false }) + representation.data.pipe(stream, { end: false }); } } else { representation.data.destroy(); diff --git a/src/server/notifications/StreamingHTTPChannel2023/StreamingHTTPListeningActivityHandler.ts b/src/server/notifications/StreamingHttpChannel2023/StreamingHttpListeningActivityHandler.ts similarity index 76% rename from src/server/notifications/StreamingHTTPChannel2023/StreamingHTTPListeningActivityHandler.ts rename to src/server/notifications/StreamingHttpChannel2023/StreamingHttpListeningActivityHandler.ts index 045bcc0a1..e484d3d11 100644 --- a/src/server/notifications/StreamingHTTPChannel2023/StreamingHTTPListeningActivityHandler.ts +++ b/src/server/notifications/StreamingHttpChannel2023/StreamingHttpListeningActivityHandler.ts @@ -4,10 +4,10 @@ import type { ResourceIdentifier } from '../../../http/representation/ResourceId import { getLoggerFor } from '../../../logging/LogUtil'; import { createErrorMessage } from '../../../util/errors/ErrorUtil'; import { StaticHandler } from '../../../util/handlers/StaticHandler'; -import { NOTIFY, type AS, type VocabularyTerm } from '../../../util/Vocabularies'; -import type { ActivityEmitter } from '.././ActivityEmitter'; -import type { NotificationHandler } from '.././NotificationHandler'; -import { NotificationChannel } from '../NotificationChannel'; +import { type AS, NOTIFY, type VocabularyTerm } from '../../../util/Vocabularies'; +import type { ActivityEmitter } from '../ActivityEmitter'; +import type { NotificationHandler } from '../NotificationHandler'; +import type { NotificationChannel } from '../NotificationChannel'; /** * Listens to an {@link ActivityEmitter} and calls the stored {@link NotificationHandler}s in case of an event @@ -17,12 +17,12 @@ import { NotificationChannel } from '../NotificationChannel'; * No class takes this one as input, so to make sure Components.js instantiates it, * it needs to be added somewhere where its presence has no impact, such as the list of initializers. */ -export class StreamingHTTPListeningActivityHandler extends StaticHandler { +export class StreamingHttpListeningActivityHandler extends StaticHandler { protected readonly logger = getLoggerFor(this); public constructor( emitter: ActivityEmitter, - private readonly source: NotificationHandler + private readonly source: NotificationHandler, ) { super(); @@ -39,16 +39,14 @@ export class StreamingHTTPListeningActivityHandler extends StaticHandler { metadata: RepresentationMetadata, ): Promise { const channel: NotificationChannel = { - // TODO decide what IRI should denote a pre-established channel id: `urn:uuid:${randomUUID()}`, type: NOTIFY.StreamingHTTPChannel2023, topic: topic.path, - accept: 'text/turtle' - } + accept: 'text/turtle', + }; try { - await this.source.handleSafe({ channel, activity, topic, metadata }) + await this.source.handleSafe({ channel, activity, topic, metadata }); } catch (error) { - // TODO: do we need to catch if only one channel per topic? this.logger.error(`Error trying to handle notification for ${topic.path}: ${createErrorMessage(error)}`); } } diff --git a/src/server/notifications/StreamingHTTPChannel2023/StreamingHTTPMap.ts b/src/server/notifications/StreamingHttpChannel2023/StreamingHttpMap.ts similarity index 77% rename from src/server/notifications/StreamingHTTPChannel2023/StreamingHTTPMap.ts rename to src/server/notifications/StreamingHttpChannel2023/StreamingHttpMap.ts index cb289439d..b8e250b29 100644 --- a/src/server/notifications/StreamingHTTPChannel2023/StreamingHTTPMap.ts +++ b/src/server/notifications/StreamingHttpChannel2023/StreamingHttpMap.ts @@ -1,10 +1,10 @@ -import type { PassThrough } from 'stream'; +import type { PassThrough } from 'node:stream'; import type { SingleThreaded } from '../../../init/cluster/SingleThreaded'; import { WrappedSetMultiMap } from '../../../util/map/WrappedSetMultiMap'; /** - * A {@link SetMultiMap} linking identifiers to a set of StreamingHTTP streams. + * A {@link SetMultiMap} linking identifiers to a set of Streaming HTTP streams. * An extension of {@link WrappedSetMultiMap} to make sure Components.js allows us to create this in the config, * as {@link WrappedSetMultiMap} has a constructor not supported. */ -export class StreamingHTTPMap extends WrappedSetMultiMap implements SingleThreaded {} +export class StreamingHttpMap extends WrappedSetMultiMap implements SingleThreaded {} diff --git a/src/server/notifications/StreamingHTTPChannel2023/StreamingHTTPMetadataWriter.ts b/src/server/notifications/StreamingHttpChannel2023/StreamingHttpMetadataWriter.ts similarity index 75% rename from src/server/notifications/StreamingHTTPChannel2023/StreamingHTTPMetadataWriter.ts rename to src/server/notifications/StreamingHttpChannel2023/StreamingHttpMetadataWriter.ts index ce8b81e6d..67470ad28 100644 --- a/src/server/notifications/StreamingHTTPChannel2023/StreamingHTTPMetadataWriter.ts +++ b/src/server/notifications/StreamingHttpChannel2023/StreamingHttpMetadataWriter.ts @@ -1,5 +1,5 @@ import { getLoggerFor } from '../../../logging/LogUtil'; -import type { HttpResponse } from '../../../server/HttpResponse'; +import type { HttpResponse } from '../../HttpResponse'; import { addHeader } from '../../../util/HeaderUtil'; import type { RepresentationMetadata } from '../../../http/representation/RepresentationMetadata'; import { MetadataWriter } from '../../../http/output/metadata/MetadataWriter'; @@ -8,21 +8,21 @@ import { MetadataWriter } from '../../../http/output/metadata/MetadataWriter'; * A {@link MetadataWriter} that adds link to the receiveFrom endpoint * of the corresponding Streaming HTTP notifications channel */ -export class StreamingHTTPMetadataWriter extends MetadataWriter { +export class StreamingHttpMetadataWriter extends MetadataWriter { protected readonly logger = getLoggerFor(this); public constructor( private readonly baseUrl: string, - private readonly pathPrefix: string + private readonly pathPrefix: string, ) { super(); } public async handle(input: { response: HttpResponse; metadata: RepresentationMetadata }): Promise { - const resourcePath = input.metadata.identifier.value.replace(this.baseUrl, '') - const receiveFrom = `${this.baseUrl}${this.pathPrefix}${resourcePath}` - const link = `<${receiveFrom}>; rel="http://www.w3.org/ns/solid/terms#updatesViaStreamingHTTP2023"` - this.logger.debug('Adding updatesViaStreamingHTTP2023 to the Link header'); + const resourcePath = input.metadata.identifier.value.replace(this.baseUrl, ''); + const receiveFrom = `${this.baseUrl}${this.pathPrefix}${resourcePath}`; + const link = `<${receiveFrom}>; rel="http://www.w3.org/ns/solid/terms#updatesViaStreamingHttp2023"`; + this.logger.debug('Adding updatesViaStreamingHttp2023 to the Link header'); addHeader(input.response, 'Link', link); } } diff --git a/src/server/notifications/StreamingHTTPChannel2023/StreamingHTTPRequestHandler.ts b/src/server/notifications/StreamingHttpChannel2023/StreamingHttpRequestHandler.ts similarity index 74% rename from src/server/notifications/StreamingHTTPChannel2023/StreamingHTTPRequestHandler.ts rename to src/server/notifications/StreamingHttpChannel2023/StreamingHttpRequestHandler.ts index 1aaca5e9e..38fa15646 100644 --- a/src/server/notifications/StreamingHTTPChannel2023/StreamingHTTPRequestHandler.ts +++ b/src/server/notifications/StreamingHttpChannel2023/StreamingHttpRequestHandler.ts @@ -1,4 +1,5 @@ -import { PassThrough } from 'stream'; +import { PassThrough } from 'node:stream'; +import { randomUUID } from 'node:crypto'; import type { Credentials } from '../../../authentication/Credentials'; import type { CredentialsExtractor } from '../../../authentication/CredentialsExtractor'; import type { Authorizer } from '../../../authorization/Authorizer'; @@ -12,58 +13,55 @@ import type { OperationHttpHandlerInput } from '../../OperationHttpHandler'; import { OperationHttpHandler } from '../../OperationHttpHandler'; import { guardStream } from '../../../util/GuardedStream'; import { IdentifierSetMultiMap } from '../../../util/map/IdentifierMap'; -import { StreamingHTTPMap } from './StreamingHTTPMap'; -import { NotificationChannel } from '../NotificationChannel'; -import { randomUUID } from 'node:crypto'; +import type { NotificationChannel } from '../NotificationChannel'; import { NOTIFY } from '../../../util/Vocabularies'; import { createErrorMessage } from '../../../util/errors/ErrorUtil'; -import { NotificationGenerator } from '../generate/NotificationGenerator'; -import { NotificationSerializer } from '../serialize/NotificationSerializer'; +import type { NotificationGenerator } from '../generate/NotificationGenerator'; +import type { NotificationSerializer } from '../serialize/NotificationSerializer'; +import type { StreamingHttpMap } from './StreamingHttpMap'; /** - * Handles request to StreamingHTTP receiveFrom endopints. - * All allowed requests are stored in the {@link StreamingHTTPMap} + * Handles request to Streaming HTTP receiveFrom endopints. + * All allowed requests are stored in the {@link StreamingHttpMap} */ -export class StreamingHTTPRequestHandler extends OperationHttpHandler { +export class StreamingHttpRequestHandler extends OperationHttpHandler { protected logger = getLoggerFor(this); - constructor( - private readonly streamMap: StreamingHTTPMap, + public constructor( + private readonly streamMap: StreamingHttpMap, private readonly pathPrefix: string, private readonly generator: NotificationGenerator, private readonly serializer: NotificationSerializer, private readonly credentialsExtractor: CredentialsExtractor, private readonly permissionReader: PermissionReader, - private readonly authorizer: Authorizer + private readonly authorizer: Authorizer, ) { - super() + super(); } public async handle({ operation, request }: OperationHttpHandlerInput): Promise { - const topic = operation.target.path.replace(this.pathPrefix, '') + const topic = operation.target.path.replace(this.pathPrefix, ''); // Verify if the client is allowed to connect const credentials = await this.credentialsExtractor.handleSafe(request); await this.authorize(credentials, topic); - const stream = guardStream(new PassThrough()) + const stream = guardStream(new PassThrough()); this.streamMap.add(topic, stream); - stream.on('error', () => this.streamMap.deleteEntry(topic, stream)); - stream.on('close', () => this.streamMap.deleteEntry(topic, stream)); + stream.on('error', (): boolean => this.streamMap.deleteEntry(topic, stream)); + stream.on('close', (): boolean => this.streamMap.deleteEntry(topic, stream)); - // TODO: de-duplicate with StreamingHTTPListeningActivityHandler const channel: NotificationChannel = { - // TODO decide what IRI should denote a pre-established channel id: `urn:uuid:${randomUUID()}`, type: NOTIFY.StreamingHTTPChannel2023, topic, - accept: 'text/turtle' - } + accept: 'text/turtle', + }; // Send initial notification try { - const notification = await this.generator.handle({ channel, topic: { path: topic } }); + const notification = await this.generator.handle({ channel, topic: { path: topic }}); const representation = await this.serializer.handleSafe({ channel, notification }); - representation.data.pipe(stream, { end: false }) + representation.data.pipe(stream, { end: false }); } catch (error: unknown) { this.logger.error(`Problem emitting initial notification: ${createErrorMessage(error)}`); } @@ -71,13 +69,13 @@ export class StreamingHTTPRequestHandler extends OperationHttpHandler { const representation = new BasicRepresentation(topic, operation.target, 'text/turtle'); return new OkResponseDescription( representation.metadata, - stream + stream, ); } /** - * TODO: consider removing duplication with {@link NotificationsSubscriber} - */ + * TODO: consider removing duplication with {@link NotificationsSubscriber} + */ private async authorize(credentials: Credentials, topic: string): Promise { const requestedModes = new IdentifierSetMultiMap([[{ path: topic }, AccessMode.read ]]); this.logger.debug(`Retrieved required modes: ${[ ...requestedModes.entrySets() ].join(',')}`); diff --git a/test/integration/StreamingHTTPChannel2023.test.ts b/test/integration/StreamingHttpChannel2023.test.ts similarity index 64% rename from test/integration/StreamingHTTPChannel2023.test.ts rename to test/integration/StreamingHttpChannel2023.test.ts index 693da49bf..5dc8a1c74 100644 --- a/test/integration/StreamingHTTPChannel2023.test.ts +++ b/test/integration/StreamingHttpChannel2023.test.ts @@ -3,7 +3,7 @@ import { BasicRepresentation } from '../../src/http/representation/BasicRepresen import type { App } from '../../src/init/App'; import type { ResourceStore } from '../../src/storage/ResourceStore'; import { joinUrl } from '../../src/util/PathUtil'; -import { AS, NOTIFY, RDF } from '../../src/util/Vocabularies'; +import { AS, RDF } from '../../src/util/Vocabularies'; import { getPort } from '../util/Util'; import { getDefaultVariables, @@ -17,7 +17,6 @@ import namedNode = DataFactory.namedNode; const port = getPort('StreamingHTTPChannel2023'); const baseUrl = `http://localhost:${port}/`; -const notificationType = NOTIFY.StreamingHTTPChannel2023; const rootFilePath = getTestFolder('StreamingHTTPChannel2023'); const stores: [string, any][] = [ @@ -31,13 +30,12 @@ const stores: [string, any][] = [ }], ]; - describe.each(stores)('A server supporting StreamingHTTPChannel2023 using %s', (name, { configs, teardown }): void => { let app: App; let store: ResourceStore; const webId = 'http://example.com/card/#me'; const topic = joinUrl(baseUrl, '/foo'); - const pathPrefix = '.notifications/StreamingHTTPChannel2023' + const pathPrefix = '.notifications/StreamingHTTPChannel2023'; const receiveFrom = joinUrl(baseUrl, pathPrefix, '/foo'); beforeAll(async(): Promise => { @@ -65,71 +63,71 @@ describe.each(stores)('A server supporting StreamingHTTPChannel2023 using %s', ( await app.stop(); }); - - it('advertises streaming http endpoint in Link header', async(): Promise => { + it('advertises streaming http endpoint in Link header.', async(): Promise => { await store.setRepresentation({ path: topic }, new BasicRepresentation('new', 'text/plain')); - const response = await fetch(topic) + const response = await fetch(topic); expect(response.status).toBe(200); const linkHeader = response.headers.get('link'); - const match = /<([^>]+)>; rel="http:\/\/www\.w3\.org\/ns\/solid\/terms#updatesViaStreamingHTTP2023"/u.exec(linkHeader!); - expect(match![1]).toEqual(receiveFrom) + const match = /<([^>]+)>; rel="http:\/\/www\.w3\.org\/ns\/solid\/terms#updatesViaStreamingHttp2023"/u + .exec(linkHeader!); + expect(match![1]).toEqual(receiveFrom); }); - it.todo('only allows GET on receiveFrom endpoint'); + it.todo('only allows GET on receiveFrom endpoint.'); it('emits initial Update if topic exists.', async(): Promise => { await store.setRepresentation({ path: topic }, new BasicRepresentation('new', 'text/plain')); - const streamingResponse = await fetch(receiveFrom) - const reader = streamingResponse.body!.getReader() - const decoder = new TextDecoder() - - const notification = await reader.read().then(({ value }) => decoder.decode(value)) - expect(notification).toBeDefined() + const streamingResponse = await fetch(receiveFrom); + const reader = streamingResponse.body!.getReader(); + const decoder = new TextDecoder(); + + const notification = await reader.read().then(({ value }): string => decoder.decode(value)); + expect(notification).toBeDefined(); const parser = new Parser(); - const quads = new Store(parser.parse(notification)) + const quads = new Store(parser.parse(notification)); - expect(quads.getObjects(null, RDF.terms.type, null)).toEqual([ AS.terms.Update]); + expect(quads.getObjects(null, RDF.terms.type, null)).toEqual([ AS.terms.Update ]); expect(quads.getObjects(null, AS.terms.object, null)).toEqual([ namedNode(topic) ]); - reader.releaseLock() - await streamingResponse.body!.cancel() - }) + reader.releaseLock(); + await streamingResponse.body!.cancel(); + }); it('emits initial Delete if topic does not exist.', async(): Promise => { try { - await store.deleteResource({ path: topic }) + await store.deleteResource({ path: topic }); } catch {} - const streamingResponse = await fetch(receiveFrom) - const reader = streamingResponse.body!.getReader() - const decoder = new TextDecoder() - - const notification = await reader.read().then(({ value }) => decoder.decode(value)) - expect(notification).toBeDefined() + const streamingResponse = await fetch(receiveFrom); + const reader = streamingResponse.body!.getReader(); + const decoder = new TextDecoder(); + + const notification = await reader.read().then(({ value }): string => decoder.decode(value)); + expect(notification).toBeDefined(); const parser = new Parser(); - const quads = new Store(parser.parse(notification)) + const quads = new Store(parser.parse(notification)); - expect(quads.getObjects(null, RDF.terms.type, null)).toEqual([ AS.terms.Delete]); + expect(quads.getObjects(null, RDF.terms.type, null)).toEqual([ AS.terms.Delete ]); expect(quads.getObjects(null, AS.terms.object, null)).toEqual([ namedNode(topic) ]); - reader.releaseLock() - await streamingResponse.body!.cancel() - }) + reader.releaseLock(); + await streamingResponse.body!.cancel(); + }); - it.todo('does not emit initial notification when other receivers connect.') + it.todo('does not emit initial notification when other receivers connect.'); it('emits Create events.', async(): Promise => { try { - await store.deleteResource({ path: topic }) + await store.deleteResource({ path: topic }); } catch {} - const streamingResponse = await fetch(receiveFrom) - const reader = streamingResponse.body!.getReader() - const decoder = new TextDecoder() - // ignore initial notification - await reader.read().then(({ value }) => decoder.decode(value)) - - // create resource + const streamingResponse = await fetch(receiveFrom); + const reader = streamingResponse.body!.getReader(); + const decoder = new TextDecoder(); + // Ignore initial notification + await reader.read().then(({ value }): string => decoder.decode(value)); + + // Create resource const response = await fetch(topic, { method: 'PUT', headers: { 'content-type': 'text/plain' }, @@ -137,28 +135,28 @@ describe.each(stores)('A server supporting StreamingHTTPChannel2023 using %s', ( }); expect(response.status).toBe(201); - const notification = await reader.read().then(({ value }) => decoder.decode(value)) - expect(notification).toBeDefined() + const notification = await reader.read().then(({ value }): string => decoder.decode(value)); + expect(notification).toBeDefined(); const parser = new Parser(); - const quads = new Store(parser.parse(notification)) + const quads = new Store(parser.parse(notification)); - expect(quads.getObjects(null, RDF.terms.type, null)).toEqual([ AS.terms.Create]); + expect(quads.getObjects(null, RDF.terms.type, null)).toEqual([ AS.terms.Create ]); expect(quads.getObjects(null, AS.terms.object, null)).toEqual([ namedNode(topic) ]); - reader.releaseLock() - await streamingResponse.body!.cancel() - }) + reader.releaseLock(); + await streamingResponse.body!.cancel(); + }); it('emits Update events.', async(): Promise => { await store.setRepresentation({ path: topic }, new BasicRepresentation('new', 'text/plain')); - const streamingResponse = await fetch(receiveFrom) - const reader = streamingResponse.body!.getReader() - const decoder = new TextDecoder() - // ignore initial notification - await reader.read().then(({ value }) => decoder.decode(value)) + const streamingResponse = await fetch(receiveFrom); + const reader = streamingResponse.body!.getReader(); + const decoder = new TextDecoder(); + // Ignore initial notification + await reader.read().then(({ value }): string => decoder.decode(value)); - // update resource + // Update resource const response = await fetch(topic, { method: 'PUT', headers: { 'content-type': 'text/plain' }, @@ -166,44 +164,44 @@ describe.each(stores)('A server supporting StreamingHTTPChannel2023 using %s', ( }); expect(response.status).toBe(205); - const notification = await reader.read().then(({ value }) => decoder.decode(value)) - expect(notification).toBeDefined() + const notification = await reader.read().then(({ value }): string => decoder.decode(value)); + expect(notification).toBeDefined(); const parser = new Parser(); - const quads = new Store(parser.parse(notification)) + const quads = new Store(parser.parse(notification)); - expect(quads.getObjects(null, RDF.terms.type, null)).toEqual([ AS.terms.Update]); + expect(quads.getObjects(null, RDF.terms.type, null)).toEqual([ AS.terms.Update ]); expect(quads.getObjects(null, AS.terms.object, null)).toEqual([ namedNode(topic) ]); - reader.releaseLock() - await streamingResponse.body!.cancel() + reader.releaseLock(); + await streamingResponse.body!.cancel(); }); it('emits Delete events.', async(): Promise => { await store.setRepresentation({ path: topic }, new BasicRepresentation('new', 'text/plain')); - const streamingResponse = await fetch(receiveFrom) - const reader = streamingResponse.body!.getReader() - const decoder = new TextDecoder() - // ignore initial notification - await reader.read().then(({ value }) => decoder.decode(value)) + const streamingResponse = await fetch(receiveFrom); + const reader = streamingResponse.body!.getReader(); + const decoder = new TextDecoder(); + // Ignore initial notification + await reader.read().then(({ value }): string => decoder.decode(value)); - // delete resource + // Delete resource const response = await fetch(topic, { method: 'DELETE', }); expect(response.status).toBe(205); - const notification = await reader.read().then(({ value }) => decoder.decode(value)) - expect(notification).toBeDefined() + const notification = await reader.read().then(({ value }): string => decoder.decode(value)); + expect(notification).toBeDefined(); const parser = new Parser(); - const quads = new Store(parser.parse(notification)) + const quads = new Store(parser.parse(notification)); - expect(quads.getObjects(null, RDF.terms.type, null)).toEqual([ AS.terms.Delete]); + expect(quads.getObjects(null, RDF.terms.type, null)).toEqual([ AS.terms.Delete ]); expect(quads.getObjects(null, AS.terms.object, null)).toEqual([ namedNode(topic) ]); - reader.releaseLock() - await streamingResponse.body!.cancel() + reader.releaseLock(); + await streamingResponse.body!.cancel(); }); it('prevents connecting to channels of restricted topics.', async(): Promise => { @@ -232,11 +230,11 @@ describe.each(stores)('A server supporting StreamingHTTPChannel2023 using %s', ( const authenticatedResponse = await fetch(restrictedReceiveFrom, { headers: { authorization: `WebID ${webId}`, - } + }, }); expect(authenticatedResponse.status).toBe(200); - await authenticatedResponse.body!.cancel() + await authenticatedResponse.body!.cancel(); }); it('emits container notifications if contents get added or removed.', async(): Promise => { @@ -244,14 +242,14 @@ describe.each(stores)('A server supporting StreamingHTTPChannel2023 using %s', ( const baseReceiveFrom = joinUrl(baseUrl, pathPrefix, '/'); // Connecting to the base URL, which is the parent container - const streamingResponse = await fetch(baseReceiveFrom) - const reader = streamingResponse.body!.getReader() - const decoder = new TextDecoder() + const streamingResponse = await fetch(baseReceiveFrom); + const reader = streamingResponse.body!.getReader(); + const decoder = new TextDecoder(); const parser = new Parser(); - // ignore initial notification - await reader.read().then(({ value }) => decoder.decode(value)) + // Ignore initial notification + await reader.read().then(({ value }): string => decoder.decode(value)); - // create contained resource + // Create contained resource const createResponse = await fetch(resource, { method: 'PUT', headers: { 'content-type': 'text/plain' }, @@ -260,32 +258,32 @@ describe.each(stores)('A server supporting StreamingHTTPChannel2023 using %s', ( expect(createResponse.status).toBe(201); // Will receive the Add notification - const addNotification = await reader.read().then(({ value }) => decoder.decode(value)) - expect(addNotification).toBeDefined() + const addNotification = await reader.read().then(({ value }): string => decoder.decode(value)); + expect(addNotification).toBeDefined(); - const addQuads = new Store(parser.parse(addNotification)) + const addQuads = new Store(parser.parse(addNotification)); - expect(addQuads.getObjects(null, RDF.terms.type, null)).toEqual([ AS.terms.Add]); + expect(addQuads.getObjects(null, RDF.terms.type, null)).toEqual([ AS.terms.Add ]); expect(addQuads.getObjects(null, AS.terms.object, null)).toEqual([ namedNode(resource) ]); expect(addQuads.getObjects(null, AS.terms.target, null)).toEqual([ namedNode(baseUrl) ]); - // remove contained resource + // Remove contained resource const removeResponse = await fetch(resource, { method: 'DELETE', }); expect(removeResponse.status).toBe(205); // Will receive the Remove notification - const removeNotification = await reader.read().then(({ value }) => decoder.decode(value)) - expect(removeNotification).toBeDefined() + const removeNotification = await reader.read().then(({ value }): string => decoder.decode(value)); + expect(removeNotification).toBeDefined(); - const removeQuads = new Store(parser.parse(removeNotification)) + const removeQuads = new Store(parser.parse(removeNotification)); - expect(removeQuads.getObjects(null, RDF.terms.type, null)).toEqual([ AS.terms.Remove]); + expect(removeQuads.getObjects(null, RDF.terms.type, null)).toEqual([ AS.terms.Remove ]); expect(removeQuads.getObjects(null, AS.terms.object, null)).toEqual([ namedNode(resource) ]); expect(removeQuads.getObjects(null, AS.terms.target, null)).toEqual([ namedNode(baseUrl) ]); - reader.releaseLock() - await streamingResponse.body!.cancel() + reader.releaseLock(); + await streamingResponse.body!.cancel(); }); }); diff --git a/test/unit/server/notifications/StreamingHTTPChannel2023/StreamingHTTP2023Emitter.test.ts b/test/unit/server/notifications/StreamingHttpChannel2023/StreamingHttp2023Emitter.test.ts similarity index 68% rename from test/unit/server/notifications/StreamingHTTPChannel2023/StreamingHTTP2023Emitter.test.ts rename to test/unit/server/notifications/StreamingHttpChannel2023/StreamingHttp2023Emitter.test.ts index 3c7e39e5f..5ea91d0c8 100644 --- a/test/unit/server/notifications/StreamingHTTPChannel2023/StreamingHTTP2023Emitter.test.ts +++ b/test/unit/server/notifications/StreamingHttpChannel2023/StreamingHttp2023Emitter.test.ts @@ -1,13 +1,13 @@ -import { PassThrough } from 'stream'; +import { PassThrough } from 'node:stream'; import { BasicRepresentation } from '../../../../../src/http/representation/BasicRepresentation'; import type { NotificationChannel } from '../../../../../src/server/notifications/NotificationChannel'; import { - StreamingHTTP2023Emitter, -} from '../../../../../src/server/notifications/StreamingHTTPChannel2023/StreamingHTTP2023Emitter'; + StreamingHttp2023Emitter, +} from '../../../../../src/server/notifications/StreamingHttpChannel2023/StreamingHttp2023Emitter'; import { WrappedSetMultiMap } from '../../../../../src/util/map/WrappedSetMultiMap'; -import type { StreamingHTTPMap } from '../../../../../src'; +import type { StreamingHttpMap } from '../../../../../src'; -describe('A StreamingHTTP2023Emitter', (): void => { +describe('A StreamingHttp2023Emitter', (): void => { const channel: NotificationChannel = { id: 'id', topic: 'http://example.com/foo', @@ -15,64 +15,64 @@ describe('A StreamingHTTP2023Emitter', (): void => { }; let stream: jest.Mocked; - let streamMap: StreamingHTTPMap; - let emitter: StreamingHTTP2023Emitter; + let streamMap: StreamingHttpMap; + let emitter: StreamingHttp2023Emitter; beforeEach(async(): Promise => { - stream = jest.mocked(new PassThrough()) + stream = jest.mocked(new PassThrough()); streamMap = new WrappedSetMultiMap(); - emitter = new StreamingHTTP2023Emitter(streamMap); + emitter = new StreamingHttp2023Emitter(streamMap); }); it('emits notifications to the stored Streams.', async(): Promise => { streamMap.add(channel.topic, stream); const representation = new BasicRepresentation('notification', 'text/plain'); - const spy = jest.spyOn(representation.data, 'pipe') + const spy = jest.spyOn(representation.data, 'pipe'); await expect(emitter.handle({ channel, representation })).resolves.toBeUndefined(); expect(spy).toHaveBeenCalledTimes(1); - expect(spy).toHaveBeenLastCalledWith(stream, { end: false}); + expect(spy).toHaveBeenLastCalledWith(stream, { end: false }); }); it('destroys the representation if there is no matching Stream.', async(): Promise => { const representation = new BasicRepresentation('notification', 'text/plain'); - const spy = jest.spyOn(representation.data, 'pipe') + const spy = jest.spyOn(representation.data, 'pipe'); await expect(emitter.handle({ channel, representation })).resolves.toBeUndefined(); expect(spy).toHaveBeenCalledTimes(0); expect(representation.data.destroyed).toBe(true); }); it('can write to multiple matching Streams.', async(): Promise => { - const stream2 = jest.mocked(new PassThrough()) + const stream2 = jest.mocked(new PassThrough()); streamMap.add(channel.topic, stream); streamMap.add(channel.topic, stream2); const representation = new BasicRepresentation('notification', 'text/plain'); - const spy = jest.spyOn(representation.data, 'pipe') + const spy = jest.spyOn(representation.data, 'pipe'); await expect(emitter.handle({ channel, representation })).resolves.toBeUndefined(); expect(spy).toHaveBeenCalledTimes(2); expect(spy).toHaveBeenCalledWith(stream, { end: false }); - expect(spy).toHaveBeenLastCalledWith(stream2, { end: false}); + expect(spy).toHaveBeenLastCalledWith(stream2, { end: false }); }); it('only writes to the matching topic Streams.', async(): Promise => { - const stream2 = jest.mocked(new PassThrough()) + const stream2 = jest.mocked(new PassThrough()); const channel2: NotificationChannel = { ...channel, id: 'other id', - topic: 'other topic' + topic: 'other topic', }; streamMap.add(channel.topic, stream); streamMap.add(channel2.topic, stream2); const representation = new BasicRepresentation('notification', 'text/plain'); - const spy = jest.spyOn(representation.data, 'pipe') + const spy = jest.spyOn(representation.data, 'pipe'); await expect(emitter.handle({ channel, representation })).resolves.toBeUndefined(); expect(spy).toHaveBeenCalledTimes(1); - expect(spy).toHaveBeenLastCalledWith(stream, { end: false}); + expect(spy).toHaveBeenLastCalledWith(stream, { end: false }); }); }); diff --git a/test/unit/server/notifications/StreamingHTTPChannel2023/StreamingHTTPListeningActivityHandler.test.ts b/test/unit/server/notifications/StreamingHttpChannel2023/StreamingHttpListeningActivityHandler.test.ts similarity index 87% rename from test/unit/server/notifications/StreamingHTTPChannel2023/StreamingHTTPListeningActivityHandler.test.ts rename to test/unit/server/notifications/StreamingHttpChannel2023/StreamingHttpListeningActivityHandler.test.ts index 9ce1cf247..2aabd1031 100644 --- a/test/unit/server/notifications/StreamingHTTPChannel2023/StreamingHTTPListeningActivityHandler.test.ts +++ b/test/unit/server/notifications/StreamingHttpChannel2023/StreamingHttpListeningActivityHandler.test.ts @@ -7,14 +7,14 @@ import type { ActivityEmitter } from '../../../../../src/server/notifications/Ac import type { NotificationHandler } from '../../../../../src/server/notifications/NotificationHandler'; import { AS } from '../../../../../src/util/Vocabularies'; import { flushPromises } from '../../../../util/Util'; -import { StreamingHTTPListeningActivityHandler } from '../../../../../src'; +import { StreamingHttpListeningActivityHandler } from '../../../../../src'; jest.mock('../../../../../src/logging/LogUtil', (): any => { const logger: Logger = { error: jest.fn() } as any; return { getLoggerFor: (): Logger => logger }; }); -describe('A StreamingHTTPListeningActivityHandler', (): void => { +describe('A StreamingHttpListeningActivityHandler', (): void => { const logger: jest.Mocked = getLoggerFor('mock') as any; const topic: ResourceIdentifier = { path: 'http://example.com/foo' }; const activity = AS.terms.Update; @@ -31,7 +31,7 @@ describe('A StreamingHTTPListeningActivityHandler', (): void => { } as any; // eslint-disable-next-line no-new - new StreamingHTTPListeningActivityHandler(emitter, notificationHandler); + new StreamingHttpListeningActivityHandler(emitter, notificationHandler); }); it('calls the NotificationHandler if there is an event.', async(): Promise => { @@ -40,7 +40,9 @@ describe('A StreamingHTTPListeningActivityHandler', (): void => { await flushPromises(); expect(notificationHandler.handleSafe).toHaveBeenCalledTimes(1); - expect(notificationHandler.handleSafe).toHaveBeenLastCalledWith(expect.objectContaining({ activity, topic, metadata })); + expect(notificationHandler.handleSafe).toHaveBeenLastCalledWith( + expect.objectContaining({ activity, topic, metadata }), + ); expect(logger.error).toHaveBeenCalledTimes(0); }); @@ -56,8 +58,9 @@ describe('A StreamingHTTPListeningActivityHandler', (): void => { }); it('logs an error if something goes wrong handling the event.', async(): Promise => { - - const erroringTopic = { get path() { throw new Error('bad event') }} as unknown as ResourceIdentifier + const erroringTopic = { get path(): string { + throw new Error('bad event'); + } } as unknown as ResourceIdentifier; emitter.emit('changed', erroringTopic, activity, metadata); diff --git a/test/unit/server/notifications/StreamingHTTPChannel2023/StreamingHTTPMetadataWriter.test.ts b/test/unit/server/notifications/StreamingHttpChannel2023/StreamingHttpMetadataWriter.test.ts similarity index 66% rename from test/unit/server/notifications/StreamingHTTPChannel2023/StreamingHTTPMetadataWriter.test.ts rename to test/unit/server/notifications/StreamingHttpChannel2023/StreamingHttpMetadataWriter.test.ts index cb3997db1..7b2110895 100644 --- a/test/unit/server/notifications/StreamingHTTPChannel2023/StreamingHTTPMetadataWriter.test.ts +++ b/test/unit/server/notifications/StreamingHttpChannel2023/StreamingHttpMetadataWriter.test.ts @@ -1,13 +1,15 @@ import { createResponse } from 'node-mocks-http'; -import { StreamingHTTPMetadataWriter } from '../../../../../src/server/notifications/StreamingHTTPChannel2023/StreamingHTTPMetadataWriter'; +import { + StreamingHttpMetadataWriter, +} from '../../../../../src/server/notifications/StreamingHttpChannel2023/StreamingHttpMetadataWriter'; import { RepresentationMetadata } from '../../../../../src/http/representation/RepresentationMetadata'; import type { HttpResponse } from '../../../../../src/server/HttpResponse'; -describe('A StreamingHTTPMetadataWriter', (): void => { - const baseUrl = 'http://example.org/' - const pathPrefix = '.notifications/StreamingHTTPChannel2023/' - const writer = new StreamingHTTPMetadataWriter(baseUrl, pathPrefix); - const rel = 'http://www.w3.org/ns/solid/terms#updatesViaStreamingHTTP2023' +describe('A StreamingHttpMetadataWriter', (): void => { + const baseUrl = 'http://example.org/'; + const pathPrefix = '.notifications/StreamingHTTPChannel2023/'; + const writer = new StreamingHttpMetadataWriter(baseUrl, pathPrefix); + const rel = 'http://www.w3.org/ns/solid/terms#updatesViaStreamingHttp2023'; it('adds the correct link header.', async(): Promise => { const response = createResponse() as HttpResponse; diff --git a/test/unit/server/notifications/StreamingHTTPChannel2023/StreamingHTTPRequestHandler.test.ts b/test/unit/server/notifications/StreamingHttpChannel2023/StreamingHttpRequestHandler.test.ts similarity index 85% rename from test/unit/server/notifications/StreamingHTTPChannel2023/StreamingHTTPRequestHandler.test.ts rename to test/unit/server/notifications/StreamingHttpChannel2023/StreamingHttpRequestHandler.test.ts index 49521455e..246cb6970 100644 --- a/test/unit/server/notifications/StreamingHTTPChannel2023/StreamingHTTPRequestHandler.test.ts +++ b/test/unit/server/notifications/StreamingHttpChannel2023/StreamingHttpRequestHandler.test.ts @@ -13,9 +13,10 @@ import type { Logger } from '../../../../../src/logging/Logger'; import { getLoggerFor } from '../../../../../src/logging/LogUtil'; import { - StreamingHTTPRequestHandler, -} from '../../../../../src/server/notifications/StreamingHTTPChannel2023/StreamingHTTPRequestHandler'; -import { NotificationGenerator, NotificationSerializer, StreamingHTTPMap } from '../../../../../src'; + StreamingHttpRequestHandler, +} from '../../../../../src/server/notifications/StreamingHttpChannel2023/StreamingHttpRequestHandler'; +import type { NotificationGenerator, NotificationSerializer } from '../../../../../src'; +import { StreamingHttpMap } from '../../../../../src'; import type { Notification } from '../../../../../src/server/notifications/Notification'; import { flushPromises } from '../../../../util/Util'; @@ -24,11 +25,10 @@ jest.mock('../../../../../src/logging/LogUtil', (): any => { return { getLoggerFor: (): Logger => logger }; }); -/* eslint-disable jest/prefer-spy-on */ -describe('A StreamingHTTPRequestHandler', (): void => { +describe('A StreamingHttpRequestHandler', (): void => { const logger: jest.Mocked = getLoggerFor('mock') as any; const topic: ResourceIdentifier = { path: 'http://example.com/foo' }; - const pathPrefix = '.notifications/StreamingHTTPChannel2023/' + const pathPrefix = '.notifications/StreamingHTTPChannel2023/'; const channel: NotificationChannel = { id: 'id', topic: topic.path, @@ -48,14 +48,14 @@ describe('A StreamingHTTPRequestHandler', (): void => { const representation = new BasicRepresentation(); const request: HttpRequest = {} as any; const response: HttpResponse = {} as any; - let streamMap: StreamingHTTPMap + let streamMap: StreamingHttpMap; let operation: Operation; let generator: jest.Mocked; let serializer: jest.Mocked; let credentialsExtractor: jest.Mocked; let permissionReader: jest.Mocked; let authorizer: jest.Mocked; - let handler: StreamingHTTPRequestHandler; + let handler: StreamingHttpRequestHandler; beforeEach(async(): Promise => { operation = { @@ -65,7 +65,7 @@ describe('A StreamingHTTPRequestHandler', (): void => { preferences: {}, }; - streamMap = new StreamingHTTPMap(); + streamMap = new StreamingHttpMap(); generator = { canHandle: jest.fn(), @@ -76,7 +76,6 @@ describe('A StreamingHTTPRequestHandler', (): void => { handleSafe: jest.fn().mockResolvedValue(representation), } as any; - credentialsExtractor = { handleSafe: jest.fn().mockResolvedValue({ public: {}}), } as any; @@ -89,7 +88,15 @@ describe('A StreamingHTTPRequestHandler', (): void => { handleSafe: jest.fn(), } as any; - handler = new StreamingHTTPRequestHandler(streamMap, pathPrefix, generator, serializer, credentialsExtractor, permissionReader, authorizer); + handler = new StreamingHttpRequestHandler( + streamMap, + pathPrefix, + generator, + serializer, + credentialsExtractor, + permissionReader, + authorizer, + ); }); it('stores streams.', async(): Promise => { @@ -100,7 +107,7 @@ describe('A StreamingHTTPRequestHandler', (): void => { it('removes closed streams.', async(): Promise => { const description = await handler.handle({ operation, request, response }); - expect(streamMap.has(channel.topic)).toBe(true) + expect(streamMap.has(channel.topic)).toBe(true); description.data!.emit('close'); expect(streamMap.has(channel.topic)).toBe(false); }); @@ -114,16 +121,16 @@ describe('A StreamingHTTPRequestHandler', (): void => { it('sets content type to turtle.', async(): Promise => { const description = await handler.handle({ operation, request, response }); - expect(description.metadata?.contentType).toBe('text/turtle') + expect(description.metadata?.contentType).toBe('text/turtle'); }); it('responds with the stream.', async(): Promise => { const description = await handler.handle({ operation, request, response }); - expect(description.data).toBeDefined() + expect(description.data).toBeDefined(); }); it('sends initial notification.', async(): Promise => { - const spy = jest.spyOn(representation.data, 'pipe') + const spy = jest.spyOn(representation.data, 'pipe'); await handler.handle({ operation, request, response }); expect(spy).toHaveBeenCalledTimes(1); });