Address comments

This commit is contained in:
Fredrik Adelöw
2020-05-28 20:50:46 +02:00
parent 0ce506ac43
commit 709e3381d8
15 changed files with 73 additions and 82 deletions
@@ -32,14 +32,14 @@ describe('DatabaseManager', () => {
readLocation: jest.fn(),
};
const policy: EntityPolicy = {
apply: jest.fn(),
enforce: jest.fn(),
};
await expect(
DatabaseManager.refreshLocations(db, reader, policy, getVoidLogger()),
).resolves.toBeUndefined();
expect(reader.readLocation).not.toHaveBeenCalled();
expect(policy.apply).not.toHaveBeenCalled();
expect(policy.enforce).not.toHaveBeenCalled();
});
it('can update a single location', async () => {
@@ -70,7 +70,7 @@ describe('DatabaseManager', () => {
),
};
const policy: EntityPolicy = {
apply: jest.fn(() => Promise.resolve(desc)),
enforce: jest.fn(() => Promise.resolve(desc)),
};
await expect(
@@ -118,7 +118,7 @@ describe('DatabaseManager', () => {
),
};
const policy: EntityPolicy = {
apply: jest.fn(() => Promise.resolve(desc)),
enforce: jest.fn(() => Promise.resolve(desc)),
};
await expect(
@@ -170,7 +170,9 @@ describe('DatabaseManager', () => {
),
};
const policy: EntityPolicy = {
apply: jest.fn(() => Promise.reject(new Error('parser error message'))),
enforce: jest.fn(() =>
Promise.reject(new Error('parser error message')),
),
};
await expect(
@@ -217,7 +219,9 @@ describe('DatabaseManager', () => {
),
};
const policy: EntityPolicy = {
apply: jest.fn(() => Promise.reject(new Error('parser error message'))),
enforce: jest.fn(() =>
Promise.reject(new Error('parser error message')),
),
};
await expect(
@@ -86,7 +86,7 @@ export class DatabaseManager {
}
try {
const entity = await entityPolicy.apply(readerItem.data);
const entity = await entityPolicy.enforce(readerItem.data);
await DatabaseManager.refreshSingleEntity(
database,
location.id,
@@ -60,7 +60,7 @@ export class IngestionModels implements IngestionModel {
result.push(item);
} else {
try {
const output = await this.entityPolicy.apply(item.data);
const output = await this.entityPolicy.enforce(item.data);
result.push({ type: 'data', data: output });
} catch (e) {
result.push({ type: 'error', error: e });