mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
chore: Update eslint-plugin-jest dependency
This commit is contained in:
@@ -48,9 +48,11 @@ describe('A ConvertingErrorHandler', (): void => {
|
||||
({ stack } = error);
|
||||
converter = {
|
||||
canHandle: jest.fn(),
|
||||
handle: jest.fn((): Representation => new BasicRepresentation('serialization', 'text/turtle', true)),
|
||||
handleSafe: jest.fn((): Representation => new BasicRepresentation('serialization', 'text/turtle', true)),
|
||||
} as any;
|
||||
handle: jest.fn(async(): Promise<Representation> =>
|
||||
new BasicRepresentation('serialization', 'text/turtle', true)),
|
||||
handleSafe: jest.fn(async(): Promise<Representation> =>
|
||||
new BasicRepresentation('serialization', 'text/turtle', true)),
|
||||
} satisfies Partial<RepresentationConverter> as any;
|
||||
|
||||
preferenceParser = {
|
||||
canHandle: jest.fn(),
|
||||
@@ -80,7 +82,7 @@ describe('A ConvertingErrorHandler', (): void => {
|
||||
it('accepts input supported by the converter.', async(): Promise<void> => {
|
||||
await expect(handler.canHandle({ error, request })).resolves.toBeUndefined();
|
||||
expect(converter.canHandle).toHaveBeenCalledTimes(1);
|
||||
const args = (converter.canHandle as jest.Mock).mock.calls[0][0] as RepresentationConverterArgs;
|
||||
const args = converter.canHandle.mock.calls[0][0];
|
||||
expect(args.preferences).toBe(preferences);
|
||||
expect(args.representation.metadata.contentType).toBe('internal/error');
|
||||
});
|
||||
@@ -90,7 +92,7 @@ describe('A ConvertingErrorHandler', (): void => {
|
||||
await expect(prom).resolves.toMatchObject({ statusCode: 404 });
|
||||
expect((await prom).metadata?.contentType).toBe('text/turtle');
|
||||
expect(converter.handle).toHaveBeenCalledTimes(1);
|
||||
const args = (converter.handle as jest.Mock).mock.calls[0][0] as RepresentationConverterArgs;
|
||||
const args = converter.handle.mock.calls[0][0];
|
||||
await expectValidArgs(args, stack, cause);
|
||||
});
|
||||
|
||||
@@ -99,7 +101,7 @@ describe('A ConvertingErrorHandler', (): void => {
|
||||
await expect(prom).resolves.toMatchObject({ statusCode: 404 });
|
||||
expect((await prom).metadata?.contentType).toBe('text/turtle');
|
||||
expect(converter.handleSafe).toHaveBeenCalledTimes(1);
|
||||
const args = (converter.handleSafe as jest.Mock).mock.calls[0][0] as RepresentationConverterArgs;
|
||||
const args = converter.handleSafe.mock.calls[0][0];
|
||||
await expectValidArgs(args, stack, cause);
|
||||
});
|
||||
|
||||
@@ -109,7 +111,7 @@ describe('A ConvertingErrorHandler', (): void => {
|
||||
await expect(prom).resolves.toMatchObject({ statusCode: 404 });
|
||||
expect((await prom).metadata?.contentType).toBe('text/turtle');
|
||||
expect(converter.handle).toHaveBeenCalledTimes(1);
|
||||
const args = (converter.handle as jest.Mock).mock.calls[0][0] as RepresentationConverterArgs;
|
||||
const args = converter.handle.mock.calls[0][0];
|
||||
await expectValidArgs(args);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { Readable } from 'node:stream';
|
||||
import { exportJWK, generateKeyPair } from 'jose';
|
||||
import type * as Koa from 'koa';
|
||||
import type { ErrorHandler } from '../../../../src/http/output/error/ErrorHandler';
|
||||
import type { ResponseWriter } from '../../../../src/http/output/ResponseWriter';
|
||||
import { IdentityProviderFactory } from '../../../../src/identity/configuration/IdentityProviderFactory';
|
||||
@@ -305,10 +304,9 @@ describe('An IdentityProviderFactory', (): void => {
|
||||
});
|
||||
|
||||
it('adds middleware to make the OIDC provider think the request wants HTML.', async(): Promise<void> => {
|
||||
const provider = await factory.getProvider() as any;
|
||||
const use = provider.use as jest.Mock<ReturnType<Koa['use']>, Parameters<Koa['use']>>;
|
||||
expect(use).toHaveBeenCalledTimes(1);
|
||||
const middleware = use.mock.calls[0][0];
|
||||
const provider = await factory.getProvider();
|
||||
expect(provider.use).toHaveBeenCalledTimes(1);
|
||||
const middleware = jest.mocked(provider.use).mock.calls[0][0];
|
||||
|
||||
// eslint-disable-next-line jest/unbound-method
|
||||
const oldAccept = ctx.accepts;
|
||||
@@ -321,10 +319,9 @@ describe('An IdentityProviderFactory', (): void => {
|
||||
});
|
||||
|
||||
it('does not modify the context accepts function in other cases.', async(): Promise<void> => {
|
||||
const provider = await factory.getProvider() as any;
|
||||
const use = provider.use as jest.Mock<ReturnType<Koa['use']>, Parameters<Koa['use']>>;
|
||||
expect(use).toHaveBeenCalledTimes(1);
|
||||
const middleware = use.mock.calls[0][0];
|
||||
const provider = await factory.getProvider();
|
||||
expect(provider.use).toHaveBeenCalledTimes(1);
|
||||
const middleware = jest.mocked(provider.use).mock.calls[0][0];
|
||||
|
||||
// eslint-disable-next-line jest/unbound-method
|
||||
const oldAccept = ctx.accepts;
|
||||
|
||||
@@ -97,7 +97,8 @@ describe('InteractionUtil', (): void => {
|
||||
await expect(forgetWebId(provider, oidcInteraction)).resolves.toBeUndefined();
|
||||
expect(provider.Session.find).toHaveBeenCalledTimes(1);
|
||||
expect(provider.Session.find).toHaveBeenLastCalledWith('cookie');
|
||||
const session = await (provider.Session.find as jest.Mock).mock.results[0].value;
|
||||
// eslint-disable-next-line jest/unbound-method
|
||||
const session = await jest.mocked(provider.Session.find).mock.results[0].value;
|
||||
expect(session.accountId).toBeUndefined();
|
||||
expect(session.persist).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
@@ -108,7 +109,8 @@ describe('InteractionUtil', (): void => {
|
||||
await expect(forgetWebId(provider, oidcInteraction)).resolves.toBeUndefined();
|
||||
expect(provider.Grant.find).toHaveBeenCalledTimes(1);
|
||||
expect(provider.Grant.find).toHaveBeenLastCalledWith('grantId');
|
||||
const grant = await (provider.Grant.find as jest.Mock).mock.results[0].value;
|
||||
// eslint-disable-next-line jest/unbound-method
|
||||
const grant = await jest.mocked(provider.Grant.find).mock.results[0].value;
|
||||
expect(grant.destroy).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -68,7 +68,8 @@ describe('A PickWebIdHandler', (): void => {
|
||||
|
||||
expect(store.isLinked).toHaveBeenCalledTimes(1);
|
||||
expect(store.isLinked).toHaveBeenLastCalledWith(webId1, accountId);
|
||||
expect((await (provider.Session.find as jest.Mock).mock.results[0].value).persist).toHaveBeenCalledTimes(1);
|
||||
// eslint-disable-next-line jest/unbound-method
|
||||
expect((await jest.mocked(provider.Session.find).mock.results[0].value).persist).toHaveBeenCalledTimes(1);
|
||||
expect(oidcInteraction.persist).toHaveBeenCalledTimes(1);
|
||||
expect(oidcInteraction.result).toEqual({
|
||||
login: {
|
||||
|
||||
@@ -43,7 +43,7 @@ describe('A TokenOwnershipValidator', (): void => {
|
||||
beforeEach(async(): Promise<void> => {
|
||||
const now = Date.now();
|
||||
jest.spyOn(Date, 'now').mockReturnValue(now);
|
||||
(v4 as jest.Mock).mockReturnValue(token);
|
||||
jest.mocked(v4).mockReturnValue(token);
|
||||
|
||||
const map = new Map<string, any>();
|
||||
storage = {
|
||||
|
||||
@@ -11,7 +11,7 @@ describe('A ClientIdAdapterFactory', (): void => {
|
||||
const id = 'https://app.example.com/card#me';
|
||||
let json: any;
|
||||
let rdf: string;
|
||||
let source: Adapter;
|
||||
let source: jest.Mocked<Adapter>;
|
||||
let sourceFactory: AdapterFactory;
|
||||
let adapter: Adapter;
|
||||
const converter = new RdfToQuadConverter();
|
||||
@@ -53,7 +53,7 @@ describe('A ClientIdAdapterFactory', (): void => {
|
||||
});
|
||||
|
||||
it('returns the source payload if there is one.', async(): Promise<void> => {
|
||||
(source.find as jest.Mock).mockResolvedValueOnce('payload!');
|
||||
source.find.mockResolvedValueOnce('payload!' as any);
|
||||
await expect(adapter.find(id)).resolves.toBe('payload!');
|
||||
});
|
||||
|
||||
|
||||
@@ -489,7 +489,8 @@ describe('AppRunner', (): void => {
|
||||
});
|
||||
|
||||
it('throws an error if creating a ComponentsManager fails.', async(): Promise<void> => {
|
||||
(manager.configRegistry.register as jest.Mock).mockRejectedValueOnce(new Error('Fatal'));
|
||||
// eslint-disable-next-line jest/unbound-method
|
||||
jest.mocked(manager.configRegistry.register).mockRejectedValueOnce(new Error('Fatal'));
|
||||
|
||||
let caughtError: Error = new Error('should disappear');
|
||||
try {
|
||||
@@ -572,7 +573,8 @@ describe('AppRunner', (): void => {
|
||||
});
|
||||
|
||||
it('throws an error if non-error objects get thrown.', async(): Promise<void> => {
|
||||
(manager.configRegistry.register as jest.Mock).mockRejectedValueOnce('NotAnError');
|
||||
// eslint-disable-next-line jest/unbound-method
|
||||
jest.mocked(manager.configRegistry.register).mockRejectedValueOnce('NotAnError');
|
||||
|
||||
let caughtError: Error = new Error('should disappear');
|
||||
try {
|
||||
|
||||
@@ -6,6 +6,7 @@ import type { ResourceIdentifier } from '../../../src/http/representation/Resour
|
||||
import { LockingResourceStore } from '../../../src/storage/LockingResourceStore';
|
||||
import type { ResourceStore } from '../../../src/storage/ResourceStore';
|
||||
import type { ExpiringReadWriteLocker } from '../../../src/util/locking/ExpiringReadWriteLocker';
|
||||
import type { ReadWriteLocker } from '../../../src/util/locking/ReadWriteLocker';
|
||||
import type { PromiseOrValue } from '../../../src/util/PromiseUtil';
|
||||
import { guardedStreamFrom } from '../../../src/util/StreamUtil';
|
||||
import { flushPromises } from '../../util/Util';
|
||||
@@ -19,7 +20,7 @@ describe('A LockingResourceStore', (): void => {
|
||||
const subjectId = { path: 'http://test.com/foo' };
|
||||
const data = { data: 'data!' } as any;
|
||||
let store: LockingResourceStore;
|
||||
let locker: ExpiringReadWriteLocker;
|
||||
let locker: jest.Mocked<ExpiringReadWriteLocker>;
|
||||
let source: ResourceStore;
|
||||
let auxiliaryStrategy: AuxiliaryIdentifierStrategy;
|
||||
let order: string[];
|
||||
@@ -62,7 +63,7 @@ describe('A LockingResourceStore', (): void => {
|
||||
} finally {
|
||||
order.push('unlock read');
|
||||
}
|
||||
}),
|
||||
}) satisfies ReadWriteLocker['withReadLock'] as any,
|
||||
withWriteLock: jest.fn(async <T>(
|
||||
identifier: ResourceIdentifier,
|
||||
whileLocked: (maintainLock: () => void) => PromiseOrValue<T>,
|
||||
@@ -73,7 +74,7 @@ describe('A LockingResourceStore', (): void => {
|
||||
} finally {
|
||||
order.push('unlock write');
|
||||
}
|
||||
}),
|
||||
}) satisfies ReadWriteLocker['withWriteLock'] as any,
|
||||
};
|
||||
|
||||
auxiliaryStrategy = {
|
||||
@@ -93,7 +94,7 @@ describe('A LockingResourceStore', (): void => {
|
||||
it('acquires a lock on the container when adding a representation.', async(): Promise<void> => {
|
||||
await store.addResource(subjectId, data);
|
||||
expect(locker.withWriteLock).toHaveBeenCalledTimes(1);
|
||||
expect((locker.withWriteLock as jest.Mock).mock.calls[0][0]).toEqual(subjectId);
|
||||
expect(locker.withWriteLock.mock.calls[0][0]).toEqual(subjectId);
|
||||
expect(source.addResource).toHaveBeenCalledTimes(1);
|
||||
expect(source.addResource).toHaveBeenLastCalledWith(subjectId, data, undefined);
|
||||
expect(order).toEqual([ 'lock write', 'addResource', 'unlock write' ]);
|
||||
@@ -101,7 +102,7 @@ describe('A LockingResourceStore', (): void => {
|
||||
order = [];
|
||||
await expect(store.addResource(auxiliaryId, data)).resolves.toBeUndefined();
|
||||
expect(locker.withWriteLock).toHaveBeenCalledTimes(2);
|
||||
expect((locker.withWriteLock as jest.Mock).mock.calls[1][0]).toEqual(subjectId);
|
||||
expect(locker.withWriteLock.mock.calls[1][0]).toEqual(subjectId);
|
||||
expect(source.addResource).toHaveBeenCalledTimes(2);
|
||||
expect(source.addResource).toHaveBeenLastCalledWith(auxiliaryId, data, undefined);
|
||||
expect(order).toEqual([ 'lock write', 'addResource', 'unlock write' ]);
|
||||
@@ -110,7 +111,7 @@ describe('A LockingResourceStore', (): void => {
|
||||
it('acquires a lock on the resource when setting its representation.', async(): Promise<void> => {
|
||||
await store.setRepresentation(subjectId, data);
|
||||
expect(locker.withWriteLock).toHaveBeenCalledTimes(1);
|
||||
expect((locker.withWriteLock as jest.Mock).mock.calls[0][0]).toEqual(subjectId);
|
||||
expect(locker.withWriteLock.mock.calls[0][0]).toEqual(subjectId);
|
||||
expect(source.setRepresentation).toHaveBeenCalledTimes(1);
|
||||
expect(source.setRepresentation).toHaveBeenLastCalledWith(subjectId, data, undefined);
|
||||
expect(order).toEqual([ 'lock write', 'setRepresentation', 'unlock write' ]);
|
||||
@@ -118,7 +119,7 @@ describe('A LockingResourceStore', (): void => {
|
||||
order = [];
|
||||
await expect(store.setRepresentation(auxiliaryId, data)).resolves.toBeUndefined();
|
||||
expect(locker.withWriteLock).toHaveBeenCalledTimes(2);
|
||||
expect((locker.withWriteLock as jest.Mock).mock.calls[1][0]).toEqual(subjectId);
|
||||
expect(locker.withWriteLock.mock.calls[1][0]).toEqual(subjectId);
|
||||
expect(source.setRepresentation).toHaveBeenCalledTimes(2);
|
||||
expect(source.setRepresentation).toHaveBeenLastCalledWith(auxiliaryId, data, undefined);
|
||||
expect(order).toEqual([ 'lock write', 'setRepresentation', 'unlock write' ]);
|
||||
@@ -127,7 +128,7 @@ describe('A LockingResourceStore', (): void => {
|
||||
it('acquires a lock on the resource when deleting it.', async(): Promise<void> => {
|
||||
await store.deleteResource(subjectId);
|
||||
expect(locker.withWriteLock).toHaveBeenCalledTimes(1);
|
||||
expect((locker.withWriteLock as jest.Mock).mock.calls[0][0]).toEqual(subjectId);
|
||||
expect(locker.withWriteLock.mock.calls[0][0]).toEqual(subjectId);
|
||||
expect(source.deleteResource).toHaveBeenCalledTimes(1);
|
||||
expect(source.deleteResource).toHaveBeenLastCalledWith(subjectId, undefined);
|
||||
expect(order).toEqual([ 'lock write', 'deleteResource', 'unlock write' ]);
|
||||
@@ -135,7 +136,7 @@ describe('A LockingResourceStore', (): void => {
|
||||
order = [];
|
||||
await expect(store.deleteResource(auxiliaryId)).resolves.toBeUndefined();
|
||||
expect(locker.withWriteLock).toHaveBeenCalledTimes(2);
|
||||
expect((locker.withWriteLock as jest.Mock).mock.calls[1][0]).toEqual(subjectId);
|
||||
expect(locker.withWriteLock.mock.calls[1][0]).toEqual(subjectId);
|
||||
expect(source.deleteResource).toHaveBeenCalledTimes(2);
|
||||
expect(source.deleteResource).toHaveBeenLastCalledWith(auxiliaryId, undefined);
|
||||
expect(order).toEqual([ 'lock write', 'deleteResource', 'unlock write' ]);
|
||||
@@ -144,7 +145,7 @@ describe('A LockingResourceStore', (): void => {
|
||||
it('acquires a lock on the resource when modifying its representation.', async(): Promise<void> => {
|
||||
await store.modifyResource(subjectId, data as Patch);
|
||||
expect(locker.withWriteLock).toHaveBeenCalledTimes(1);
|
||||
expect((locker.withWriteLock as jest.Mock).mock.calls[0][0]).toEqual(subjectId);
|
||||
expect(locker.withWriteLock.mock.calls[0][0]).toEqual(subjectId);
|
||||
expect(source.modifyResource).toHaveBeenCalledTimes(1);
|
||||
expect(source.modifyResource).toHaveBeenLastCalledWith(subjectId, data, undefined);
|
||||
expect(order).toEqual([ 'lock write', 'modifyResource', 'unlock write' ]);
|
||||
@@ -152,7 +153,7 @@ describe('A LockingResourceStore', (): void => {
|
||||
order = [];
|
||||
await expect(store.modifyResource(auxiliaryId, data as Patch)).resolves.toBeUndefined();
|
||||
expect(locker.withWriteLock).toHaveBeenCalledTimes(2);
|
||||
expect((locker.withWriteLock as jest.Mock).mock.calls[1][0]).toEqual(subjectId);
|
||||
expect(locker.withWriteLock.mock.calls[1][0]).toEqual(subjectId);
|
||||
expect(source.modifyResource).toHaveBeenCalledTimes(2);
|
||||
expect(source.modifyResource).toHaveBeenLastCalledWith(auxiliaryId, data, undefined);
|
||||
expect(order).toEqual([ 'lock write', 'modifyResource', 'unlock write' ]);
|
||||
@@ -165,7 +166,7 @@ describe('A LockingResourceStore', (): void => {
|
||||
};
|
||||
await expect(store.getRepresentation(subjectId, {})).rejects.toThrow('dummy');
|
||||
expect(locker.withReadLock).toHaveBeenCalledTimes(1);
|
||||
expect((locker.withReadLock as jest.Mock).mock.calls[0][0]).toEqual(subjectId);
|
||||
expect(locker.withReadLock.mock.calls[0][0]).toEqual(subjectId);
|
||||
expect(order).toEqual([ 'lock read', 'bad get', 'unlock read' ]);
|
||||
});
|
||||
|
||||
@@ -180,7 +181,7 @@ describe('A LockingResourceStore', (): void => {
|
||||
|
||||
// Verify the lock was acquired and released at the right time
|
||||
expect(locker.withReadLock).toHaveBeenCalledTimes(1);
|
||||
expect((locker.withReadLock as jest.Mock).mock.calls[0][0]).toEqual(subjectId);
|
||||
expect(locker.withReadLock.mock.calls[0][0]).toEqual(subjectId);
|
||||
expect(source.getRepresentation).toHaveBeenCalledTimes(1);
|
||||
expect(source.getRepresentation).toHaveBeenLastCalledWith(subjectId, {}, undefined);
|
||||
expect(order).toEqual([ 'lock read', 'getRepresentation', 'end', 'unlock read' ]);
|
||||
@@ -197,7 +198,7 @@ describe('A LockingResourceStore', (): void => {
|
||||
|
||||
// Verify the lock was acquired and released at the right time
|
||||
expect(locker.withReadLock).toHaveBeenCalledTimes(1);
|
||||
expect((locker.withReadLock as jest.Mock).mock.calls[0][0]).toEqual(subjectId);
|
||||
expect(locker.withReadLock.mock.calls[0][0]).toEqual(subjectId);
|
||||
expect(source.getRepresentation).toHaveBeenCalledTimes(1);
|
||||
expect(source.getRepresentation).toHaveBeenLastCalledWith(auxiliaryId, {}, undefined);
|
||||
expect(order).toEqual([ 'lock read', 'getRepresentation', 'end', 'unlock read' ]);
|
||||
@@ -215,7 +216,7 @@ describe('A LockingResourceStore', (): void => {
|
||||
|
||||
// Verify the lock was acquired and released at the right time
|
||||
expect(locker.withReadLock).toHaveBeenCalledTimes(1);
|
||||
expect((locker.withReadLock as jest.Mock).mock.calls[0][0]).toEqual(subjectId);
|
||||
expect(locker.withReadLock.mock.calls[0][0]).toEqual(subjectId);
|
||||
expect(source.getRepresentation).toHaveBeenCalledTimes(1);
|
||||
expect(representation.data.destroy).toHaveBeenCalledTimes(1);
|
||||
expect(order).toEqual([ 'lock read', 'getRepresentation', 'error', 'unlock read', 'close' ]);
|
||||
@@ -232,7 +233,7 @@ describe('A LockingResourceStore', (): void => {
|
||||
|
||||
// Verify the lock was acquired and released at the right time
|
||||
expect(locker.withReadLock).toHaveBeenCalledTimes(1);
|
||||
expect((locker.withReadLock as jest.Mock).mock.calls[0][0]).toEqual(subjectId);
|
||||
expect(locker.withReadLock.mock.calls[0][0]).toEqual(subjectId);
|
||||
expect(source.getRepresentation).toHaveBeenCalledTimes(1);
|
||||
expect(order).toEqual([ 'lock read', 'getRepresentation', 'close', 'unlock read' ]);
|
||||
});
|
||||
@@ -251,7 +252,7 @@ describe('A LockingResourceStore', (): void => {
|
||||
|
||||
// Verify the lock was acquired and released at the right time
|
||||
expect(locker.withReadLock).toHaveBeenCalledTimes(1);
|
||||
expect((locker.withReadLock as jest.Mock).mock.calls[0][0]).toEqual(subjectId);
|
||||
expect(locker.withReadLock.mock.calls[0][0]).toEqual(subjectId);
|
||||
expect(source.getRepresentation).toHaveBeenCalledTimes(1);
|
||||
expect(order).toEqual([ 'lock read', 'getRepresentation', 'end', 'unlock read' ]);
|
||||
});
|
||||
@@ -268,7 +269,7 @@ describe('A LockingResourceStore', (): void => {
|
||||
|
||||
// Verify the lock was acquired and released at the right time
|
||||
expect(locker.withReadLock).toHaveBeenCalledTimes(1);
|
||||
expect((locker.withReadLock as jest.Mock).mock.calls[0][0]).toEqual(subjectId);
|
||||
expect(locker.withReadLock.mock.calls[0][0]).toEqual(subjectId);
|
||||
expect(source.getRepresentation).toHaveBeenCalledTimes(1);
|
||||
expect(representation.data.destroy).toHaveBeenCalledTimes(1);
|
||||
expect(representation.data.destroy).toHaveBeenLastCalledWith(new Error('timeout'));
|
||||
@@ -288,7 +289,7 @@ describe('A LockingResourceStore', (): void => {
|
||||
|
||||
await expect(prom).rejects.toThrow('timeout');
|
||||
expect(locker.withReadLock).toHaveBeenCalledTimes(1);
|
||||
expect((locker.withReadLock as jest.Mock).mock.calls[0][0]).toEqual(subjectId);
|
||||
expect(locker.withReadLock.mock.calls[0][0]).toEqual(subjectId);
|
||||
expect(source.getRepresentation).toHaveBeenCalledTimes(1);
|
||||
expect(order).toEqual([ 'lock read', 'useless get', 'timeout', 'unlock read' ]);
|
||||
});
|
||||
|
||||
@@ -6,14 +6,14 @@ import { NotImplementedHttpError } from '../../../src/util/errors/NotImplemented
|
||||
|
||||
describe('A PatchingStore', (): void => {
|
||||
let store: PatchingStore;
|
||||
let source: ResourceStore;
|
||||
let source: jest.Mocked<ResourceStore>;
|
||||
let patcher: PatchHandler;
|
||||
let handleSafeFn: jest.Mock<Promise<void>, []>;
|
||||
|
||||
beforeEach(async(): Promise<void> => {
|
||||
source = {
|
||||
modifyResource: jest.fn(async(): Promise<any> => 'modify'),
|
||||
} as unknown as ResourceStore;
|
||||
} satisfies Partial<ResourceStore> as any;
|
||||
|
||||
handleSafeFn = jest.fn(async(): Promise<any> => 'patcher');
|
||||
patcher = { handleSafe: handleSafeFn } as unknown as PatchHandler;
|
||||
@@ -34,7 +34,7 @@ describe('A PatchingStore', (): void => {
|
||||
await expect(store.modifyResource({ path: 'modifyPath' }, {} as Patch)).resolves.toBe('patcher');
|
||||
expect(source.modifyResource).toHaveBeenCalledTimes(1);
|
||||
expect(source.modifyResource).toHaveBeenLastCalledWith({ path: 'modifyPath' }, {}, undefined);
|
||||
await expect((source.modifyResource as jest.Mock).mock.results[0].value).rejects.toThrow(NotImplementedHttpError);
|
||||
await expect(source.modifyResource.mock.results[0].value).rejects.toThrow(NotImplementedHttpError);
|
||||
expect(handleSafeFn).toHaveBeenCalledTimes(1);
|
||||
expect(handleSafeFn).toHaveBeenLastCalledWith({ source, identifier: { path: 'modifyPath' }, patch: {}});
|
||||
});
|
||||
|
||||
@@ -174,13 +174,13 @@ describe('A ChainedConverter', (): void => {
|
||||
];
|
||||
const converter = new ChainedConverter(converters);
|
||||
|
||||
jest.spyOn(converters[0], 'handle');
|
||||
jest.spyOn(converters[1], 'handle');
|
||||
const spy0 = jest.spyOn(converters[0], 'handle');
|
||||
const spy1 = jest.spyOn(converters[1], 'handle');
|
||||
const result = await converter.handle(args);
|
||||
expect(result.metadata.contentType).toBe('x/x');
|
||||
let { metadata } = await (converters[0].handle as jest.Mock).mock.results[0].value;
|
||||
let { metadata } = await spy0.mock.results[0].value;
|
||||
expect(metadata.contentType).toBe('c/c');
|
||||
({ metadata } = await (converters[1].handle as jest.Mock).mock.results[0].value);
|
||||
({ metadata } = await spy1.mock.results[0].value);
|
||||
expect(metadata.contentType).toBe('d/d');
|
||||
});
|
||||
|
||||
|
||||
@@ -143,7 +143,7 @@ describe('StreamUtil', (): void => {
|
||||
});
|
||||
|
||||
it('does not destroy the source stream if it is an HttpRequest.', async(): Promise<void> => {
|
||||
(isHttpRequest as unknown as jest.Mock).mockReturnValueOnce(true);
|
||||
jest.mocked(isHttpRequest).mockReturnValueOnce(true);
|
||||
const input = new PassThrough();
|
||||
const output = new PassThrough();
|
||||
const piped = pipeSafely(input, output);
|
||||
@@ -160,7 +160,7 @@ describe('StreamUtil', (): void => {
|
||||
});
|
||||
|
||||
it('still sends errors downstream if the input is an HttpRequest.', async(): Promise<void> => {
|
||||
(isHttpRequest as unknown as jest.Mock).mockReturnValueOnce(true);
|
||||
jest.mocked(isHttpRequest).mockReturnValueOnce(true);
|
||||
const input = new PassThrough();
|
||||
input.read = (): any => {
|
||||
input.emit('error', new Error('error'));
|
||||
@@ -172,7 +172,7 @@ describe('StreamUtil', (): void => {
|
||||
});
|
||||
|
||||
it('can map errors if the input is an HttpRequest.', async(): Promise<void> => {
|
||||
(isHttpRequest as unknown as jest.Mock).mockReturnValueOnce(true);
|
||||
jest.mocked(isHttpRequest).mockReturnValueOnce(true);
|
||||
const input = Readable.from([ 'data' ]);
|
||||
input.read = (): any => {
|
||||
input.emit('error', new Error('error'));
|
||||
|
||||
@@ -9,16 +9,16 @@ describe('A WrappedExpiringReadWriteLocker', (): void => {
|
||||
const identifier = { path: 'path' };
|
||||
let syncCb: () => string;
|
||||
let asyncCb: () => Promise<string>;
|
||||
let wrappedLocker: ReadWriteLocker;
|
||||
let wrappedLocker: jest.Mocked<ReadWriteLocker>;
|
||||
let locker: WrappedExpiringReadWriteLocker;
|
||||
const expiration = 1000;
|
||||
|
||||
beforeEach(async(): Promise<void> => {
|
||||
wrappedLocker = {
|
||||
withReadLock: jest.fn(async<T>(id: ResourceIdentifier, whileLocked: () => PromiseOrValue<T>):
|
||||
Promise<T> => whileLocked()),
|
||||
Promise<T> => whileLocked()) satisfies ReadWriteLocker['withReadLock'] as any,
|
||||
withWriteLock: jest.fn(async<T>(id: ResourceIdentifier, whileLocked: () => PromiseOrValue<T>):
|
||||
Promise<T> => whileLocked()),
|
||||
Promise<T> => whileLocked()) satisfies ReadWriteLocker['withWriteLock'] as any,
|
||||
};
|
||||
|
||||
syncCb = jest.fn((): string => 'sync');
|
||||
@@ -33,12 +33,12 @@ describe('A WrappedExpiringReadWriteLocker', (): void => {
|
||||
let prom = locker.withReadLock(identifier, syncCb);
|
||||
await expect(prom).resolves.toBe('sync');
|
||||
expect(wrappedLocker.withReadLock).toHaveBeenCalledTimes(1);
|
||||
expect((wrappedLocker.withReadLock as jest.Mock).mock.calls[0][0]).toBe(identifier);
|
||||
expect(wrappedLocker.withReadLock.mock.calls[0][0]).toBe(identifier);
|
||||
|
||||
prom = locker.withWriteLock(identifier, syncCb);
|
||||
await expect(prom).resolves.toBe('sync');
|
||||
expect(wrappedLocker.withWriteLock).toHaveBeenCalledTimes(1);
|
||||
expect((wrappedLocker.withWriteLock as jest.Mock).mock.calls[0][0]).toBe(identifier);
|
||||
expect(wrappedLocker.withWriteLock.mock.calls[0][0]).toBe(identifier);
|
||||
});
|
||||
|
||||
it('calls the functions that need to be locked through the wrapped locker.', async(): Promise<void> => {
|
||||
|
||||
Reference in New Issue
Block a user