Skip to content

Commit

Permalink
fix(hub-common): update spatial element from default dcat us template (
Browse files Browse the repository at this point in the history
  • Loading branch information
sansth1010 authored Jan 31, 2025
1 parent 98d11a7 commit 064deea
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/common/src/sites/feeds/_internal/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const DCAT_US_1X_DEFAULT = {
fn: "{{owner}}",
hasEmail: "{{orgContactEmail}}",
},
spatial: "{{extent}}",
spatial: "{{extent:computeSpatialProperty}}",
};

const DCAT_US_3X_DEFAULT = {
Expand Down
15 changes: 14 additions & 1 deletion packages/common/src/sites/feeds/getFeedTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,20 @@ function getDcatApConfig(feedsConfig: IFeedsConfiguration, version: string) {

function getDcatUsConfig(feedsConfig: IFeedsConfiguration, version: string) {
if (getMajorVersion(version) === "1") {
return feedsConfig.dcatUS1X || feedsConfig.dcatUS11;
const dcatUsConfig = feedsConfig.dcatUS1X || feedsConfig.dcatUS11;
// Some sites may have dcat us config with invalid
// extent value for spatial property i.e. '{{extent}}'
//
// Following fixes that by replacing invalid default extent
// value to valid one i.e. '{{{extent:computeSpatialProperty}}'
if (
dcatUsConfig &&
typeof dcatUsConfig.spatial === "string" &&
dcatUsConfig.spatial.replace(/\s/g, "") === "{{extent}}"
) {
dcatUsConfig.spatial = "{{extent:computeSpatialProperty}}";
}
return dcatUsConfig;
}

if (getMajorVersion(version) === "3") {
Expand Down
16 changes: 16 additions & 0 deletions packages/common/test/sites/feeds/getFeedTemplate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,22 @@ describe("getFeedTemplate", () => {
const chk = getFeedTemplate({ feedsConfig, format, version });
expect(chk).toEqual(dcatUsConfig);
});
it("gets DCAT US configuration containing spatial field with valid extent value", async () => {
const dcatUsConfig = {
title: "{{title}}",
spatial: " {{ extent }} ",
};
const feedsConfig: IFeedsConfiguration = {
dcatUS1X: dcatUsConfig,
};
const format: FeedFormat = "dcat-us";
const version = "1.1";
const chk = getFeedTemplate({ feedsConfig, format, version });
expect(chk).toEqual(dcatUsConfig);
expect(chk).toBeDefined();
expect(chk.spatial).toEqual("{{extent:computeSpatialProperty}}");
expect(chk.title).toEqual("{{title}}");
});
it("throws error if DCAT US version is not supported", async () => {
const dcatUsConfig = {
title: "{{title}}",
Expand Down

0 comments on commit 064deea

Please sign in to comment.