Skip to content

Commit

Permalink
ensure custom params are passed through too
Browse files Browse the repository at this point in the history
  • Loading branch information
jgravois committed Feb 28, 2019
1 parent 3d4af05 commit 1ccf71e
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 8 deletions.
9 changes: 5 additions & 4 deletions packages/arcgis-rest-groups/src/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@ export function createGroup(
requestOptions: IGroupAddRequestOptions
): Promise<{ success: boolean; group: IGroup }> {
const url = `${getPortalUrl(requestOptions)}/community/createGroup`;
const options: IGroupAddRequestOptions = {
...requestOptions

requestOptions.params = {
...requestOptions.params,
...requestOptions.group
};

options.params = requestOptions.group;
return request(url, options);
return request(url, requestOptions);
}
8 changes: 4 additions & 4 deletions packages/arcgis-rest-groups/src/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ export function updateGroup(
requestOptions.group.id
}/update`;

const options: IGroupUpdateRequestOptions = {
...requestOptions
requestOptions.params = {
...requestOptions.params,
...requestOptions.group
};

options.params = requestOptions.group;
return request(url, options);
return request(url, requestOptions);
}
36 changes: 36 additions & 0 deletions packages/arcgis-rest-groups/test/crud.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,42 @@ describe("groups", () => {
});
});

it("should update a group with a custom param", done => {
fetchMock.once("*", GroupEditResponse);
const fakeGroup = {
id: "5bc",
title: "fake group",
owner: "fakeUser",
tags: ["foo", "bar"],
description: "my fake group"
};
updateGroup({
group: fakeGroup,
authentication: MOCK_AUTH,
params: {
clearEmptyFields: true
}
})
.then(response => {
expect(fetchMock.called()).toEqual(true);
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
expect(url).toEqual(
"https://myorg.maps.arcgis.com/sharing/rest/community/groups/5bc/update"
);
expect(options.method).toBe("POST");
expect(options.body).toContain(encodeParam("f", "json"));
expect(options.body).toContain(encodeParam("token", "fake-token"));
expect(options.body).toContain(encodeParam("owner", "fakeUser"));
// ensure the array props are serialized into strings
expect(options.body).toContain(encodeParam("tags", "foo,bar"));
expect(options.body).toContain(encodeParam("clearEmptyFields", true));
done();
})
.catch(e => {
fail(e);
});
});

it("should remove a group", done => {
fetchMock.once("*", GroupEditResponse);

Expand Down
55 changes: 55 additions & 0 deletions packages/arcgis-rest-items/test/update.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,61 @@ describe("search", () => {
});
});

it("should update an item with custom params", done => {
fetchMock.once("*", ItemSuccessResponse);
const fakeItem = {
id: "5bc",
owner: "dbouwman",
title: "my fake item",
description: "yep its fake",
snipped: "so very fake",
type: "Web Mapping Application",
typeKeywords: ["fake", "kwds"],
tags: ["fakey", "mcfakepants"],
properties: {
key: "somevalue"
},
data: {
values: {
key: "value"
}
}
};
updateItem({
item: fakeItem,
authentication: MOCK_USER_SESSION,
params: {
clearEmptyFields: true
}
})
.then(response => {
expect(fetchMock.called()).toEqual(true);
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
expect(url).toEqual(
"https://myorg.maps.arcgis.com/sharing/rest/content/users/dbouwman/items/5bc/update"
);
expect(options.method).toBe("POST");
expect(options.body).toContain(encodeParam("f", "json"));
expect(options.body).toContain(encodeParam("token", "fake-token"));
expect(options.body).toContain(encodeParam("owner", "dbouwman"));
// ensure the array props are serialized into strings
expect(options.body).toContain(
encodeParam("typeKeywords", "fake,kwds")
);
expect(options.body).toContain(
encodeParam("tags", "fakey,mcfakepants")
);
expect(options.body).toContain(
encodeParam("text", JSON.stringify(fakeItem.data))
);
expect(options.body).toContain(encodeParam("clearEmptyFields", true));
done();
})
.catch(e => {
fail(e);
});
});

it("should update an item, including data and service proxy params", done => {
fetchMock.once("*", ItemSuccessResponse);
const fakeItem = {
Expand Down

0 comments on commit 1ccf71e

Please sign in to comment.