Skip to content

Commit

Permalink
fix: only add references property if references found
Browse files Browse the repository at this point in the history
  • Loading branch information
paulrobertlloyd committed Jan 16, 2024
1 parent 90d0f69 commit b573236
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/fetch-references.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ export const fetchReferences = async (jf2) => {
};
}

jf2.references = references;
// Only add `references` property if references found
if (Object.entries(references).length !== 0) {

Check failure on line 51 in lib/fetch-references.js

View workflow job for this annotation

GitHub Actions / test (20.x)

Use `.length > 0` when checking length is not zero
jf2.references = references;
}

return jf2;
};
29 changes: 29 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,7 @@ describe("mf2tojf2", () => {
published: ["2019-02-12T10:00:00.000+00:00"],
url: ["https://website.example/bookmarks/lunch"],
"bookmark-of": ["https://another.example/notes/lunch"],
"mp-syndicate-to": "https://example.social/@username",
},
},
],
Expand All @@ -629,6 +630,7 @@ describe("mf2tojf2", () => {
published: "2019-02-12T10:00:00.000+00:00",
url: "https://website.example/bookmarks/lunch",
"bookmark-of": "https://another.example/notes/lunch",
"mp-syndicate-to": "https://example.social/@username",
references: {
"https://another.example/notes/lunch": {
type: "entry",
Expand All @@ -646,4 +648,31 @@ describe("mf2tojf2", () => {
expected,
);
});

it("Doesn’t add references", async () => {
const expected = await mf2tojf2referenced({
items: [
{
type: ["h-entry"],
properties: {
name: ["What my friend ate for lunch yesterday"],
published: ["2019-02-12T10:00:00.000+00:00"],
url: ["https://website.example/bookmarks/lunch"],
"mp-syndicate-to": "https://example.social/@username",
},
},
],
});

assert.deepEqual(
{
type: "entry",
name: "What my friend ate for lunch yesterday",
published: "2019-02-12T10:00:00.000+00:00",
url: "https://website.example/bookmarks/lunch",
"mp-syndicate-to": "https://example.social/@username",
},
expected,
);
});
});

0 comments on commit b573236

Please sign in to comment.