mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
refactor: Enable stricter test linting
This commit is contained in:
@@ -26,7 +26,7 @@ describe('An RdfValidator', (): void => {
|
||||
});
|
||||
|
||||
it('validates data by running it through a converter.', async(): Promise<void> => {
|
||||
converter.handleSafe = jest.fn().mockResolvedValue(new BasicRepresentation('transformedData', 'wrong/type'));
|
||||
jest.spyOn(converter, 'handleSafe').mockResolvedValue(new BasicRepresentation('transformedData', 'wrong/type'));
|
||||
const representation = new BasicRepresentation('data', 'content/type');
|
||||
const quads = representation.metadata.quads();
|
||||
// Output is not important for this Validator
|
||||
@@ -38,7 +38,7 @@ describe('An RdfValidator', (): void => {
|
||||
});
|
||||
|
||||
it('throws an error when validating invalid data.', async(): Promise<void> => {
|
||||
converter.handleSafe = jest.fn().mockRejectedValue(new Error('bad data!'));
|
||||
jest.spyOn(converter, 'handleSafe').mockRejectedValue(new Error('bad data!'));
|
||||
const representation = new BasicRepresentation('data', 'content/type');
|
||||
await expect(validator.handle({ representation, identifier })).rejects.toThrow('bad data!');
|
||||
// Make sure the data on the readable has not been reset
|
||||
|
||||
@@ -61,8 +61,8 @@ describe('A RoutingAuxiliaryStrategy', (): void => {
|
||||
});
|
||||
|
||||
it('#addMetadata adds the metadata of all sources for the base identifier.', async(): Promise<void> => {
|
||||
sources[0].addMetadata = jest.fn();
|
||||
sources[1].addMetadata = jest.fn();
|
||||
jest.spyOn(sources[0], 'addMetadata').mockImplementation();
|
||||
jest.spyOn(sources[1], 'addMetadata').mockImplementation();
|
||||
const metadata = new RepresentationMetadata(baseId);
|
||||
await expect(strategy.addMetadata(metadata)).resolves.toBeUndefined();
|
||||
expect(sources[0].addMetadata).toHaveBeenCalledTimes(1);
|
||||
@@ -72,8 +72,8 @@ describe('A RoutingAuxiliaryStrategy', (): void => {
|
||||
});
|
||||
|
||||
it('#addMetadata adds the metadata of the correct source for auxiliary identifiers.', async(): Promise<void> => {
|
||||
sources[0].addMetadata = jest.fn();
|
||||
sources[1].addMetadata = jest.fn();
|
||||
jest.spyOn(sources[0], 'addMetadata').mockImplementation();
|
||||
jest.spyOn(sources[1], 'addMetadata').mockImplementation();
|
||||
const metadata = new RepresentationMetadata(dummy2Id);
|
||||
await expect(strategy.addMetadata(metadata)).resolves.toBeUndefined();
|
||||
expect(sources[0].addMetadata).toHaveBeenCalledTimes(0);
|
||||
@@ -82,8 +82,8 @@ describe('A RoutingAuxiliaryStrategy', (): void => {
|
||||
});
|
||||
|
||||
it('#usesOwnAuthorization returns the result of the correct source.', async(): Promise<void> => {
|
||||
sources[0].usesOwnAuthorization = jest.fn();
|
||||
sources[1].usesOwnAuthorization = jest.fn();
|
||||
jest.spyOn(sources[0], 'usesOwnAuthorization').mockImplementation();
|
||||
jest.spyOn(sources[1], 'usesOwnAuthorization').mockImplementation();
|
||||
strategy.usesOwnAuthorization(dummy2Id);
|
||||
expect(sources[0].usesOwnAuthorization).toHaveBeenCalledTimes(0);
|
||||
expect(sources[1].usesOwnAuthorization).toHaveBeenCalledTimes(1);
|
||||
@@ -91,8 +91,8 @@ describe('A RoutingAuxiliaryStrategy', (): void => {
|
||||
});
|
||||
|
||||
it('#isRequiredInRoot returns the result of the correct source.', async(): Promise<void> => {
|
||||
sources[0].isRequiredInRoot = jest.fn();
|
||||
sources[1].isRequiredInRoot = jest.fn();
|
||||
jest.spyOn(sources[0], 'isRequiredInRoot').mockImplementation();
|
||||
jest.spyOn(sources[1], 'isRequiredInRoot').mockImplementation();
|
||||
strategy.isRequiredInRoot(dummy2Id);
|
||||
expect(sources[0].isRequiredInRoot).toHaveBeenCalledTimes(0);
|
||||
expect(sources[1].isRequiredInRoot).toHaveBeenCalledTimes(1);
|
||||
@@ -100,8 +100,8 @@ describe('A RoutingAuxiliaryStrategy', (): void => {
|
||||
});
|
||||
|
||||
it('#validates using the correct validator.', async(): Promise<void> => {
|
||||
sources[0].validate = jest.fn();
|
||||
sources[1].validate = jest.fn();
|
||||
jest.spyOn(sources[0], 'validate').mockImplementation();
|
||||
jest.spyOn(sources[1], 'validate').mockImplementation();
|
||||
|
||||
let metadata = new RepresentationMetadata(dummy1Id);
|
||||
await expect(strategy.validate({ metadata } as any)).resolves.toBeUndefined();
|
||||
|
||||
@@ -64,7 +64,7 @@ describe('A SparqlUpdateBodyParser', (): void => {
|
||||
expect(result.binary).toBe(true);
|
||||
expect(result.metadata).toBe(input.metadata);
|
||||
|
||||
expect(await arrayifyStream(result.data)).toEqual(
|
||||
await expect(arrayifyStream(result.data)).resolves.toEqual(
|
||||
[ 'DELETE DATA { <http://test.com/s> <http://test.com/p> <http://test.com/o> }' ],
|
||||
);
|
||||
});
|
||||
@@ -84,7 +84,7 @@ describe('A SparqlUpdateBodyParser', (): void => {
|
||||
expect(result.binary).toBe(true);
|
||||
expect(result.metadata).toBe(input.metadata);
|
||||
|
||||
expect(await arrayifyStream(result.data)).toEqual(
|
||||
await expect(arrayifyStream(result.data)).resolves.toEqual(
|
||||
[ 'INSERT DATA { <#it> <http://test.com/p> <http://test.com/o> }' ],
|
||||
);
|
||||
});
|
||||
|
||||
@@ -9,11 +9,14 @@ describe('A DeleteOperationHandler', (): void => {
|
||||
let operation: Operation;
|
||||
const conditions: Conditions = { matchesMetadata: jest.fn() };
|
||||
const body = new BasicRepresentation();
|
||||
const store = {} as unknown as ResourceStore;
|
||||
const handler = new DeleteOperationHandler(store);
|
||||
let store: jest.Mocked<ResourceStore>;
|
||||
let handler: DeleteOperationHandler;
|
||||
beforeEach(async(): Promise<void> => {
|
||||
operation = { method: 'DELETE', target: { path: 'http://test.com/foo' }, preferences: {}, conditions, body };
|
||||
store.deleteResource = jest.fn(async(): Promise<any> => undefined);
|
||||
store = {
|
||||
deleteResource: jest.fn(async(): Promise<any> => undefined),
|
||||
} as any satisfies ResourceStore;
|
||||
handler = new DeleteOperationHandler(store);
|
||||
});
|
||||
|
||||
it('only supports DELETE operations.', async(): Promise<void> => {
|
||||
|
||||
@@ -48,7 +48,7 @@ describe('BasicRepresentation', (): void => {
|
||||
const data = [ 'my', 'data' ];
|
||||
const metadata = new RepresentationMetadata();
|
||||
const representation = new BasicRepresentation(data, metadata);
|
||||
expect(await arrayifyStream(representation.data)).toEqual(data);
|
||||
await expect(arrayifyStream(representation.data)).resolves.toEqual(data);
|
||||
expect(representation.metadata).toBe(metadata);
|
||||
expect(representation.binary).toBe(true);
|
||||
});
|
||||
@@ -57,7 +57,7 @@ describe('BasicRepresentation', (): void => {
|
||||
const data = 'my data';
|
||||
const metadata = new RepresentationMetadata();
|
||||
const representation = new BasicRepresentation(data, metadata);
|
||||
expect(await arrayifyStream(representation.data)).toEqual([ data ]);
|
||||
await expect(arrayifyStream(representation.data)).resolves.toEqual([ data ]);
|
||||
expect(representation.metadata).toBe(metadata);
|
||||
expect(representation.binary).toBe(true);
|
||||
});
|
||||
|
||||
@@ -303,7 +303,7 @@ describe('A RepresentationMetadata', (): void => {
|
||||
it('errors if a shorthand has multiple values.', async(): Promise<void> => {
|
||||
metadata.add(CONTENT_TYPE_TERM, 'a/b');
|
||||
metadata.add(CONTENT_TYPE_TERM, 'c/d');
|
||||
expect((): any => metadata.contentType).toThrow();
|
||||
expect((): any => metadata.contentType).toThrow('Multiple results for http://www.w3.org/ns/ma-ont#format');
|
||||
});
|
||||
|
||||
it('has a shorthand for Content-Type as string.', async(): Promise<void> => {
|
||||
|
||||
Reference in New Issue
Block a user