Skip to content

Commit

Permalink
feat(): support value mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
tannerjt committed Jul 19, 2023
1 parent 06ccda4 commit 9ff8624
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
16 changes: 12 additions & 4 deletions packages/common/src/search/_internal/hubSearchChannels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,23 @@ export const processSearchParams = (
const mapValue = (key: keyof ISearchChannels, value: any): string => {
let _value = value;
if (key === "sortOrder") {
_value = value.toUpperCase();
_value = value?.toUpperCase();
} else if (key === "sortBy") {
_value = {
created: "createdAt",
modified: "updatedAt",
title: null,
}[value as "created" | "modified" | "title"];
}
return _value;
};
allowedPaginationProps.forEach((prop) => {
if (options.hasOwnProperty(prop)) {
const key = mapKey(prop);
const value = mapValue(key, options[prop]);
paginationProps[key] = value;
if (key && value) {
paginationProps[key] = value;
}
}
});
// Acceptable fields to use as filters
Expand Down Expand Up @@ -107,9 +115,9 @@ export const toHubSearchResult = (
...channel,
id: channel.id,
name: channel.name,
createdDate: channel.createdAt,
createdDate: new Date(channel.createdAt),
createdDateSource: "channel",
updatedDate: channel.updatedAt,
updatedDate: new Date(channel.updatedAt),
updatedDateSource: "channel",
type: "channel",
access: channel.access,
Expand Down
30 changes: 30 additions & 0 deletions packages/common/test/search/_internal/hubSearchChannels.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,34 @@ describe("discussionsSearchItems Module |", () => {
expect(err.name).toBe("HubError");
}
});
it("handles undefined values", async () => {
const qry: IQuery = {
targetEntity: "channel",
filters: [
{
predicates: [
{
access: "private",
groups: ["cb0ddfc90f4f45b899c076c88d3fdc84"],
},
],
},
],
};
const opts: IHubSearchOptions = {
num: 10,
sortField: undefined,
sortOrder: undefined,
requestOptions: {
isPortal: false,
hubApiUrl: "https://hubqa.arcgis.com/api",
token: "my-secret-token",
} as IHubRequestOptions,
};
const result = await hubSearchChannels.hubSearchChannels(qry, opts);
expect(processSearchParamsSpy).toHaveBeenCalledTimes(1);
expect(toHubSearchResultSpy).toHaveBeenCalledTimes(1);
expect(searchChannelsSpy).toHaveBeenCalledTimes(1);
expect(result).toBeTruthy();
});
});

0 comments on commit 9ff8624

Please sign in to comment.