Skip to content

Commit

Permalink
fix(searchGroupUsers func): searchOptions is now an optional parameter
Browse files Browse the repository at this point in the history
ISSUES CLOSED: #615
  • Loading branch information
drewdaemon committed Sep 3, 2019
1 parent d49159f commit bbfdd9c
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 33 deletions.
13 changes: 5 additions & 8 deletions packages/arcgis-rest-portal/src/groups/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,12 @@ export interface ISearchGroupUsersResult {
*/
export function searchGroupUsers(
id: string,
searchOptions: ISearchGroupUsersOptions
searchOptions?: ISearchGroupUsersOptions
): Promise<ISearchGroupUsersResult> {
const url = `${getPortalUrl(searchOptions)}/community/groups/${id}/userlist`;
const options = appendCustomParams<ISearchGroupUsersOptions>(
searchOptions,
["name", "num", "start", "sortField", "sortOrder", "joined", "memberType"],
{
httpMethod: "GET"
}
);
const options: IRequestOptions = {
...{ httpMethod: "GET" },
...searchOptions
};
return request(url, options);
}
71 changes: 46 additions & 25 deletions packages/arcgis-rest-portal/test/groups/get.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,33 +104,54 @@ describe("groups", () => {
});
});

it("should search group users", done => {
fetchMock.once("*", SearchGroupUsersResponse);
describe("search group users", function() {
it("should search group users", done => {
fetchMock.once("*", SearchGroupUsersResponse);

searchGroupUsers("5bc", {
params: {
name: "jupe",
sortField: "fullname",
sortOrder: "asc",
num: 2,
start: 2,
joined: [null, 123456],
memberType: "member"
},
...MOCK_REQOPTS
})
.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/userlist?f=json&name=jupe&sortField=fullname&sortOrder=asc&num=2&start=2&joined=%2C123456&memberType=member&token=fake-token"
);
expect(options.method).toBe("GET");
done();
searchGroupUsers("5bc", {
params: {
name: "jupe",
sortField: "fullname",
sortOrder: "asc",
num: 2,
start: 2,
joined: [null, 123456],
memberType: "member"
},
...MOCK_REQOPTS
})
.catch(e => {
fail(e);
});
.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/userlist?f=json&name=jupe&sortField=fullname&sortOrder=asc&num=2&start=2&joined=%2C123456&memberType=member&token=fake-token"
);
expect(options.method).toBe("GET");
done();
})
.catch(e => {
fail(e);
});
});

it("shouldn't require searchOptions", done => {
fetchMock.once("*", SearchGroupUsersResponse);

searchGroupUsers("5bc")
.then(_ => {
expect(fetchMock.called()).toEqual(true);
const [__, options]: [string, RequestInit] = fetchMock.lastCall(
"*"
);
expect(options.method).toBe("GET");
done();
})
.catch(e => {
fail(e);
});
});
});
});
});

0 comments on commit bbfdd9c

Please sign in to comment.