-
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): add "reharvestSiteCatalog" util (#1279)
affects: @esri/hub-common
- Loading branch information
1 parent
92b2bf6
commit 6bdda94
Showing
3 changed files
with
64 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { IArcGISContext } from "../ArcGISContext"; | ||
|
||
interface IGroupReharvestInfo { | ||
/** | ||
* Catalog group being harvested | ||
*/ | ||
groupId: string; | ||
/** | ||
* Internal job id | ||
*/ | ||
jobId: string; | ||
/** | ||
* HTTP status code of the job | ||
*/ | ||
status: number; | ||
} | ||
|
||
/** | ||
* Trigger a manual update to reharvest each public item within a site's catalog. | ||
* This should only be used when search metadata has gotten out of sync despite | ||
* the nightly reharvest. | ||
* | ||
* @param siteId site's catalog to reharvest | ||
* @param context | ||
* @returns Job info for each group whose content is being harvested | ||
*/ | ||
export async function reharvestSiteCatalog( | ||
siteId: string, | ||
context: IArcGISContext | ||
): Promise<IGroupReharvestInfo[]> { | ||
const apiHost = context.hubUrl; | ||
const url = `${apiHost}/api/v3/jobs/site/${siteId}/harvest`; | ||
const options = { | ||
method: "POST", | ||
headers: { | ||
"content-type": "application/json", | ||
authorization: context.hubRequestOptions.authentication.token, | ||
}, | ||
}; | ||
return fetch(url, options).then((result) => result.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,22 @@ | ||
import * as fetchMock from "fetch-mock"; | ||
import { MOCK_CONTEXT } from "../mocks/mock-auth"; | ||
import { reharvestSiteCatalog } from "../../src/sites/reharvestSiteCatalog"; | ||
|
||
describe("reharvestSiteCatalog", () => { | ||
it("correctly calls the reharvest endpoint", async () => { | ||
const url = `${MOCK_CONTEXT.hubUrl}/api/v3/jobs/site/some-site-id/harvest`; | ||
const expectedResults = [ | ||
{ | ||
groupId: "some-group-id", | ||
jobId: "some-job-id", | ||
status: 202, | ||
}, | ||
]; | ||
fetchMock.once(url, expectedResults); | ||
const actualResults = await reharvestSiteCatalog( | ||
"some-site-id", | ||
MOCK_CONTEXT | ||
); | ||
expect(actualResults).toEqual(expectedResults); | ||
}); | ||
}); |