Skip to content
This repository has been archived by the owner on Nov 25, 2020. It is now read-only.

Commit

Permalink
fix(entity): do not delete id from request body in update calls
Browse files Browse the repository at this point in the history
Previous functionality unnecessarily limited common alternative API conventions.

BREAKING CHANGE: id properties are now included in the request body of update calls. Fixes #185.
  • Loading branch information
CuddleBunny committed Feb 7, 2017
1 parent a813afc commit cfd6cf6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
2 changes: 0 additions & 2 deletions src/entity.js
Expand Up @@ -172,8 +172,6 @@ export class Entity {
let requestBody = this.asObject(true);
let response;

delete requestBody[this.getIdProperty()];

return this.getTransport()
.update(this.getResource(), this.getId(), requestBody)
.then(updated => { response = updated; })
Expand Down
7 changes: 4 additions & 3 deletions test/entity.spec.js
Expand Up @@ -189,7 +189,7 @@ describe('Entity', function() {
entity.idTag = 1337;

entity.save().then(response => {
expect(response.body).toEqual({foo: 'bar'});
expect(response.body).toEqual({idTag: 1337, foo: 'bar'});
expect(response.path).toEqual('/with-resource/1337');
expect(response.method).toEqual('PUT');

Expand Down Expand Up @@ -251,7 +251,7 @@ describe('Entity', function() {
entity.id = 1991;

entity.save().then(response => {
expect(response.body).toEqual({bacon: 'great!'});
expect(response.body).toEqual({id: 1991, bacon: 'great!'});
expect(response.path).toEqual('/default-entity/1991');
expect(response.method).toEqual('PUT');

Expand Down Expand Up @@ -416,7 +416,7 @@ describe('Entity', function() {
entity.city = {awesome: true};

entity.update().then(response => {
expect(response.body).toEqual({foo: 'bar', city: {awesome: true}});
expect(response.body).toEqual({idTag: 666, foo: 'bar', city: {awesome: true}});
expect(response.path).toEqual('/with-resource/666');
expect(response.method).toEqual('PUT');

Expand Down Expand Up @@ -474,6 +474,7 @@ describe('Entity', function() {
expect(response.path).toEqual('/withassociations/1');
expect(response.method).toEqual('PUT');
expect(response.body).toEqual({
id: 1,
bar: {
baby: 'steps'
},
Expand Down

0 comments on commit cfd6cf6

Please sign in to comment.