mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
fix: Enable strict TypeScript settings
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import { Lock } from '../../../src/storage/Lock';
|
||||
import { LockingResourceStore } from '../../../src/storage/LockingResourceStore';
|
||||
import { Patch } from '../../../src/ldp/http/Patch';
|
||||
import { Representation } from '../../../src/ldp/representation/Representation';
|
||||
import { ResourceLocker } from '../../../src/storage/ResourceLocker';
|
||||
import { ResourceStore } from '../../../src/storage/ResourceStore';
|
||||
|
||||
@@ -40,7 +42,7 @@ describe('A LockingResourceStore', (): void => {
|
||||
});
|
||||
|
||||
it('acquires a lock on the resource when getting it.', async(): Promise<void> => {
|
||||
await store.getRepresentation({ path: 'path' }, null);
|
||||
await store.getRepresentation({ path: 'path' }, {});
|
||||
expect(locker.acquire).toHaveBeenCalledTimes(1);
|
||||
expect(locker.acquire).toHaveBeenLastCalledWith({ path: 'path' });
|
||||
expect(source.getRepresentation).toHaveBeenCalledTimes(1);
|
||||
@@ -49,7 +51,7 @@ describe('A LockingResourceStore', (): void => {
|
||||
});
|
||||
|
||||
it('acquires a lock on the container when adding a representation.', async(): Promise<void> => {
|
||||
await store.addResource({ path: 'path' }, null);
|
||||
await store.addResource({ path: 'path' }, {} as Representation);
|
||||
expect(locker.acquire).toHaveBeenCalledTimes(1);
|
||||
expect(locker.acquire).toHaveBeenLastCalledWith({ path: 'path' });
|
||||
expect(source.addResource).toHaveBeenCalledTimes(1);
|
||||
@@ -58,7 +60,7 @@ describe('A LockingResourceStore', (): void => {
|
||||
});
|
||||
|
||||
it('acquires a lock on the resource when setting its representation.', async(): Promise<void> => {
|
||||
await store.setRepresentation({ path: 'path' }, null);
|
||||
await store.setRepresentation({ path: 'path' }, {} as Representation);
|
||||
expect(locker.acquire).toHaveBeenCalledTimes(1);
|
||||
expect(locker.acquire).toHaveBeenLastCalledWith({ path: 'path' });
|
||||
expect(source.setRepresentation).toHaveBeenCalledTimes(1);
|
||||
@@ -76,7 +78,7 @@ describe('A LockingResourceStore', (): void => {
|
||||
});
|
||||
|
||||
it('acquires a lock on the resource when modifying its representation.', async(): Promise<void> => {
|
||||
await store.modifyResource({ path: 'path' }, null);
|
||||
await store.modifyResource({ path: 'path' }, {} as Patch);
|
||||
expect(locker.acquire).toHaveBeenCalledTimes(1);
|
||||
expect(locker.acquire).toHaveBeenLastCalledWith({ path: 'path' });
|
||||
expect(source.modifyResource).toHaveBeenCalledTimes(1);
|
||||
@@ -88,7 +90,7 @@ describe('A LockingResourceStore', (): void => {
|
||||
source.getRepresentation = async(): Promise<any> => {
|
||||
throw new Error('dummy');
|
||||
};
|
||||
await expect(store.getRepresentation({ path: 'path' }, null)).rejects.toThrow('dummy');
|
||||
await expect(store.getRepresentation({ path: 'path' }, {})).rejects.toThrow('dummy');
|
||||
expect(locker.acquire).toHaveBeenCalledTimes(1);
|
||||
expect(locker.acquire).toHaveBeenLastCalledWith({ path: 'path' });
|
||||
expect(lock.release).toHaveBeenCalledTimes(1);
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import { Patch } from '../../../src/ldp/http/Patch';
|
||||
import { PatchHandler } from '../../../src/storage/patch/PatchHandler';
|
||||
import { PatchingStore } from '../../../src/storage/PatchingStore';
|
||||
import { Representation } from '../../../src/ldp/representation/Representation';
|
||||
import { ResourceStore } from '../../../src/storage/ResourceStore';
|
||||
|
||||
describe('A PatchingStore', (): void => {
|
||||
@@ -24,44 +26,44 @@ describe('A PatchingStore', (): void => {
|
||||
});
|
||||
|
||||
it('calls getRepresentation directly from the source.', async(): Promise<void> => {
|
||||
await expect(store.getRepresentation({ path: 'getPath' }, null)).resolves.toBe('get');
|
||||
await expect(store.getRepresentation({ path: 'getPath' }, {})).resolves.toBe('get');
|
||||
expect(source.getRepresentation).toHaveBeenCalledTimes(1);
|
||||
expect(source.getRepresentation).toHaveBeenLastCalledWith({ path: 'getPath' }, null, undefined);
|
||||
expect(source.getRepresentation).toHaveBeenLastCalledWith({ path: 'getPath' }, {}, undefined);
|
||||
});
|
||||
|
||||
it('calls addResource directly from the source.', async(): Promise<void> => {
|
||||
await expect(store.addResource({ path: 'addPath' }, null)).resolves.toBe('add');
|
||||
await expect(store.addResource({ path: 'addPath' }, {} as Representation)).resolves.toBe('add');
|
||||
expect(source.addResource).toHaveBeenCalledTimes(1);
|
||||
expect(source.addResource).toHaveBeenLastCalledWith({ path: 'addPath' }, null, undefined);
|
||||
expect(source.addResource).toHaveBeenLastCalledWith({ path: 'addPath' }, {}, undefined);
|
||||
});
|
||||
|
||||
it('calls setRepresentation directly from the source.', async(): Promise<void> => {
|
||||
await expect(store.setRepresentation({ path: 'setPath' }, null)).resolves.toBe('set');
|
||||
await expect(store.setRepresentation({ path: 'setPath' }, {} as Representation)).resolves.toBe('set');
|
||||
expect(source.setRepresentation).toHaveBeenCalledTimes(1);
|
||||
expect(source.setRepresentation).toHaveBeenLastCalledWith({ path: 'setPath' }, null, undefined);
|
||||
expect(source.setRepresentation).toHaveBeenLastCalledWith({ path: 'setPath' }, {}, undefined);
|
||||
});
|
||||
|
||||
it('calls deleteResource directly from the source.', async(): Promise<void> => {
|
||||
await expect(store.deleteResource({ path: 'deletePath' }, null)).resolves.toBe('delete');
|
||||
await expect(store.deleteResource({ path: 'deletePath' })).resolves.toBe('delete');
|
||||
expect(source.deleteResource).toHaveBeenCalledTimes(1);
|
||||
expect(source.deleteResource).toHaveBeenLastCalledWith({ path: 'deletePath' }, null);
|
||||
expect(source.deleteResource).toHaveBeenLastCalledWith({ path: 'deletePath' }, undefined);
|
||||
});
|
||||
|
||||
it('calls modifyResource directly from the source if available.', async(): Promise<void> => {
|
||||
await expect(store.modifyResource({ path: 'modifyPath' }, null)).resolves.toBe('modify');
|
||||
await expect(store.modifyResource({ path: 'modifyPath' }, {} as Patch)).resolves.toBe('modify');
|
||||
expect(source.modifyResource).toHaveBeenCalledTimes(1);
|
||||
expect(source.modifyResource).toHaveBeenLastCalledWith({ path: 'modifyPath' }, null, undefined);
|
||||
expect(source.modifyResource).toHaveBeenLastCalledWith({ path: 'modifyPath' }, {}, undefined);
|
||||
});
|
||||
|
||||
it('calls its patcher if modifyResource failed.', async(): Promise<void> => {
|
||||
source.modifyResource = jest.fn(async(): Promise<any> => {
|
||||
throw new Error('dummy');
|
||||
});
|
||||
await expect(store.modifyResource({ path: 'modifyPath' }, null)).resolves.toBe('patcher');
|
||||
await expect(store.modifyResource({ path: 'modifyPath' }, {} as Patch)).resolves.toBe('patcher');
|
||||
expect(source.modifyResource).toHaveBeenCalledTimes(1);
|
||||
expect(source.modifyResource).toHaveBeenLastCalledWith({ path: 'modifyPath' }, null, undefined);
|
||||
expect(source.modifyResource).toHaveBeenLastCalledWith({ path: 'modifyPath' }, {}, undefined);
|
||||
await expect((source.modifyResource as jest.Mock).mock.results[0].value).rejects.toThrow('dummy');
|
||||
expect(handleSafeFn).toHaveBeenCalledTimes(1);
|
||||
expect(handleSafeFn).toHaveBeenLastCalledWith({ identifier: { path: 'modifyPath' }, patch: null });
|
||||
expect(handleSafeFn).toHaveBeenLastCalledWith({ identifier: { path: 'modifyPath' }, patch: {}});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -2,6 +2,7 @@ import arrayifyStream from 'arrayify-stream';
|
||||
import { NotFoundHttpError } from '../../../src/util/errors/NotFoundHttpError';
|
||||
import { QuadRepresentation } from '../../../src/ldp/representation/QuadRepresentation';
|
||||
import { Readable } from 'stream';
|
||||
import { RepresentationMetadata } from '../../../src/ldp/representation/RepresentationMetadata';
|
||||
import { SimpleResourceStore } from '../../../src/storage/SimpleResourceStore';
|
||||
import streamifyArray from 'streamify-array';
|
||||
import { UnsupportedMediaTypeHttpError } from '../../../src/util/errors/UnsupportedMediaTypeHttpError';
|
||||
@@ -24,15 +25,15 @@ describe('A SimpleResourceStore', (): void => {
|
||||
representation = {
|
||||
data: streamifyArray([ quad ]),
|
||||
dataType: 'quad',
|
||||
metadata: null,
|
||||
metadata: {} as RepresentationMetadata,
|
||||
};
|
||||
});
|
||||
|
||||
it('errors if a resource was not found.', async(): Promise<void> => {
|
||||
await expect(store.getRepresentation({ path: `${base}wrong` }, {})).rejects.toThrow(NotFoundHttpError);
|
||||
await expect(store.addResource({ path: 'http://wrong.com/wrong' }, null)).rejects.toThrow(NotFoundHttpError);
|
||||
await expect(store.addResource({ path: 'http://wrong.com/wrong' }, representation)).rejects.toThrow(NotFoundHttpError);
|
||||
await expect(store.deleteResource({ path: 'wrong' })).rejects.toThrow(NotFoundHttpError);
|
||||
await expect(store.setRepresentation({ path: 'http://wrong.com/' }, null)).rejects.toThrow(NotFoundHttpError);
|
||||
await expect(store.setRepresentation({ path: 'http://wrong.com/' }, representation)).rejects.toThrow(NotFoundHttpError);
|
||||
});
|
||||
|
||||
it('errors when modifying resources.', async(): Promise<void> => {
|
||||
|
||||
@@ -41,15 +41,13 @@ describe('A SimpleSparqlUpdatePatchHandler', (): void => {
|
||||
metadata: null,
|
||||
};
|
||||
}),
|
||||
addResource: null,
|
||||
setRepresentation: jest.fn(async(): Promise<any> => {
|
||||
order.push('setRepresentation');
|
||||
}),
|
||||
deleteResource: null,
|
||||
modifyResource: jest.fn(async(): Promise<any> => {
|
||||
throw new Error('noModify');
|
||||
}),
|
||||
};
|
||||
} as unknown as ResourceStore;
|
||||
|
||||
release = jest.fn(async(): Promise<any> => order.push('release'));
|
||||
locker = {
|
||||
|
||||
Reference in New Issue
Block a user