Skip to content

Commit

Permalink
feat(hub-common): add s123 url to context (#1439)
Browse files Browse the repository at this point in the history
  • Loading branch information
juliannaeapicella authored Mar 13, 2024
1 parent 2465da4 commit be5f99e
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 3 deletions.
17 changes: 17 additions & 0 deletions packages/common/src/ArcGISContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,11 @@ export interface IArcGISContext {
*/
orgThumbnailUrl: string;

/**
* Return the Survey123 url
*/
survey123Url: string;

/**
* Return the token for a given app, if defined
* @param app
Expand Down Expand Up @@ -815,6 +820,18 @@ export class ArcGISContext implements IArcGISContext {
return getOrgThumbnailUrl(this.portal, this.session?.token);
}

/**
* Return the survey123 url
*/
public get survey123Url(): string {
const suffixes: Partial<Record<HubEnvironment, string>> = {
qaext: "qa",
devext: "dev",
};
const suffix = suffixes[this.environment] ?? "";
return `https://survey123${suffix}.arcgis.com`;
}

/**
* Return a token for a specific app
* @param app
Expand Down
7 changes: 7 additions & 0 deletions packages/common/src/surveys/utils/get-s123-share-url.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { IArcGISContext } from "../../ArcGISContext";

export function getS123ShareUrl(id: string, context: IArcGISContext) {
return `${context.survey123Url}/share/${id}?portalUrl=${encodeURIComponent(
context.portalUrl
)}`;
}
1 change: 1 addition & 0 deletions packages/common/src/surveys/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export * from "./get-form-info-json";
export * from "./get-form-json";
export * from "./get-input-feature-service-model";
export * from "./get-map-question";
export * from "./get-s123-share-url";
export * from "./get-source-feature-service-model-from-fieldworker";
export * from "./get-stakeholder-model";
export * from "./get-survey-models";
Expand Down
21 changes: 19 additions & 2 deletions packages/common/test/ArcGISContextManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ describe("ArcGISContext:", () => {
expect(mgr.context.isAlphaOrg).toEqual(false);
expect(mgr.context.isBetaOrg).toEqual(false);
expect(mgr.context.orgThumbnailUrl).toBeNull();
expect(mgr.context.survey123Url).toEqual("https://survey123.arcgis.com");
});
it("verify alpha and beta orgs", async () => {
const mgr = await ArcGISContextManager.create({
Expand Down Expand Up @@ -694,6 +695,7 @@ describe("ArcGISContext:", () => {
expect(mgr.context.orgThumbnailUrl).toBe(
`${MOCK_AUTH.portal}/portals/FAKEID/resources/fake-thumbnail.jpg?token=${MOCK_AUTH.token}`
);
expect(mgr.context.survey123Url).toEqual("https://survey123.arcgis.com");
});
it("verify props update setting session after", async () => {
spyOn(portalModule, "getSelf").and.callFake(() => {
Expand Down Expand Up @@ -1127,6 +1129,7 @@ describe("ArcGISContext:", () => {
expect(mgr.context.discussionsServiceUrl).toBeUndefined();
expect(mgr.context.hubSearchServiceUrl).toBeUndefined();
expect(mgr.context.domainServiceUrl).toBeUndefined();
expect(mgr.context.survey123Url).toEqual("https://survey123.arcgis.com");
expect(mgr.context.hubLicense).toBe("enterprise-sites");
});
it("verify props when passed session", async () => {
Expand All @@ -1151,6 +1154,7 @@ describe("ArcGISContext:", () => {
MOCK_ENTERPRISE_AUTH.portal.replace(`/sharing/rest`, "")
);
expect(mgr.context.sharingApiUrl).toBe(MOCK_ENTERPRISE_AUTH.portal);
expect(mgr.context.survey123Url).toEqual("https://survey123.arcgis.com");
// Partnered orgs
expect(mgr.context.trustedOrgIds).toEqual([]);
expect(mgr.context.trustedOrgs).toEqual([]);
Expand Down Expand Up @@ -1180,20 +1184,27 @@ describe("ArcGISContext:", () => {
expect(mgr.context.portalUrl).toBe(
MOCK_ENTERPRISE_AUTH.portal.replace(`/sharing/rest`, "")
);
expect(mgr.context.survey123Url).toEqual("https://survey123.arcgis.com");
});
});
describe("extra coverage:", () => {
it("handles qaext hubUrl", async () => {
it("handles devext urls", async () => {
const mgr = await ArcGISContextManager.create({
portalUrl: "https://qaext.arcgis.com",
});
expect(mgr.context.hubUrl).toBe("https://hubqa.arcgis.com");
expect(mgr.context.survey123Url).toEqual(
"https://survey123qa.arcgis.com"
);
});
it("handles devext hubUrl", async () => {
it("handles devext urls", async () => {
const mgr = await ArcGISContextManager.create({
portalUrl: "https://devext.arcgis.com",
});
expect(mgr.context.hubUrl).toBe("https://hubdev.arcgis.com");
expect(mgr.context.survey123Url).toEqual(
"https://survey123dev.arcgis.com"
);
});
it("sign out on qa, resets portalUrl correctly", async () => {
const mgr = await ArcGISContextManager.create({
Expand All @@ -1203,6 +1214,9 @@ describe("ArcGISContext:", () => {
mgr.clearAuthentication();
expect(mgr.context.hubUrl).toBe("https://hubqa.arcgis.com");
expect(mgr.context.portalUrl).toBe("https://qaext.arcgis.com");
expect(mgr.context.survey123Url).toEqual(
"https://survey123qa.arcgis.com"
);
});
it("sign out on dev, resets portalUrl correctly", async () => {
const mgr = await ArcGISContextManager.create({
Expand All @@ -1212,6 +1226,9 @@ describe("ArcGISContext:", () => {
mgr.clearAuthentication();
expect(mgr.context.hubUrl).toBe("https://hubdev.arcgis.com");
expect(mgr.context.portalUrl).toBe("https://devext.arcgis.com");
expect(mgr.context.survey123Url).toEqual(
"https://survey123dev.arcgis.com"
);
});
it("handles ArcGISContext properties undefined", () => {
const ctx = new ArcGISContext({
Expand Down
2 changes: 1 addition & 1 deletion packages/common/test/surveys/edit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { MOCK_AUTH } from "../mocks/mock-auth";
import * as modelUtils from "../../src/models";
import { IModel } from "../../src/types";
import { deleteSurvey, updateSurvey } from "../../src/surveys/edit";
import { IHubSurvey } from "../../dist/types/core/types/IHubSurvey";
import * as getFormJsonUtil from "../../src/surveys/utils/get-form-json";
import { IHubSurvey } from "../../src/core/types/IHubSurvey";

const GUID = "9b77674e43cf4bbd9ecad5189b3f1fdc";

Expand Down
13 changes: 13 additions & 0 deletions packages/common/test/surveys/utils/get-s123-share-url.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { IArcGISContext } from "../../../src/ArcGISContext";
import { getS123ShareUrl } from "../../../src/surveys/utils/get-s123-share-url";

describe("getS123ShareUrl", () => {
it("gets url", () => {
const context = {
survey123Url: "survey-url",
portalUrl: "portal-url",
} as any as IArcGISContext;
const result = getS123ShareUrl("survey-id", context);
expect(result).toEqual("survey-url/share/survey-id?portalUrl=portal-url");
});
});

0 comments on commit be5f99e

Please sign in to comment.