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

Also make sure that update and create do not modify their data #14

Merged
merged 1 commit into from
Jul 8, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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