-
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 composeHubContent() for creating an IHubEditabl…
…eContent from pre-fetched parts (#1630)
- Loading branch information
1 parent
1dd9a1f
commit 2626a26
Showing
3 changed files
with
97 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { IHubEditableContentEnrichments } from "../items/_enrichments"; | ||
import { IHubEditableContent } from "../core/types/IHubEditableContent"; | ||
import { normalizeItemType } from "./compose"; | ||
import { setProp } from "../objects/set-prop"; | ||
import { modelToHubEditableContent } from "./modelToHubEditableContent"; | ||
import { cloneObject } from "../util"; | ||
import { IItem } from "@esri/arcgis-rest-portal"; | ||
import { IHubRequestOptions } from "../types"; | ||
|
||
/** | ||
* composes a Hub content entity from an item and optional enrichments | ||
* @param item item to compose content from | ||
* @param requestOptions request options (needed to determine certain urls) | ||
* @param enrichments enrichments to use during composition | ||
* @returns content entity | ||
*/ | ||
export const composeHubContent = ( | ||
item: IItem, | ||
requestOptions: IHubRequestOptions, | ||
enrichments: IHubEditableContentEnrichments | ||
): IHubEditableContent => { | ||
// we must normalize the underlying item type to account | ||
// for older items (e.g. sites that are type "Web Mapping | ||
// Application") before we map the model to a Hub Entity | ||
const normalizedItem = cloneObject(item); | ||
const type = normalizeItemType(item); | ||
setProp("type", type, normalizedItem); | ||
|
||
return modelToHubEditableContent( | ||
{ item: normalizedItem }, | ||
requestOptions, | ||
enrichments | ||
); | ||
}; |
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,62 @@ | ||
import { | ||
HOSTED_FEATURE_SERVICE_DEFINITION, | ||
HOSTED_FEATURE_SERVICE_GUID, | ||
HOSTED_FEATURE_SERVICE_ITEM, | ||
PDF_GUID, | ||
PDF_ITEM, | ||
} from "./fixtures"; | ||
import { MOCK_AUTH } from "../mocks/mock-auth"; | ||
import { | ||
composeHubContent, | ||
IHubRequestOptions, | ||
IServiceExtendedProps, | ||
} from "../../src"; | ||
import { IHubEditableContentEnrichments } from "../../src/items/_enrichments"; | ||
import { IItem } from "@esri/arcgis-rest-portal"; | ||
|
||
describe("composeHubContent", () => { | ||
it("composes feature service content", () => { | ||
const requestOptions = { | ||
portal: MOCK_AUTH.portal, | ||
authentication: MOCK_AUTH, | ||
} as IHubRequestOptions; | ||
|
||
const enrichments: IHubEditableContentEnrichments = { | ||
server: HOSTED_FEATURE_SERVICE_DEFINITION, | ||
}; | ||
|
||
const chk = composeHubContent( | ||
HOSTED_FEATURE_SERVICE_ITEM, | ||
requestOptions, | ||
enrichments | ||
); | ||
const extendedProps = chk.extendedProps as IServiceExtendedProps; | ||
expect(chk.id).toBe(HOSTED_FEATURE_SERVICE_GUID); | ||
expect(chk.owner).toBe(HOSTED_FEATURE_SERVICE_ITEM.owner); | ||
expect(extendedProps.serverExtractCapability).toBeTruthy(); | ||
expect(extendedProps.serverQueryCapability).toBeTruthy(); | ||
}); | ||
|
||
it("composes non-service content", () => { | ||
const requestOptions = { authentication: MOCK_AUTH } as IHubRequestOptions; | ||
const enrichments: IHubEditableContentEnrichments = { metadata: null }; | ||
|
||
const chk = composeHubContent(PDF_ITEM, requestOptions, enrichments); | ||
expect(chk.id).toBe(PDF_GUID); | ||
expect(chk.owner).toBe(PDF_ITEM.owner); | ||
}); | ||
|
||
it("normalizes the item type", () => { | ||
const item = { | ||
id: "ae3", | ||
type: "Web Mapping Application", | ||
typeKeywords: ["hubSite"], | ||
} as IItem; | ||
const requestOptions = { authentication: MOCK_AUTH } as IHubRequestOptions; | ||
const enrichments: IHubEditableContentEnrichments = { metadata: null }; | ||
|
||
const chk = composeHubContent(item, requestOptions, enrichments); | ||
|
||
expect(chk.type).toBe("Hub Site Application"); | ||
}); | ||
}); |