feat: Only accept NamedNodes as predicates for metadata

* refactor: move toCachedNamedNode (private)

* chore: only NamedNodes predicates in removes

* feat: enforce NamedNode predicates in most cases

* feat: getAll only accepts NamedNodes

* feat: toCachedNamedNode only accepts string arg

* tests: use NamedNodes for getAll calls

* test: remove unnecessary string check for coverage

* tests: fix NamedNodes in new tests after rebase

* feat: metadatawriters store NamedNodes

* refactor: toCachedNamedNode as utility function

* fix: double write of linkRelMap

* test: use the CONTENT_TYPE constant
This commit is contained in:
Jasper Vaneessen
2022-04-15 09:53:39 +02:00
committed by GitHub
parent db906ae872
commit 668d0a331f
26 changed files with 172 additions and 183 deletions

View File

@@ -63,7 +63,7 @@ describe('A ConstantConverter', (): void => {
it('does not support representations that are already in the right format.', async(): Promise<void> => {
const preferences = { type: { 'text/html': 1 }};
const metadata = new RepresentationMetadata({ contentType: 'text/html' });
const metadata = new RepresentationMetadata({ [CONTENT_TYPE]: 'text/html' });
const representation = { metadata } as any;
const args = { identifier, representation, preferences };
@@ -101,7 +101,7 @@ describe('A ConstantConverter', (): void => {
it('replaces the representation of a supported request.', async(): Promise<void> => {
const preferences = { type: { 'text/html': 1 }};
const metadata = new RepresentationMetadata({ contentType: 'text/turtle' });
const metadata = new RepresentationMetadata({ [CONTENT_TYPE]: 'text/turtle' });
const representation = { metadata, data: { destroy: jest.fn() }} as any;
const args = { identifier, representation, preferences };

View File

@@ -2,6 +2,7 @@ import 'jest-rdf';
import { RepresentationMetadata } from '../../../../src/http/representation/RepresentationMetadata';
import { ContentTypeReplacer } from '../../../../src/storage/conversion/ContentTypeReplacer';
import { NotImplementedHttpError } from '../../../../src/util/errors/NotImplementedHttpError';
import { CONTENT_TYPE } from '../../../../src/util/Vocabularies';
const binary = true;
const data = { data: true };
@@ -21,7 +22,7 @@ describe('A ContentTypeReplacer', (): void => {
});
it('throws on an unsupported input type.', async(): Promise<void> => {
const metadata = new RepresentationMetadata({ contentType: 'text/plain' });
const metadata = new RepresentationMetadata({ [CONTENT_TYPE]: 'text/plain' });
const representation = { metadata };
const preferences = { type: { 'application/json': 1 }};
@@ -31,7 +32,7 @@ describe('A ContentTypeReplacer', (): void => {
});
it('throws on an unsupported output type.', async(): Promise<void> => {
const metadata = new RepresentationMetadata({ contentType: 'application/n-triples' });
const metadata = new RepresentationMetadata({ [CONTENT_TYPE]: 'application/n-triples' });
const representation = { metadata };
const preferences = { type: { 'application/json': 1 }};
@@ -51,7 +52,7 @@ describe('A ContentTypeReplacer', (): void => {
});
it('replaces a supported content type when no preferences are given.', async(): Promise<void> => {
const metadata = new RepresentationMetadata({ contentType: 'application/n-triples' });
const metadata = new RepresentationMetadata({ [CONTENT_TYPE]: 'application/n-triples' });
const representation = { binary, data, metadata };
const preferences = {};
@@ -62,7 +63,7 @@ describe('A ContentTypeReplacer', (): void => {
});
it('replaces a supported content type when preferences are given.', async(): Promise<void> => {
const metadata = new RepresentationMetadata({ contentType: 'application/n-triples' });
const metadata = new RepresentationMetadata({ [CONTENT_TYPE]: 'application/n-triples' });
const representation = { binary, data, metadata };
const preferences = { type: { 'application/n-quads': 1 }};
@@ -73,7 +74,7 @@ describe('A ContentTypeReplacer', (): void => {
});
it('replaces a supported wildcard type.', async(): Promise<void> => {
const metadata = new RepresentationMetadata({ contentType: 'text/plain' });
const metadata = new RepresentationMetadata({ [CONTENT_TYPE]: 'text/plain' });
const representation = { binary, data, metadata };
const preferences = { type: { 'application/octet-stream': 1 }};
@@ -84,7 +85,7 @@ describe('A ContentTypeReplacer', (): void => {
});
it('picks the most preferred content type.', async(): Promise<void> => {
const metadata = new RepresentationMetadata({ contentType: 'application/n-triples' });
const metadata = new RepresentationMetadata({ [CONTENT_TYPE]: 'application/n-triples' });
const representation = { binary, data, metadata };
const preferences = { type: {
'text/turtle': 0.5,