Skip to content

Commit

Permalink
RE - Rename partial updates to patch.
Browse files Browse the repository at this point in the history
  • Loading branch information
RickEyre authored and alicoding committed Jul 13, 2017
1 parent c9064b2 commit 54f2e13
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
6 changes: 4 additions & 2 deletions src/lib/__tests__/service.integration-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,15 @@ describe('service', () => {
expect(result).toEqual({ response: 200 });
});
});
});

test('should make put request given partial update', () => {
describe('#patch', () => {
test('should make patch request', () => {
fetchMock.patch(detailEndpoint, { response: 200 });

const service = buildService(testEndpoint);

return service.update('1', cake, { partial: true }).then((result) => {
return service.patch('1', cake).then((result) => {
expect(fetchMock.done(detailEndpoint)).toEqual(true);
expect(result).toEqual({ response: 200 });
});
Expand Down
6 changes: 4 additions & 2 deletions src/lib/__tests__/service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,15 @@ describe('crud-service', () => {
expect(result).toEqual(cake);
});
});
});

test('should make patch request given partial flag set to true', () => {
describe('#patch', () => {
test('should make patch request', () => {
api.patch = jest.fn().mockImplementation(mockResponse({ body: cake }));

const service = buildService(TEST_ENDPOINT);

return service.update('1', cake, { partial: true }).then((result) => {
return service.patch('1', cake).then((result) => {
expect(api.patch).toHaveBeenCalledWith(
`${TEST_ENDPOINT}/1`,
cake,
Expand Down
11 changes: 5 additions & 6 deletions src/lib/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,11 @@ class Service {
create(body) {
return makeRequest(api.post, this.endpoint, body);
}
update(id, body, { partial } = {}) {
return makeRequest(
partial ? api.patch : api.put,
getUrl(this.endpoint, id),
body
);
update(id, body) {
return makeRequest(api.put, getUrl(this.endpoint, id), body);
}
patch(id, body) {
return makeRequest(api.patch, getUrl(this.endpoint, id), body);
}
remove(id) {
return makeRequest(api.delete, getUrl(this.endpoint, id));
Expand Down

0 comments on commit 54f2e13

Please sign in to comment.