Skip to content

Commit 3e3dd5f

Browse files
committed
Pass options for create
1 parent 28dbdfa commit 3e3dd5f

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

src/Resource.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class Resource {
7474
return this.api.get(url).then(extractData).catch(extractErrorResponse);
7575
}
7676

77-
create({attributes, relationships}) {
77+
create({attributes, relationships, options}) {
7878
const record = {type: this.name};
7979
if (attributes) {
8080
record.attributes = attributes;
@@ -84,7 +84,7 @@ class Resource {
8484
}
8585
const requestData = {data: record};
8686
return this.api
87-
.post(`${this.name}`, requestData)
87+
.post(`${this.name}?${getOptionsQuery(options)}`, requestData)
8888
.then(extractData)
8989
.catch(extractErrorResponse);
9090
}

test/Resource.spec.js

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -245,16 +245,16 @@ describe('Resource', () => {
245245
});
246246

247247
describe('create', () => {
248-
it('can create a record', () => {
249-
const attributes = {key: 'value'};
250-
const relationships = {key2: 'value2'};
248+
const attributes = {key: 'value'};
249+
const relationships = {key2: 'value2'};
251250

251+
it('can create a record', () => {
252252
const responseBody = {data: record};
253253
api.post.mockResolvedValue({data: responseBody});
254254

255255
const result = resource.create({attributes, relationships});
256256

257-
expect(api.post).toHaveBeenCalledWith('widgets', {
257+
expect(api.post).toHaveBeenCalledWith('widgets?', {
258258
data: {
259259
type: 'widgets',
260260
attributes,
@@ -264,6 +264,21 @@ describe('Resource', () => {
264264
return expect(result).resolves.toEqual(responseBody);
265265
});
266266

267+
it('passes options', () => {
268+
const responseBody = {data: record};
269+
api.post.mockResolvedValue({data: responseBody});
270+
271+
resource.create({
272+
attributes,
273+
relationships,
274+
options: optionsWithInclude,
275+
});
276+
277+
expect(api.post).toHaveBeenCalledWith('widgets?include=comments', {
278+
data: {type: 'widgets', attributes, relationships},
279+
});
280+
});
281+
267282
it('rejects with the response upon error', () => {
268283
const errorResponse = {dummy: 'data'};
269284
api.post.mockRejectedValue({response: errorResponse});

0 commit comments

Comments
 (0)