|
| 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