mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
committed by
Joachim Van Herwegen
parent
236bbc6e5d
commit
5989a1fdc5
14
package-lock.json
generated
14
package-lock.json
generated
@@ -87,7 +87,7 @@
|
||||
"@typescript-eslint/eslint-plugin": "^5.3.0",
|
||||
"@typescript-eslint/parser": "^5.3.0",
|
||||
"cheerio": "^1.0.0-rc.10",
|
||||
"componentsjs-generator": "^3.0.2",
|
||||
"componentsjs-generator": "^3.0.3",
|
||||
"eslint": "^8.8.0",
|
||||
"eslint-config-es": "4.1.0",
|
||||
"eslint-import-resolver-typescript": "^2.5.0",
|
||||
@@ -5906,9 +5906,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/componentsjs-generator": {
|
||||
"version": "3.0.2",
|
||||
"resolved": "https://registry.npmjs.org/componentsjs-generator/-/componentsjs-generator-3.0.2.tgz",
|
||||
"integrity": "sha512-r0u4PJD6oEAmjSX920JZndA5/mb7s4UbwSf1awisEXs5s4zTp0jiOhNG3z6p5lvAHBTZHwIPf83b4yWUU/9TYA==",
|
||||
"version": "3.0.3",
|
||||
"resolved": "https://registry.npmjs.org/componentsjs-generator/-/componentsjs-generator-3.0.3.tgz",
|
||||
"integrity": "sha512-Pv4+tnwAWjOkUpwt6SoD8DWfBdGfxhaqAK3zRvZIgrbPFo4V4bZpXgN8MBYXm1InRGYQeHdNUTGdXYZw0L8GjA==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"@types/lru-cache": "^5.1.0",
|
||||
@@ -19763,9 +19763,9 @@
|
||||
}
|
||||
},
|
||||
"componentsjs-generator": {
|
||||
"version": "3.0.2",
|
||||
"resolved": "https://registry.npmjs.org/componentsjs-generator/-/componentsjs-generator-3.0.2.tgz",
|
||||
"integrity": "sha512-r0u4PJD6oEAmjSX920JZndA5/mb7s4UbwSf1awisEXs5s4zTp0jiOhNG3z6p5lvAHBTZHwIPf83b4yWUU/9TYA==",
|
||||
"version": "3.0.3",
|
||||
"resolved": "https://registry.npmjs.org/componentsjs-generator/-/componentsjs-generator-3.0.3.tgz",
|
||||
"integrity": "sha512-Pv4+tnwAWjOkUpwt6SoD8DWfBdGfxhaqAK3zRvZIgrbPFo4V4bZpXgN8MBYXm1InRGYQeHdNUTGdXYZw0L8GjA==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@types/lru-cache": "^5.1.0",
|
||||
|
||||
@@ -151,7 +151,7 @@
|
||||
"@typescript-eslint/eslint-plugin": "^5.3.0",
|
||||
"@typescript-eslint/parser": "^5.3.0",
|
||||
"cheerio": "^1.0.0-rc.10",
|
||||
"componentsjs-generator": "^3.0.2",
|
||||
"componentsjs-generator": "^3.0.3",
|
||||
"eslint": "^8.8.0",
|
||||
"eslint-config-es": "4.1.0",
|
||||
"eslint-import-resolver-typescript": "^2.5.0",
|
||||
|
||||
@@ -23,9 +23,9 @@ export class ConvertingRouterRule extends RouterRule {
|
||||
private readonly typedStores: ConvertingStoreEntry[];
|
||||
private readonly defaultStore: ResourceStore;
|
||||
|
||||
public constructor(typedStore: ConvertingStoreEntry, defaultStore: ResourceStore) {
|
||||
public constructor(typedStores: ConvertingStoreEntry[], defaultStore: ResourceStore) {
|
||||
super();
|
||||
this.typedStores = [ typedStore ];
|
||||
this.typedStores = typedStores;
|
||||
this.defaultStore = defaultStore;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user