Ported refPush and added tests

This commit is contained in:
Keith Holliday
2016-03-25 08:09:24 -05:00
parent 19a63e8128
commit d7b6e0b760
3 changed files with 59 additions and 6 deletions

View File

@@ -0,0 +1,53 @@
import shared from '../../../common';
import { v4 as generateUUID } from 'uuid';
describe('refPush', () => {
it('it hashes one object into another by its id', () => {
let referenceObject = {};
let objectToHash = {
a: 1,
id: generateUUID(),
};
shared.refPush(referenceObject, objectToHash);
expect(referenceObject[objectToHash.id].a).to.equal(objectToHash.a);
expect(referenceObject[objectToHash.id].id).to.equal(objectToHash.id);
expect(referenceObject[objectToHash.id].sort).to.equal(0);
});
it('it hashes one object into another by a uuid when object does not have an id', () => {
let referenceObject = {};
let objectToHash = {
a: 1,
};
shared.refPush(referenceObject, objectToHash);
let hashedObject = _.find(referenceObject, (hashedItem) => {
return objectToHash.a === hashedItem.a;
});
expect(hashedObject.a).to.equal(objectToHash.a);
expect(hashedObject.id).to.equal(objectToHash.id);
expect(hashedObject.sort).to.equal(0);
});
it('it hashes one object into another by a id and gives it the highest sort value', () => {
let referenceObject = {};
referenceObject[generateUUID()] = { b: 2, sort: 1 };
let objectToHash = {
a: 1,
};
shared.refPush(referenceObject, objectToHash);
let hashedObject = _.find(referenceObject, (hashedItem) => {
return objectToHash.a === hashedItem.a;
});
expect(hashedObject.a).to.equal(objectToHash.a);
expect(hashedObject.id).to.equal(objectToHash.id);
expect(hashedObject.sort).to.equal(2);
});
});