Skip to content
This repository was archived by the owner on Jun 22, 2021. It is now read-only.

Commit a6dab3a

Browse files
committed
feat(patchEntity): Adds tests for patchEntity.
1 parent 85d8816 commit a6dab3a

File tree

2 files changed

+46
-5
lines changed

2 files changed

+46
-5
lines changed

src/tests/overwriteEntity/test.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,24 @@ import Facade from '../../Facade';
66
import { TestEntity, testEntity, testId, TestId } from '../testEntity';
77

88
export default (facade: Facade<TestId, TestEntity>) => {
9-
describe('removeEntity', () => {
9+
describe('overwriteEntity', () => {
1010
it('should error when identifier does not exist', async () => {
1111
const promise = facade.overwriteEntity({ id: testId, entity: testEntity });
1212
await assertRejects(promise, MissingEntityError);
1313
});
1414

1515
it('should overwrite when identifier does exist', async () => {
16-
const overwrite: TestEntity = {
16+
const testOverwrite: TestEntity = {
1717
...testId,
1818
booleanProp: false,
1919
numberProp: 2,
2020
stringProp: 'test_string_prop_overwrite',
2121
};
2222
await facade.createEntity({ entity: testEntity });
23-
const overwrittenEntity = await facade.overwriteEntity({ id: testId, entity: overwrite });
23+
const overwrittenEntity = await facade.overwriteEntity({ id: testId, entity: testOverwrite });
2424
const retrievedEntity = await facade.getEntity({ id: testId });
25-
assert.deepEqual(overwrittenEntity, overwrite);
26-
assert.deepEqual(retrievedEntity, overwrite);
25+
assert.deepEqual(overwrittenEntity, testOverwrite);
26+
assert.deepEqual(retrievedEntity, testOverwrite);
2727
});
2828
});
2929
};

src/tests/patchEntity/test.ts

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import * as assertRejects from 'assert-rejects';
2+
import 'mocha'; // tslint:disable-line:no-import-side-effect
3+
import * as assert from 'power-assert';
4+
import MissingEntityError from '../../errors/MissingEntityError';
5+
import Facade from '../../Facade';
6+
import { TestEntity, testEntity, testId, TestId } from '../testEntity';
7+
8+
export default (facade: Facade<TestId, TestEntity>) => {
9+
describe('patchEntity', () => {
10+
const assertPatch = async (testPatch: Partial<TestEntity>) => {
11+
const patchedEntity = await facade.patchEntity({ id: testId, patch: testPatch });
12+
const retrievedEntity = await facade.getEntity({ id: testId });
13+
const expectedEntity = { ...testEntity, ...testPatch };
14+
assert.deepEqual(patchedEntity, expectedEntity);
15+
assert.deepEqual(retrievedEntity, expectedEntity);
16+
};
17+
18+
it('should error when identifier does not exist', async () => {
19+
const promise = facade.overwriteEntity({ id: testId, entity: testEntity });
20+
await assertRejects(promise, MissingEntityError);
21+
});
22+
23+
it('should patch when patching one entity property', async () => {
24+
const testPatch: Partial<TestEntity> = {
25+
stringProp: 'test_string_prop_patch',
26+
};
27+
await facade.createEntity({ entity: testEntity });
28+
await assertPatch(testPatch);
29+
});
30+
31+
it('should patch when patching all entity properties', async () => {
32+
const testPatch: Partial<TestEntity> = {
33+
booleanProp: false,
34+
numberProp: 2,
35+
stringProp: 'test_string_prop_patch',
36+
};
37+
await facade.createEntity({ entity: testEntity });
38+
await assertPatch(testPatch);
39+
});
40+
});
41+
};

0 commit comments

Comments
 (0)