From ff1bd9b2c9517eb4a6b82a32c54ed0596025329d Mon Sep 17 00:00:00 2001 From: wgroeneveld Date: Tue, 9 Mar 2021 16:30:53 +0100 Subject: [PATCH] likes do not have content, separate out the type --- src/webmention/receive.js | 5 ++- test/__mocks__/valid-bridgy-like.html | 54 +++++++++++++++++++++++++ test/webmention/receive-process.test.js | 31 +++++++++++++- 3 files changed, 88 insertions(+), 2 deletions(-) create mode 100644 test/__mocks__/valid-bridgy-like.html diff --git a/src/webmention/receive.js b/src/webmention/receive.js index 213ce8a..9bd9a57 100644 --- a/src/webmention/receive.js +++ b/src/webmention/receive.js @@ -72,7 +72,7 @@ function publishedNow() { function parseBodyAsIndiewebSite(source, target, hEntry) { function shorten(txt) { - if(txt.length <= 250) return txt + if(!txt || txt.length <= 250) return txt return txt.substring(0, 250) + "..." } @@ -85,6 +85,7 @@ function parseBodyAsIndiewebSite(source, target, hEntry) { const publishedDate = hEntry.properties?.published?.[0] const uid = hEntry.properties?.uid?.[0] const url = hEntry.properties?.url?.[0] + const type = hEntry.properties?.["like-of"]?.length ? "like" : "mention" return { author: { @@ -94,6 +95,7 @@ function parseBodyAsIndiewebSite(source, target, hEntry) { name: name, content: summary ? shorten(summary) : shorten(contentEntry), published: publishedDate ? publishedDate : publishedNow(), + type, // Mastodon uids start with "tag:server", but we do want indieweb uids from other sources url: uid && uid.startsWith("http") ? uid : (url ? url : source), source, @@ -112,6 +114,7 @@ function parseBodyAsNonIndiewebSite(source, target, body) { content: title, published: publishedNow(), url: source, + type: "mention", source, target } diff --git a/test/__mocks__/valid-bridgy-like.html b/test/__mocks__/valid-bridgy-like.html new file mode 100644 index 0000000..6a5389f --- /dev/null +++ b/test/__mocks__/valid-bridgy-like.html @@ -0,0 +1,54 @@ + + + + + +Stampeding Longhorn + + +
+ tag:chat.brainbaking.com,2013:A4nx1rFwKUJYSe4TqK_favorited_by_A4nwg4LYyh4WgrJOXg + + + + + + + Stampeding Longhorn + + StampedingLonghorn + + + + +
+ + +
+ + + + + + + + + +
+ + diff --git a/test/webmention/receive-process.test.js b/test/webmention/receive-process.test.js index 7c27902..1e49ca7 100644 --- a/test/webmention/receive-process.test.js +++ b/test/webmention/receive-process.test.js @@ -26,6 +26,32 @@ describe("receive webmention process tests happy path", () => { return `${dumpdir}/` + md5(`source=${body.source},target=${body.target}`) } + test("receive a brid.gy webmention like", async () => { + const body = { + source: "https://brainbaking.com/valid-bridgy-like.html", + // wrapped in a a class="u-like-of" tag + target: "https://brainbaking.com/valid-indieweb-target.html" + } + await receive(body) + + const result = await fsp.readFile(`${asFilename(body)}.json`, 'utf-8') + const data = JSON.parse(result) + + expect(data).toEqual({ + author: { + name: "Stampeding Longhorn", + picture: "https://cdn.social.linux.pizza/v1/AUTH_91eb37814936490c95da7b85993cc2ff/sociallinuxpizza/accounts/avatars/000/185/996/original/9e36da0c093cfc9b.png" + }, + url: "https://chat.brainbaking.com/notice/A4nx1rFwKUJYSe4TqK#favorited-by-A4nwg4LYyh4WgrJOXg", + name: "", + type: "like", + source: body.source, + target: body.target, + // no dates in bridgy-to-mastodon likes... + published: "2020-01-01T01:00:00" + }) + }) + test("receive a brid.gy webmention that has a url and photo without value", async () => { const body = { source: "https://brainbaking.com/valid-bridgy-source.html", @@ -44,12 +70,12 @@ describe("receive webmention process tests happy path", () => { url: "https://social.linux.pizza/@StampedingLonghorn/105821099684887793", content: "@wouter The cat pictures are awesome. for jest tests!", name: "@wouter The cat pictures are awesome. for jest tests!", + type: "mention", source: body.source, target: body.target, published: "2021-03-02T16:17:18.000Z" }) }) - test("receive saves a JSON file of indieweb-metadata if all is valid", async () => { const body = { source: "https://brainbaking.com/valid-indieweb-source.html", @@ -68,6 +94,7 @@ describe("receive webmention process tests happy path", () => { url: "https://brainbaking.com/notes/2021/03/06h12m41s48/", content: "This is cool, I just found out about valid indieweb target - so cool", name: "I just learned about https://www.inklestudios.com/...", + type: "mention", source: body.source, target: body.target, published: "2021-03-06T12:41:00" @@ -92,6 +119,7 @@ describe("receive webmention process tests happy path", () => { url: "https://brainbaking.com/notes/2021/03/06h12m41s48/", name: "I just learned about https://www.inklestudios.com/...", content: "This is cool, this is a summary!", + type: "mention", source: body.source, target: body.target, published: "2021-03-06T12:41:00" @@ -114,6 +142,7 @@ describe("receive webmention process tests happy path", () => { }, content: "Diablo 2 Twenty Years Later: A Retrospective | Jefklaks Codex", name: "Diablo 2 Twenty Years Later: A Retrospective | Jefklaks Codex", + type: "mention", url: body.source, source: body.source, target: body.target,