From 2aa69b7f57e19d2c390a17c1bcb58a28d5234c5c Mon Sep 17 00:00:00 2001 From: sansth1010 Date: Wed, 8 May 2024 13:18:49 -0500 Subject: [PATCH 1/4] fix(hub-common): fix undefined token when getting schedule --- packages/common/src/content/manageSchedule.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/common/src/content/manageSchedule.ts b/packages/common/src/content/manageSchedule.ts index ab92d4bd8e8..96596e77c3c 100644 --- a/packages/common/src/content/manageSchedule.ts +++ b/packages/common/src/content/manageSchedule.ts @@ -163,7 +163,7 @@ export const isDownloadSchedulingAvailable = ( requestOptions: IHubRequestOptions, access: AccessLevel ): boolean => { - const token = requestOptions.authentication.token; + const token = requestOptions.authentication?.token; return ( requestOptions.portal?.includes("arcgis.com") && access === "public" && From 255836957247a06c19e341ee3f3b16ea7979854a Mon Sep 17 00:00:00 2001 From: sansth1010 Date: Wed, 8 May 2024 13:56:12 -0500 Subject: [PATCH 2/4] fix(hub-common): add tests for getSchedule without a token --- packages/common/test/content/fetch.test.ts | 50 +++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/packages/common/test/content/fetch.test.ts b/packages/common/test/content/fetch.test.ts index 81633dcf44e..b748c6a5cae 100644 --- a/packages/common/test/content/fetch.test.ts +++ b/packages/common/test/content/fetch.test.ts @@ -11,6 +11,7 @@ import { } from "../../src"; import * as _enrichmentsModule from "../../src/items/_enrichments"; import * as _fetchModule from "../../src/content/_fetch"; +import * as scheduleModule from "../../src/content/manageSchedule"; import * as documentItem from "../mocks/items/document.json"; import * as multiLayerFeatureServiceItem from "../mocks/items/multi-layer-feature-service.json"; import { @@ -23,7 +24,7 @@ import { PDF_GUID, PDF_ITEM, } from "./fixtures"; -import { MOCK_AUTH } from "../mocks/mock-auth"; +import { MOCK_AUTH, MOCK_NOAUTH_HUB_REQOPTS } from "../mocks/mock-auth"; // mock the item enrichments that would be returned for a multi-layer service const getMultiLayerItemEnrichments = () => { @@ -708,6 +709,53 @@ describe("fetchHubContent", () => { expect(fetchItemEnrichmentsSpy.calls.argsFor(1)[1]).toEqual(["metadata"]); }); + it("should not get schedule without token", async () => { + const getItemSpy = spyOn(portalModule, "getItem").and.returnValue( + Promise.resolve(HOSTED_FEATURE_SERVICE_ITEM) + ); + const getServiceSpy = spyOn( + featureLayerModule, + "getService" + ).and.returnValue(HOSTED_FEATURE_SERVICE_DEFINITION); + const fetchItemEnrichmentsSpy = spyOn( + _enrichmentsModule, + "fetchItemEnrichments" + ).and.returnValue({ metadata: null }); + + const getScheduleSpy = spyOn(scheduleModule, "getSchedule").and.returnValue( + Promise.resolve({ + mode: "manual", + }) + ); + + const chk = await fetchHubContent( + HOSTED_FEATURE_SERVICE_GUID, + MOCK_NOAUTH_HUB_REQOPTS + ); + + // test for schedule + expect(chk.schedule).not.toBeDefined(); + expect(getScheduleSpy.calls.count()).toBe(0); + + expect(chk.id).toBe(HOSTED_FEATURE_SERVICE_GUID); + expect(chk.owner).toBe(HOSTED_FEATURE_SERVICE_ITEM.owner); + expect(chk.serverExtractCapability).toBeTruthy(); + + expect(getItemSpy.calls.count()).toBe(1); + expect(getItemSpy.calls.argsFor(0)[0]).toBe(HOSTED_FEATURE_SERVICE_GUID); + expect(getServiceSpy.calls.count()).toBe(1); + expect(getServiceSpy.calls.argsFor(0)[0].url).toBe( + HOSTED_FEATURE_SERVICE_URL + ); + // NOTE: the first call to fetchItemEnrichments is done by fetchContent under the hood, + // while the second call is done by fetchHubContent. We only care about the second call here + expect(fetchItemEnrichmentsSpy.calls.count()).toBe(2); + expect(fetchItemEnrichmentsSpy.calls.argsFor(1)[0]).toBe( + HOSTED_FEATURE_SERVICE_ITEM + ); + expect(fetchItemEnrichmentsSpy.calls.argsFor(1)[1]).toEqual(["metadata"]); + }); + it("gets non-hosted feature service", async () => { const getItemSpy = spyOn(portalModule, "getItem").and.returnValue( Promise.resolve(NON_HOSTED_FEATURE_SERVICE_ITEM) From 326f63dbb5d83debcc690f44722ceadf41f098ef Mon Sep 17 00:00:00 2001 From: sansth1010 Date: Wed, 8 May 2024 13:59:35 -0500 Subject: [PATCH 3/4] fix(hub-common): fix order of tests for getting schedule --- packages/common/test/content/fetch.test.ts | 94 +++++++++++----------- 1 file changed, 47 insertions(+), 47 deletions(-) diff --git a/packages/common/test/content/fetch.test.ts b/packages/common/test/content/fetch.test.ts index b748c6a5cae..786ce10bc20 100644 --- a/packages/common/test/content/fetch.test.ts +++ b/packages/common/test/content/fetch.test.ts @@ -709,53 +709,6 @@ describe("fetchHubContent", () => { expect(fetchItemEnrichmentsSpy.calls.argsFor(1)[1]).toEqual(["metadata"]); }); - it("should not get schedule without token", async () => { - const getItemSpy = spyOn(portalModule, "getItem").and.returnValue( - Promise.resolve(HOSTED_FEATURE_SERVICE_ITEM) - ); - const getServiceSpy = spyOn( - featureLayerModule, - "getService" - ).and.returnValue(HOSTED_FEATURE_SERVICE_DEFINITION); - const fetchItemEnrichmentsSpy = spyOn( - _enrichmentsModule, - "fetchItemEnrichments" - ).and.returnValue({ metadata: null }); - - const getScheduleSpy = spyOn(scheduleModule, "getSchedule").and.returnValue( - Promise.resolve({ - mode: "manual", - }) - ); - - const chk = await fetchHubContent( - HOSTED_FEATURE_SERVICE_GUID, - MOCK_NOAUTH_HUB_REQOPTS - ); - - // test for schedule - expect(chk.schedule).not.toBeDefined(); - expect(getScheduleSpy.calls.count()).toBe(0); - - expect(chk.id).toBe(HOSTED_FEATURE_SERVICE_GUID); - expect(chk.owner).toBe(HOSTED_FEATURE_SERVICE_ITEM.owner); - expect(chk.serverExtractCapability).toBeTruthy(); - - expect(getItemSpy.calls.count()).toBe(1); - expect(getItemSpy.calls.argsFor(0)[0]).toBe(HOSTED_FEATURE_SERVICE_GUID); - expect(getServiceSpy.calls.count()).toBe(1); - expect(getServiceSpy.calls.argsFor(0)[0].url).toBe( - HOSTED_FEATURE_SERVICE_URL - ); - // NOTE: the first call to fetchItemEnrichments is done by fetchContent under the hood, - // while the second call is done by fetchHubContent. We only care about the second call here - expect(fetchItemEnrichmentsSpy.calls.count()).toBe(2); - expect(fetchItemEnrichmentsSpy.calls.argsFor(1)[0]).toBe( - HOSTED_FEATURE_SERVICE_ITEM - ); - expect(fetchItemEnrichmentsSpy.calls.argsFor(1)[1]).toEqual(["metadata"]); - }); - it("gets non-hosted feature service", async () => { const getItemSpy = spyOn(portalModule, "getItem").and.returnValue( Promise.resolve(NON_HOSTED_FEATURE_SERVICE_ITEM) @@ -832,4 +785,51 @@ describe("fetchHubContent", () => { expect(chk.type).toBe("Hub Site Application"); }); + + it("should not get schedule without token", async () => { + const getItemSpy = spyOn(portalModule, "getItem").and.returnValue( + Promise.resolve(HOSTED_FEATURE_SERVICE_ITEM) + ); + const getServiceSpy = spyOn( + featureLayerModule, + "getService" + ).and.returnValue(HOSTED_FEATURE_SERVICE_DEFINITION); + const fetchItemEnrichmentsSpy = spyOn( + _enrichmentsModule, + "fetchItemEnrichments" + ).and.returnValue({ metadata: null }); + + const getScheduleSpy = spyOn(scheduleModule, "getSchedule").and.returnValue( + Promise.resolve({ + mode: "manual", + }) + ); + + const chk = await fetchHubContent( + HOSTED_FEATURE_SERVICE_GUID, + MOCK_NOAUTH_HUB_REQOPTS + ); + + // test for schedule + expect(chk.schedule).not.toBeDefined(); + expect(getScheduleSpy.calls.count()).toBe(0); + + expect(chk.id).toBe(HOSTED_FEATURE_SERVICE_GUID); + expect(chk.owner).toBe(HOSTED_FEATURE_SERVICE_ITEM.owner); + expect(chk.serverExtractCapability).toBeTruthy(); + + expect(getItemSpy.calls.count()).toBe(1); + expect(getItemSpy.calls.argsFor(0)[0]).toBe(HOSTED_FEATURE_SERVICE_GUID); + expect(getServiceSpy.calls.count()).toBe(1); + expect(getServiceSpy.calls.argsFor(0)[0].url).toBe( + HOSTED_FEATURE_SERVICE_URL + ); + // NOTE: the first call to fetchItemEnrichments is done by fetchContent under the hood, + // while the second call is done by fetchHubContent. We only care about the second call here + expect(fetchItemEnrichmentsSpy.calls.count()).toBe(2); + expect(fetchItemEnrichmentsSpy.calls.argsFor(1)[0]).toBe( + HOSTED_FEATURE_SERVICE_ITEM + ); + expect(fetchItemEnrichmentsSpy.calls.argsFor(1)[1]).toEqual(["metadata"]); + }); }); From ec22344c409dd8f31c0bec3324146ccbcfb1978a Mon Sep 17 00:00:00 2001 From: sansth1010 Date: Wed, 8 May 2024 14:02:41 -0500 Subject: [PATCH 4/4] fix(hub-common): add additional tests for get schedule --- packages/common/test/content/fetch.test.ts | 49 +++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/packages/common/test/content/fetch.test.ts b/packages/common/test/content/fetch.test.ts index 786ce10bc20..89c31258ca8 100644 --- a/packages/common/test/content/fetch.test.ts +++ b/packages/common/test/content/fetch.test.ts @@ -786,7 +786,54 @@ describe("fetchHubContent", () => { expect(chk.type).toBe("Hub Site Application"); }); - it("should not get schedule without token", async () => { + it("should get schedule for request with a token", async () => { + const getItemSpy = spyOn(portalModule, "getItem").and.returnValue( + Promise.resolve(HOSTED_FEATURE_SERVICE_ITEM) + ); + const getServiceSpy = spyOn( + featureLayerModule, + "getService" + ).and.returnValue(HOSTED_FEATURE_SERVICE_DEFINITION); + const fetchItemEnrichmentsSpy = spyOn( + _enrichmentsModule, + "fetchItemEnrichments" + ).and.returnValue({ metadata: null }); + + const getScheduleSpy = spyOn(scheduleModule, "getSchedule").and.returnValue( + Promise.resolve({ + mode: "manual", + }) + ); + + const chk = await fetchHubContent(HOSTED_FEATURE_SERVICE_GUID, { + portal: MOCK_AUTH.portal, + authentication: MOCK_AUTH, + }); + + // test for schedule + expect(chk.schedule).toBeDefined(); + expect(getScheduleSpy.calls.count()).toBe(1); + + expect(chk.id).toBe(HOSTED_FEATURE_SERVICE_GUID); + expect(chk.owner).toBe(HOSTED_FEATURE_SERVICE_ITEM.owner); + expect(chk.serverExtractCapability).toBeTruthy(); + + expect(getItemSpy.calls.count()).toBe(1); + expect(getItemSpy.calls.argsFor(0)[0]).toBe(HOSTED_FEATURE_SERVICE_GUID); + expect(getServiceSpy.calls.count()).toBe(1); + expect(getServiceSpy.calls.argsFor(0)[0].url).toBe( + HOSTED_FEATURE_SERVICE_URL + ); + // NOTE: the first call to fetchItemEnrichments is done by fetchContent under the hood, + // while the second call is done by fetchHubContent. We only care about the second call here + expect(fetchItemEnrichmentsSpy.calls.count()).toBe(2); + expect(fetchItemEnrichmentsSpy.calls.argsFor(1)[0]).toBe( + HOSTED_FEATURE_SERVICE_ITEM + ); + expect(fetchItemEnrichmentsSpy.calls.argsFor(1)[1]).toEqual(["metadata"]); + }); + + it("should not get schedule for request without a token", async () => { const getItemSpy = spyOn(portalModule, "getItem").and.returnValue( Promise.resolve(HOSTED_FEATURE_SERVICE_ITEM) );