feat: Add Content-Type constructor to metadata.

This commit is contained in:
Ruben Verborgh
2021-01-10 21:31:55 +01:00
parent 775aaa79cd
commit be1af89b56
18 changed files with 67 additions and 47 deletions

View File

@@ -9,7 +9,6 @@ import { RepresentationMetadata } from '../../../../src/ldp/representation/Repre
import { INTERNAL_QUADS } from '../../../../src/util/ContentTypes';
import { NotImplementedHttpError } from '../../../../src/util/errors/NotImplementedHttpError';
import { guardedStreamFrom } from '../../../../src/util/StreamUtil';
import { CONTENT_TYPE } from '../../../../src/util/Vocabularies';
import { StaticAsyncHandler } from '../../../util/StaticAsyncHandler';
describe('A BasicResponseWriter', (): void => {
@@ -28,7 +27,7 @@ describe('A BasicResponseWriter', (): void => {
it('requires the input to be a binary ResponseDescription.', async(): Promise<void> => {
await expect(writer.canHandle({ response, result: new Error('error') }))
.rejects.toThrow(NotImplementedHttpError);
const metadata = new RepresentationMetadata({ [CONTENT_TYPE]: INTERNAL_QUADS });
const metadata = new RepresentationMetadata(INTERNAL_QUADS);
await expect(writer.canHandle({ response, result: { statusCode: 201, metadata }}))
.rejects.toThrow(NotImplementedHttpError);
await expect(writer.canHandle({ response, result }))

View File

@@ -27,11 +27,22 @@ describe('A RepresentationMetadata', (): void => {
expect(metadata.identifier).toEqualRdfTerm(namedNode('identifier'));
});
it('converts identifier strings to named nodes.', async(): Promise<void> => {
it('converts identifiers to named nodes.', async(): Promise<void> => {
metadata = new RepresentationMetadata({ path: 'identifier' });
expect(metadata.identifier).toEqualRdfTerm(namedNode('identifier'));
});
it('converts string to content type.', async(): Promise<void> => {
metadata = new RepresentationMetadata('text/turtle');
expect(metadata.contentType).toEqual('text/turtle');
metadata = new RepresentationMetadata({ path: 'identifier' }, 'text/turtle');
expect(metadata.contentType).toEqual('text/turtle');
metadata = new RepresentationMetadata(new RepresentationMetadata(), 'text/turtle');
expect(metadata.contentType).toEqual('text/turtle');
});
it('copies an other metadata object.', async(): Promise<void> => {
const other = new RepresentationMetadata({ path: 'otherId' }, { 'test:pred': 'objVal' });
metadata = new RepresentationMetadata(other);