8000 Fix #21 - Patch added and removed changes · Wikodit/js-data-jsonapi-light@c857947 · GitHub
[go: up one dir, main page]

Skip to content

Commit c857947

Browse files
committed
Fix #21 - Patch added and removed changes
1 parent 0068088 commit c857947

File tree

4 files changed

+15
-10
lines changed

4 files changed

+15
-10
lines changed

dist/js-data-jsonapi-light.js

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/js-data-jsonapi-light.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/serializer.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { mapperCacheRelationByField } from './utils';
2+
import { utils } from 'js-data';
23

34
export function wrapSerialize (self:any):any{
45
return function(mapper:any, data:any, opts:any){
@@ -31,7 +32,10 @@ export function jsonApiSerialize (mapper:any, data:any, opts:any){
3132
// opts.changes is there when update method is PATCH
3233
// in this case we change only what has changed
3334
if (!opts.forceReplace && opts.changes && id) {
34-
data = opts.changes.changed;
35+
data = utils.deepMixIn(
36+
utils.deepMixIn({}, opts.changes.changed),
37+
opts.changes.added
38+
);
3539
}
3640

3741
// @todo For the moment sending hasMany items is not supported and maybe

test/unit/crud/update.spec.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,15 +129,15 @@ describe('UPDATE', () => {
129129
const TEST_ADDED_FIELD = 'test';
130130
return store.find('Article', ID).then((record) => {
131131
record.title = UPDATE_PARAMS.title;
132-
record.description = TEST_ADDED_FIELD;
132+
record.testAddedField = TEST_ADDED_FIELD;
133133
return record.save();
134134
}).then((data) => {
135-
expect(reqPatch.body).to.deep.equal({
136-
data: {
137-
type: MAPPER_NAME,
138-
id: ID,
139-
attributes: { title: UPDATE_PARAMS.title, testAddedField: TEST_ADDED_FIELD }
140-
}
135+
expect(reqPatch.body.data).to.be.an('object');
136+
expect(reqPatch.body.data.type).to.equal(MAPPER_NAME);
137+
expect(reqPatch.body.data.id).to.equal(ID);
138+
expect(reqPatch.body.data.attributes).to.deep.equal({
139+
title: UPDATE_PARAMS.title,
140+
testAddedField: TEST_ADDED_FIELD
141141
})
142142
})
143143
});

0 commit comments

Comments
 (0)
0