Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(hub-common): add "reharvestSiteCatalog" util #1279

Merged
merged 1 commit into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/common/src/sites/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export * from "./site-schema-version";
export * from "./themes";
export * from "./upgrade-site-schema";
export * from "./feed-configuration";
export * from "./reharvestSiteCatalog";
// No longer exported b/c site app registration is now handled
// by the domain service due to requirement to send signed HMAC request
// export * from "./registerSiteAsApplication";
41 changes: 41 additions & 0 deletions packages/common/src/sites/reharvestSiteCatalog.ts
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());
}
22 changes: 22 additions & 0 deletions packages/common/test/sites/reharvestSiteCatalog.test.ts
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);
});
});