Skip to content

Commit

Permalink
fix(endpoint-posts): don’t return useless location property
Browse files Browse the repository at this point in the history
  • Loading branch information
paulrobertlloyd committed Jan 20, 2024
1 parent a2da82c commit 0778519
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
13 changes: 8 additions & 5 deletions packages/endpoint-posts/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,22 @@ export const getGeoValue = (location) => {
* @returns {object} JF2 location property
*/
export const getLocationProperty = (values) => {
const { location, geo } = values;
const { geo, location } = values;

const hasGeo = geo && geo.length > 0;
const hasLocation = location && Object.entries(sanitise(location)).length > 0;

// Determine Microformat type
if (location && location.name) {
if (hasLocation && location.name) {
location.type = "card";
} else if (location) {
} else if (hasLocation && !hasGeo) {
location.type = "adr";
}

// Add (or use) any provided geo location properties
if (location && geo) {
if (hasLocation && hasGeo) {
location.geo = getGeoProperty(geo);
} else if (geo) {
} else if (hasGeo) {
return getGeoProperty(geo);
}

Expand Down
14 changes: 14 additions & 0 deletions packages/endpoint-posts/test/unit/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,20 @@ describe("endpoint-posts/lib/utils", () => {
});
});

it("Returns empty object if location property is empty", () => {
assert.deepEqual(
getLocationProperty({
location: {
"street-address": "",
locality: "",
"postal-code": "",
},
geo: "",
}),
{},
);
});

it("Gets post name", () => {
const post = { name: "My favourite sandwich" };

Expand Down

0 comments on commit 0778519

Please sign in to comment.