feat: Support content negotiation for IDP requests

This commit is contained in:
Joachim Van Herwegen
2021-08-10 15:55:49 +02:00
parent 7b42c72142
commit 80ebd02cc4
20 changed files with 483 additions and 209 deletions

View File

@@ -1,10 +1,10 @@
import 'jest-rdf';
import type { Literal } from 'n3';
import type { NamedNode, Literal } from 'n3';
import { BasicRepresentation } from '../../../src/ldp/representation/BasicRepresentation';
import type { Representation } from '../../../src/ldp/representation/Representation';
import { RepresentationMetadata } from '../../../src/ldp/representation/RepresentationMetadata';
import { cloneRepresentation, updateModifiedDate } from '../../../src/util/ResourceUtil';
import { DC, XSD } from '../../../src/util/Vocabularies';
import { addTemplateMetadata, cloneRepresentation, updateModifiedDate } from '../../../src/util/ResourceUtil';
import { CONTENT_TYPE_TERM, DC, SOLID_META, XSD } from '../../../src/util/Vocabularies';
describe('ResourceUtil', (): void => {
let representation: Representation;
@@ -30,6 +30,21 @@ describe('ResourceUtil', (): void => {
});
});
describe('#addTemplateMetadata', (): void => {
const filePath = '/templates/template.html.ejs';
const contentType = 'text/html';
it('stores the template metadata.', (): void => {
const metadata = new RepresentationMetadata();
addTemplateMetadata(metadata, filePath, contentType);
const templateNode = metadata.get(SOLID_META.terms.template);
expect(templateNode?.value).toBe(filePath);
const quads = metadata.quads(templateNode as NamedNode, CONTENT_TYPE_TERM);
expect(quads).toHaveLength(1);
expect(quads[0].object.value).toBe(contentType);
});
});
describe('#cloneRepresentation', (): void => {
it('returns a clone of the passed representation.', async(): Promise<void> => {
const res = await cloneRepresentation(representation);