Skip to content

Commit

Permalink
Merge eccdd9e into ebbdc7e
Browse files Browse the repository at this point in the history
  • Loading branch information
jgravois committed Aug 17, 2018
2 parents ebbdc7e + eccdd9e commit cf86885
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
9 changes: 7 additions & 2 deletions packages/arcgis-rest-items/src/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,17 @@ export function searchItems(
if (typeof search === "string") {
options.params.q = search;
} else {
options.params = search.searchForm;
// mixin, giving user supplied requestOptions precedence
// mixin user supplied requestOptions with defaults
options = {
...options,
...search
};

// mixin arbitrary request parameters with search form
options.params = {
...search.params,
...search.searchForm
};
}

// construct the search url
Expand Down
29 changes: 29 additions & 0 deletions packages/arcgis-rest-items/test/search.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,35 @@ describe("search", () => {
});
});

it("should mixin generic params with the search form", done => {
fetchMock.once("*", SearchResponse);

searchItems({
searchForm: {
q: "DC AND typekeywords:hubSiteApplication",
num: 12,
start: 22,
sortField: "title",
sortDir: "desc"
},
params: {
foo: "bar"
}
})
.then(() => {
expect(fetchMock.called()).toEqual(true);
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
expect(url).toEqual(
"https://www.arcgis.com/sharing/rest/search?f=json&foo=bar&q=DC%20AND%20typekeywords%3AhubSiteApplication&num=12&start=22&sortField=title&sortDir=desc"
);
expect(options.method).toBe("GET");
done();
})
.catch(e => {
fail(e);
});
});

describe("Authenticated methods", () => {
// setup a UserSession to use in all these tests
const MOCK_USER_SESSION = new UserSession({
Expand Down

0 comments on commit cf86885

Please sign in to comment.