mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
feat: Add Content-Type constructor to metadata.
This commit is contained in:
@@ -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 }))
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -14,7 +14,7 @@ describe('A RepresentationConvertingStore', (): void => {
|
||||
const convertedIn = { metadata: {}};
|
||||
const convertedOut = { metadata: {}};
|
||||
const inType = 'text/turtle';
|
||||
const metadata = new RepresentationMetadata({ [CONTENT_TYPE]: 'text/turtle' });
|
||||
const metadata = new RepresentationMetadata('text/turtle');
|
||||
let representation: Representation;
|
||||
|
||||
beforeEach(async(): Promise<void> => {
|
||||
|
||||
@@ -32,7 +32,7 @@ describe('A FileDataAccessor', (): void => {
|
||||
cache = mockFs(rootFilePath, now);
|
||||
accessor = new FileDataAccessor(new ExtensionBasedMapper(base, rootFilePath));
|
||||
|
||||
metadata = new RepresentationMetadata({ [CONTENT_TYPE]: APPLICATION_OCTET_STREAM });
|
||||
metadata = new RepresentationMetadata(APPLICATION_OCTET_STREAM);
|
||||
|
||||
data = guardedStreamFrom([ 'data' ]);
|
||||
});
|
||||
|
||||
@@ -7,7 +7,7 @@ import { APPLICATION_OCTET_STREAM } from '../../../../src/util/ContentTypes';
|
||||
import { NotFoundHttpError } from '../../../../src/util/errors/NotFoundHttpError';
|
||||
import type { Guarded } from '../../../../src/util/GuardedStream';
|
||||
import { guardedStreamFrom, readableToString } from '../../../../src/util/StreamUtil';
|
||||
import { CONTENT_TYPE, LDP, RDF } from '../../../../src/util/Vocabularies';
|
||||
import { LDP, RDF } from '../../../../src/util/Vocabularies';
|
||||
|
||||
describe('An InMemoryDataAccessor', (): void => {
|
||||
const base = 'http://test.com/';
|
||||
@@ -21,7 +21,7 @@ describe('An InMemoryDataAccessor', (): void => {
|
||||
// Create default root container
|
||||
await accessor.writeContainer({ path: `${base}` }, new RepresentationMetadata());
|
||||
|
||||
metadata = new RepresentationMetadata({ [CONTENT_TYPE]: APPLICATION_OCTET_STREAM });
|
||||
metadata = new RepresentationMetadata(APPLICATION_OCTET_STREAM);
|
||||
|
||||
data = guardedStreamFrom([ 'data' ]);
|
||||
});
|
||||
|
||||
@@ -49,7 +49,7 @@ describe('A ChainedConverter', (): void => {
|
||||
];
|
||||
converter = new ChainedConverter(converters);
|
||||
|
||||
const metadata = new RepresentationMetadata({ [CONTENT_TYPE]: 'text/turtle' });
|
||||
const metadata = new RepresentationMetadata('text/turtle');
|
||||
representation = { metadata } as Representation;
|
||||
preferences = { type: { 'internal/quads': 1 }};
|
||||
args = { representation, preferences, identifier: { path: 'path' }};
|
||||
|
||||
@@ -8,7 +8,7 @@ import type { RepresentationPreferences } from '../../../../src/ldp/representati
|
||||
import type { ResourceIdentifier } from '../../../../src/ldp/representation/ResourceIdentifier';
|
||||
import { QuadToRdfConverter } from '../../../../src/storage/conversion/QuadToRdfConverter';
|
||||
import { INTERNAL_QUADS } from '../../../../src/util/ContentTypes';
|
||||
import { CONTENT_TYPE, DC, PREFERRED_PREFIX_TERM } from '../../../../src/util/Vocabularies';
|
||||
import { DC, PREFERRED_PREFIX_TERM } from '../../../../src/util/Vocabularies';
|
||||
|
||||
describe('A QuadToRdfConverter', (): void => {
|
||||
const converter = new QuadToRdfConverter();
|
||||
@@ -16,7 +16,7 @@ describe('A QuadToRdfConverter', (): void => {
|
||||
let metadata: RepresentationMetadata;
|
||||
|
||||
beforeEach((): void => {
|
||||
metadata = new RepresentationMetadata({ [CONTENT_TYPE]: INTERNAL_QUADS });
|
||||
metadata = new RepresentationMetadata(INTERNAL_QUADS);
|
||||
});
|
||||
|
||||
it('supports parsing quads.', async(): Promise<void> => {
|
||||
|
||||
@@ -11,7 +11,6 @@ import type { ResourceIdentifier } from '../../../../src/ldp/representation/Reso
|
||||
import { RdfToQuadConverter } from '../../../../src/storage/conversion/RdfToQuadConverter';
|
||||
import { INTERNAL_QUADS } from '../../../../src/util/ContentTypes';
|
||||
import { BadRequestHttpError } from '../../../../src/util/errors/BadRequestHttpError';
|
||||
import { CONTENT_TYPE } from '../../../../src/util/Vocabularies';
|
||||
|
||||
describe('A RdfToQuadConverter', (): void => {
|
||||
const converter = new RdfToQuadConverter();
|
||||
@@ -26,21 +25,21 @@ describe('A RdfToQuadConverter', (): void => {
|
||||
});
|
||||
|
||||
it('can handle turtle to quad conversions.', async(): Promise<void> => {
|
||||
const metadata = new RepresentationMetadata({ [CONTENT_TYPE]: 'text/turtle' });
|
||||
const metadata = new RepresentationMetadata('text/turtle');
|
||||
const representation = { metadata } as Representation;
|
||||
const preferences: RepresentationPreferences = { type: { [INTERNAL_QUADS]: 1 }};
|
||||
await expect(converter.canHandle({ identifier, representation, preferences })).resolves.toBeUndefined();
|
||||
});
|
||||
|
||||
it('can handle JSON-LD to quad conversions.', async(): Promise<void> => {
|
||||
const metadata = new RepresentationMetadata({ [CONTENT_TYPE]: 'application/ld+json' });
|
||||
const metadata = new RepresentationMetadata('application/ld+json');
|
||||
const representation = { metadata } as Representation;
|
||||
const preferences: RepresentationPreferences = { type: { [INTERNAL_QUADS]: 1 }};
|
||||
await expect(converter.canHandle({ identifier, representation, preferences })).resolves.toBeUndefined();
|
||||
});
|
||||
|
||||
it('converts turtle to quads.', async(): Promise<void> => {
|
||||
const metadata = new RepresentationMetadata({ [CONTENT_TYPE]: 'text/turtle' });
|
||||
const metadata = new RepresentationMetadata('text/turtle');
|
||||
const representation = {
|
||||
data: streamifyArray([ '<http://test.com/s> <http://test.com/p> <http://test.com/o>.' ]),
|
||||
metadata,
|
||||
@@ -61,7 +60,7 @@ describe('A RdfToQuadConverter', (): void => {
|
||||
});
|
||||
|
||||
it('converts JSON-LD to quads.', async(): Promise<void> => {
|
||||
const metadata = new RepresentationMetadata({ [CONTENT_TYPE]: 'application/ld+json' });
|
||||
const metadata = new RepresentationMetadata('application/ld+json');
|
||||
const representation = {
|
||||
data: streamifyArray([ '{"@id": "http://test.com/s", "http://test.com/p": { "@id": "http://test.com/o" }}' ]),
|
||||
metadata,
|
||||
@@ -82,7 +81,7 @@ describe('A RdfToQuadConverter', (): void => {
|
||||
});
|
||||
|
||||
it('throws an BadRequestHttpError on invalid triple data.', async(): Promise<void> => {
|
||||
const metadata = new RepresentationMetadata({ [CONTENT_TYPE]: 'text/turtle' });
|
||||
const metadata = new RepresentationMetadata('text/turtle');
|
||||
const representation = {
|
||||
data: streamifyArray([ '<http://test.com/s> <http://test.com/p> <http://test.co' ]),
|
||||
metadata,
|
||||
|
||||
Reference in New Issue
Block a user