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

@@ -1,14 +1,13 @@
import 'jest-rdf';
import { DataFactory } from 'n3';
import {
toCachedNamedNode,
toNamedTerm,
toPredicateTerm,
toObjectTerm,
toLiteral,
isTerm,
} from '../../../src/util/TermUtil';
import { CONTENT_TYPE_TERM, XSD } from '../../../src/util/Vocabularies';
import { XSD } from '../../../src/util/Vocabularies';
const { literal, namedNode } = DataFactory;
describe('TermUtil', (): void => {
@@ -22,27 +21,6 @@ describe('TermUtil', (): void => {
});
});
describe('toCachedNamedNode function', (): void => {
it('returns the input if it was a named node.', async(): Promise<void> => {
const term = namedNode('name');
expect(toCachedNamedNode(term)).toBe(term);
});
it('returns a named node when a string is used.', async(): Promise<void> => {
expect(toCachedNamedNode('name')).toEqualRdfTerm(namedNode('name'));
});
it('caches generated named nodes.', async(): Promise<void> => {
const result = toCachedNamedNode('name');
expect(result).toEqualRdfTerm(namedNode('name'));
expect(toCachedNamedNode('name')).toBe(result);
});
it('supports URI shorthands.', async(): Promise<void> => {
expect(toCachedNamedNode('contentType')).toEqualRdfTerm(CONTENT_TYPE_TERM);
});
});
describe('toSubjectTerm function', (): void => {
it('returns the input if it was a term.', async(): Promise<void> => {
const nn = namedNode('name');