-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(hub-common): _searchGroups via Filter<group>
- Loading branch information
Showing
8 changed files
with
342 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { UserSession } from "@esri/arcgis-rest-auth"; | ||
|
||
const TOMORROW = (function () { | ||
const now = new Date(); | ||
now.setDate(now.getDate() + 1); | ||
return now; | ||
})(); | ||
|
||
export const MOCK_AUTH = new UserSession({ | ||
clientId: "clientId", | ||
redirectUri: "https://example-app.com/redirect-uri", | ||
token: "fake-token", | ||
tokenExpires: TOMORROW, | ||
refreshToken: "refreshToken", | ||
refreshTokenExpires: TOMORROW, | ||
refreshTokenTTL: 1440, | ||
username: "casey", | ||
password: "123456", | ||
portal: "https://myorg.maps.arcgis.com/sharing/rest", | ||
}); |
85 changes: 85 additions & 0 deletions
85
packages/common/test/mocks/portal-groups-search/simple-response.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
{ | ||
"query": "(Open) ", | ||
"total": 2, | ||
"start": 1, | ||
"num": 20, | ||
"nextStart": -1, | ||
"results": [ | ||
{ | ||
"id": "7d9cc5e39a8f4c0aa29e04a473bf4703", | ||
"title": "00 Demo OD Initiative Open Data Group", | ||
"isInvitationOnly": false, | ||
"owner": "dbouwman", | ||
"description": "00 Demo OD Initiative Open Data Group", | ||
"snippet": null, | ||
"tags": [ | ||
"Hub Initiative Group", | ||
"Open Data" | ||
], | ||
"typeKeywords": [], | ||
"phone": null, | ||
"sortField": "title", | ||
"sortOrder": "asc", | ||
"isViewOnly": false, | ||
"isOpenData": true, | ||
"featuredItemsId": null, | ||
"thumbnail": "happy-gilmore.png", | ||
"created": 1551991859000, | ||
"modified": 1551991860000, | ||
"access": "public", | ||
"capabilities": [], | ||
"isFav": false, | ||
"isReadOnly": false, | ||
"protected": true, | ||
"autoJoin": false, | ||
"notificationsEnabled": false, | ||
"provider": null, | ||
"providerGroupName": null, | ||
"leavingDisallowed": false, | ||
"hiddenMembers": false, | ||
"displaySettings": { | ||
"itemTypes": "" | ||
}, | ||
"properties": null | ||
}, | ||
{ | ||
"id": "8564992879dc48ed82780637f99074bf", | ||
"title": "Alexandria Open Data Demo Content", | ||
"isInvitationOnly": false, | ||
"owner": "phammons_dcdev", | ||
"description": "Use this group to organize the items that you want to share as part of your initiative. Shared items become available in your initiative's search results and only people who have access to these items will be able to find them. Members of the core team get access to shared items and can update them at any time. Certain cards, like the Gallery card, will automatically populate with shared items so that you don't have to search for them when choosing what you want to display on your site.<br /><br />Contact support with any questions related to this group or content management for your site.<br /><br /><strong>DO NOT DELETE THIS GROUP.</strong>", | ||
"snippet": "Applications, maps, data, etc. shared with this group generates the Alexandria Open Data Demo content catalog.", | ||
"tags": [ | ||
"Hub Group", | ||
"Hub Content Group", | ||
"Hub Site Group", | ||
"Hub Initiative Group" | ||
], | ||
"typeKeywords": [], | ||
"phone": null, | ||
"sortField": "modified", | ||
"sortOrder": "desc", | ||
"isViewOnly": false, | ||
"featuredItemsId": null, | ||
"thumbnail": null, | ||
"created": 1586893843000, | ||
"modified": 1586893844000, | ||
"access": "public", | ||
"capabilities": [], | ||
"isFav": false, | ||
"isReadOnly": false, | ||
"protected": true, | ||
"autoJoin": false, | ||
"notificationsEnabled": false, | ||
"provider": null, | ||
"providerGroupName": null, | ||
"leavingDisallowed": false, | ||
"hiddenMembers": false, | ||
"displaySettings": { | ||
"itemTypes": "" | ||
}, | ||
"properties": null | ||
} | ||
|
||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { | ||
cloneObject, | ||
Filter, | ||
IHubSearchOptions, | ||
_searchGroups, | ||
} from "../../src"; | ||
import * as Portal from "@esri/arcgis-rest-portal"; | ||
import * as SimpleResponse from "../mocks/portal-groups-search/simple-response.json"; | ||
import { MOCK_AUTH } from "../mocks/mock-auth"; | ||
|
||
describe("_searchGroups:", () => { | ||
it("defaults to ago prod", async () => { | ||
const searchGroupsSpy = spyOn(Portal, "searchGroups").and.callFake(() => { | ||
return Promise.resolve(cloneObject(SimpleResponse)); | ||
}); | ||
const f: Filter<"group"> = { | ||
filterType: "group", | ||
term: "water", | ||
}; | ||
const o: IHubSearchOptions = {}; | ||
await _searchGroups(f, o); | ||
expect(searchGroupsSpy.calls.count()).toBe(1, "should call searchGroups"); | ||
const [expectedParams] = searchGroupsSpy.calls.argsFor(0); | ||
expect(expectedParams.q).toEqual("water"); | ||
expect(expectedParams.portal).toBe("https://www.arcgis.com/sharing/rest"); | ||
}); | ||
|
||
it("uses specified apis, passes num", async () => { | ||
const searchGroupsSpy = spyOn(Portal, "searchGroups").and.callFake(() => { | ||
return Promise.resolve(cloneObject(SimpleResponse)); | ||
}); | ||
const f: Filter<"group"> = { | ||
filterType: "group", | ||
term: "water", | ||
}; | ||
const o: IHubSearchOptions = { | ||
apis: ["arcgisQA"], | ||
num: 6, | ||
}; | ||
await _searchGroups(f, o); | ||
expect(searchGroupsSpy.calls.count()).toBe(1, "should call searchGroups"); | ||
const [expectedParams] = searchGroupsSpy.calls.argsFor(0); | ||
|
||
expect(expectedParams.q).toEqual("water"); | ||
expect(expectedParams.num).toEqual(6); | ||
expect(expectedParams.portal).toBe("https://qaext.arcgis.com/sharing/rest"); | ||
}); | ||
it("passes auth", async () => { | ||
const searchGroupsSpy = spyOn(Portal, "searchGroups").and.callFake(() => { | ||
return Promise.resolve(cloneObject(SimpleResponse)); | ||
}); | ||
const f: Filter<"group"> = { | ||
filterType: "group", | ||
term: "water", | ||
}; | ||
const o: IHubSearchOptions = { | ||
authentication: MOCK_AUTH, | ||
}; | ||
const chk = await _searchGroups(f, o); | ||
expect(searchGroupsSpy.calls.count()).toBe(1, "should call searchGroups"); | ||
const [expectedParams] = searchGroupsSpy.calls.argsFor(0); | ||
expect(expectedParams.authentication).toBe(MOCK_AUTH); | ||
const g1 = chk.results[0]; | ||
expect(g1.id).toBe("7d9cc5e39a8f4c0aa29e04a473bf4703"); | ||
expect(g1.thumbnailUrl).toBeDefined(); | ||
}); | ||
}); |
Oops, something went wrong.