fix: revert ef6f01a
This commit is contained in:
Thomas Dupont
2022-05-13 16:00:36 +02:00
committed by Joachim Van Herwegen
parent 236bbc6e5d
commit 5989a1fdc5
4 changed files with 26 additions and 11 deletions

View File

@@ -7,14 +7,17 @@ import { InternalServerError } from '../../../../src/util/errors/InternalServerE
describe('A ConvertingRouterRule', (): void => {
let store1: ResourceStore;
let store2: ResourceStore;
let defaultStore: ResourceStore;
let checker1: PreferenceSupport;
let checker2: PreferenceSupport;
let rule: ConvertingRouterRule;
let representation: Representation;
let metadata: RepresentationMetadata;
beforeEach(async(): Promise<void> => {
store1 = { name: 'turtleStore' } as any;
store2 = { name: 'textStore' } as any;
defaultStore = { name: 'defaultStore' } as any;
checker1 = {
@@ -23,7 +26,16 @@ describe('A ConvertingRouterRule', (): void => {
},
} as any;
rule = new ConvertingRouterRule({ store: store1, supportChecker: checker1 }, defaultStore);
checker2 = {
async supports(input: { representation: Representation }): Promise<boolean> {
return input.representation.metadata.contentType === 'application/ld+json';
},
} as any;
rule = new ConvertingRouterRule([
{ store: store1, supportChecker: checker1 },
{ store: store2, supportChecker: checker2 },
], defaultStore);
metadata = new RepresentationMetadata();
representation = { binary: true, data: 'data!' as any, metadata, isEmpty: false };
@@ -32,6 +44,8 @@ describe('A ConvertingRouterRule', (): void => {
it('returns the corresponding store if it supports the input.', async(): Promise<void> => {
metadata.contentType = 'text/turtle';
await expect(rule.handle({ identifier: { path: 'identifier' }, representation })).resolves.toBe(store1);
metadata.contentType = 'application/ld+json';
await expect(rule.handle({ identifier: { path: 'identifier' }, representation })).resolves.toBe(store2);
});
it('returns the defaultStore if the converter does not support the input.', async(): Promise<void> => {
@@ -46,6 +60,7 @@ describe('A ConvertingRouterRule', (): void => {
it('returns the defaultStore if no other store has the resource.', async(): Promise<void> => {
store1.hasResource = jest.fn().mockImplementationOnce((): any => false);
store2.hasResource = jest.fn().mockImplementationOnce((): any => false);
await expect(rule.handle({ identifier: { path: 'identifier' }})).resolves.toBe(defaultStore);
});