Skip to content

Commit 2aa7f77

Browse files
committed
Fill in type for update()
1 parent 2facbc1 commit 2aa7f77

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/Resource.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,9 @@ class Resource {
8383
.catch(extractErrorResponse);
8484
}
8585

86-
update(record) {
86+
update(partialRecord) {
8787
// http://jsonapi.org/faq/#wheres-put
88+
const record = Object.assign({}, partialRecord, { type: this.name });
8889
const requestData = { data: record };
8990
return this.api
9091
.patch(`${this.name}/${record.id}`, requestData)

test/Resource.spec.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,12 +274,15 @@ describe('Resource', () => {
274274

275275
describe('update', () => {
276276
it('can update a record', () => {
277+
const partialRecord = { id: '1', attributes: { key: 'value' } };
277278
const responseBody = { data: record };
278279
api.patch.mockResolvedValue({ data: responseBody });
279280

280-
const result = resource.update(record);
281+
const result = resource.update(partialRecord);
281282

282-
expect(api.patch).toHaveBeenCalledWith('widgets/1', { data: record });
283+
expect(api.patch).toHaveBeenCalledWith('widgets/1', {
284+
data: { ...partialRecord, type: 'widgets' },
285+
});
283286
return expect(result).resolves.toEqual(responseBody);
284287
});
285288

0 commit comments

Comments
 (0)