mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
feat: Added resourceExists method to ResourceStore
* feat: added resourceExists method to ResourceStore * Merge remote-tracking branch 'origin/main' into feat/add-resourceExists-method-to-ResourceStore * fix: adapted to review * fix: adapted to review
This commit is contained in:
committed by
GitHub
parent
e5b7d99da4
commit
b3f292d718
@@ -1,11 +1,9 @@
|
||||
import type { Readable } from 'stream';
|
||||
import type { Representation } from '../../../../src/ldp/representation/Representation';
|
||||
import { RepresentationMetadata } from '../../../../src/ldp/representation/RepresentationMetadata';
|
||||
import type { ResourceStore } from '../../../../src/storage/ResourceStore';
|
||||
import { ConvertingRouterRule } from '../../../../src/storage/routing/ConvertingRouterRule';
|
||||
import type { PreferenceSupport } from '../../../../src/storage/routing/PreferenceSupport';
|
||||
import { InternalServerError } from '../../../../src/util/errors/InternalServerError';
|
||||
import { NotFoundHttpError } from '../../../../src/util/errors/NotFoundHttpError';
|
||||
|
||||
describe('A ConvertingRouterRule', (): void => {
|
||||
let store1: ResourceStore;
|
||||
@@ -41,23 +39,18 @@ describe('A ConvertingRouterRule', (): void => {
|
||||
});
|
||||
|
||||
it('checks if the stores contain the identifier if there is no data.', async(): Promise<void> => {
|
||||
const data: Readable = { destroy: jest.fn() } as any;
|
||||
store1.getRepresentation = async(): Promise<Representation> => ({ data } as any);
|
||||
store1.resourceExists = jest.fn().mockImplementationOnce((): any => true);
|
||||
await expect(rule.handle({ identifier: { path: 'identifier' }})).resolves.toBe(store1);
|
||||
expect(data.destroy).toHaveBeenCalledTimes(1);
|
||||
expect(store1.resourceExists).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('returns the defaultStore if no other store has the resource.', async(): Promise<void> => {
|
||||
store1.getRepresentation = (): any => {
|
||||
throw new NotFoundHttpError();
|
||||
};
|
||||
store1.resourceExists = jest.fn().mockImplementationOnce((): any => false);
|
||||
await expect(rule.handle({ identifier: { path: 'identifier' }})).resolves.toBe(defaultStore);
|
||||
});
|
||||
|
||||
it('throws the error if a store had a non-404 error.', async(): Promise<void> => {
|
||||
store1.getRepresentation = (): any => {
|
||||
throw new InternalServerError();
|
||||
};
|
||||
store1.resourceExists = jest.fn().mockRejectedValueOnce(new InternalServerError());
|
||||
await expect(rule.handle({ identifier: { path: 'identifier' }})).rejects.toThrow(InternalServerError);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user