From b573236cbfe30c36ddbd24a9850ffdbefb13df11 Mon Sep 17 00:00:00 2001 From: Paul Robert Lloyd Date: Tue, 16 Jan 2024 23:55:51 +0000 Subject: [PATCH] fix: only add references property if references found --- lib/fetch-references.js | 5 ++++- test/index.js | 29 +++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/lib/fetch-references.js b/lib/fetch-references.js index ca1bb8c..9a213d3 100644 --- a/lib/fetch-references.js +++ b/lib/fetch-references.js @@ -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) { + jf2.references = references; + } return jf2; }; diff --git a/test/index.js b/test/index.js index 6ae27a1..5ba85df 100644 --- a/test/index.js +++ b/test/index.js @@ -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", }, }, ], @@ -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", @@ -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, + ); + }); });