Address comments

This commit is contained in:
Fredrik Adelöw
2020-05-14 09:31:04 +02:00
parent d86baf0ec5
commit 922e783150
3 changed files with 15 additions and 7 deletions
@@ -28,7 +28,7 @@ describe('CatalogLogic', () => {
it('works with no locations added', async () => {
const catalog = ({
addOrUpdateComponent: jest.fn(),
locations: jest.fn(() => []),
locations: jest.fn().mockResolvedValue([]),
} as unknown) as Catalog;
const locationReader = jest.fn();
@@ -41,7 +41,7 @@ describe('CatalogLogic', () => {
it('can update a single location', async () => {
const catalog = ({
addOrUpdateComponent: jest.fn(),
locations: jest.fn(() => [
locations: jest.fn().mockResolvedValue([
{
id: '123',
type: 'some',
@@ -24,19 +24,27 @@ export class CatalogLogic {
reader: LocationReader,
logger: Logger,
): () => void {
let cancel: () => void;
let cancelled = false;
const cancellationPromise = new Promise((resolve) => {
cancel = () => {
resolve();
cancelled = true;
};
});
const startRefresh = async () => {
while (!cancelled) {
await CatalogLogic.refreshLocations(catalog, reader, logger);
await new Promise((resolve) => setTimeout(resolve, 10000));
await Promise.race([
new Promise((resolve) => setTimeout(resolve, 10000)),
cancellationPromise,
]);
}
};
startRefresh();
return () => {
cancelled = true;
};
return cancel!;
}
public static async refreshLocations(
@@ -53,7 +53,7 @@ describe('DatabaseCatalog', () => {
await catalog.removeLocation(locations[0].id);
await expect(catalog.locations()).resolves.toEqual([]);
await expect(catalog.location(locations[0].id)).rejects.toThrowError(
await expect(catalog.location(locations[0].id)).rejects.toThrow(
/Found no location/,
);
});