Skip to content
This repository has been archived by the owner on Dec 17, 2018. It is now read-only.

Commit

Permalink
Also make sure that update and create do not modify their data (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
daffl authored Jul 8, 2016
1 parent 06f19ae commit a625612
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/common-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -406,8 +406,12 @@ export default function common(people, _ids, errors, idProp = 'id') {
});

describe('update', () => {
it('replaces an existing instance', done => {
people.update(_ids.Doug, { name: 'Dougler' }).then(data => {
it('replaces an existing instance, does not modify original data', done => {
const originalData = { [idProp]: _ids.Doug, name: 'Dougler' };
const originalCopy = Object.assign({}, originalData);

people.update(_ids.Doug, originalData).then(data => {
expect(originalData).to.deep.equal(originalCopy);
expect(data[idProp].toString()).to.equal(_ids.Doug.toString());
expect(data.name).to.equal('Dougler');
expect(!data.age).to.be.ok;
Expand All @@ -426,7 +430,7 @@ export default function common(people, _ids, errors, idProp = 'id') {
});

describe('patch', () => {
it('updates an existing instance, does not delete data', done => {
it('updates an existing instance, does not modify original data', done => {
const originalData = { [idProp]: _ids.Doug, name: 'PatchDoug' };
const originalCopy = Object.assign({}, originalData);

Expand Down Expand Up @@ -463,10 +467,14 @@ export default function common(people, _ids, errors, idProp = 'id') {

describe('create', () => {
it('creates a single new instance and returns the created instance', done => {
people.create({
const originalData = {
name: 'Bill',
age: 40
}).then(data => {
};
const originalCopy = Object.assign({}, originalData);

people.create(originalData).then(data => {
expect(originalData).to.deep.equal(originalCopy);
expect(data).to.be.instanceof(Object);
expect(data).to.not.be.empty;
expect(data.name).to.equal('Bill');
Expand Down

0 comments on commit a625612

Please sign in to comment.