fix: Use full encoded topic iri in streaming http receiveFrom url template

* fix: use full encoded topic iri in streaming http receiveFrom url template

* clean up urls and routing
This commit is contained in:
elf Pavlik
2024-08-19 00:58:53 -06:00
committed by GitHub
parent 4599bf413e
commit 3e8365bb26
7 changed files with 42 additions and 26 deletions

View File

@@ -2,19 +2,24 @@ import { createResponse } from 'node-mocks-http';
import {
StreamingHttpMetadataWriter,
} from '../../../../../src/server/notifications/StreamingHttpChannel2023/StreamingHttpMetadataWriter';
import {
AbsolutePathInteractionRoute,
} from '../../../../../src/identity/interaction/routing/AbsolutePathInteractionRoute';
import { RepresentationMetadata } from '../../../../../src/http/representation/RepresentationMetadata';
import type { HttpResponse } from '../../../../../src/server/HttpResponse';
import type { ResourceIdentifier } from '../../../../../src/http/representation/ResourceIdentifier';
describe('A StreamingHttpMetadataWriter', (): void => {
const baseUrl = 'http://example.org/';
const pathPrefix = '.notifications/StreamingHTTPChannel2023/';
const writer = new StreamingHttpMetadataWriter(baseUrl, pathPrefix);
const path = 'http://example.org/.notifications/StreamingHTTPChannel2023/';
const route = new AbsolutePathInteractionRoute(path);
const writer = new StreamingHttpMetadataWriter(route);
const rel = 'http://www.w3.org/ns/solid/terms#updatesViaStreamingHttp2023';
it('adds the correct link header.', async(): Promise<void> => {
const topic: ResourceIdentifier = { path: 'http://example.com/foo' };
const response = createResponse() as HttpResponse;
const metadata = new RepresentationMetadata({ path: 'http://example.org/foo/bar/baz' });
const metadata = new RepresentationMetadata(topic);
await expect(writer.handle({ response, metadata })).resolves.toBeUndefined();
expect(response.getHeaders()).toEqual({ link: `<http://example.org/.notifications/StreamingHTTPChannel2023/foo/bar/baz>; rel="${rel}"` });
expect(response.getHeaders()).toEqual({ link: `<http://example.org/.notifications/StreamingHTTPChannel2023/${encodeURIComponent(topic.path)}>; rel="${rel}"` });
});
});