hi there! test discovering: single. Nice!
+this one is a pingback-only single one. Not good!
+another cool link: multiple
]]> diff --git a/test/__mocks__/link-discover-bothtypes.html b/test/__mocks__/link-discover-bothtypes.html new file mode 100644 index 0000000..f56b990 --- /dev/null +++ b/test/__mocks__/link-discover-bothtypes.html @@ -0,0 +1,12 @@ + + +... + + +... + + +.... +... + + diff --git a/test/__mocks__/pingback-discover-test-headers.json b/test/__mocks__/pingback-discover-test-headers.json new file mode 100644 index 0000000..ac1d99f --- /dev/null +++ b/test/__mocks__/pingback-discover-test-headers.json @@ -0,0 +1,3 @@ +{ + "X-Pingback": "http://aaronpk.example/pingback-endpoint" +} \ No newline at end of file diff --git a/test/__mocks__/pingback-discover-test-multiple.html b/test/__mocks__/pingback-discover-test-multiple.html new file mode 100644 index 0000000..e8b6f85 --- /dev/null +++ b/test/__mocks__/pingback-discover-test-multiple.html @@ -0,0 +1,12 @@ + + +... + +... + + +.... +pingback +... + + diff --git a/test/__mocks__/pingback-discover-test-single.html b/test/__mocks__/pingback-discover-test-single.html new file mode 100644 index 0000000..b82f340 --- /dev/null +++ b/test/__mocks__/pingback-discover-test-single.html @@ -0,0 +1,11 @@ + + +... +... + + +.... +pingback +... + + diff --git a/test/__mocks__/pingback-discover-test.html b/test/__mocks__/pingback-discover-test.html new file mode 100644 index 0000000..e8b6f85 --- /dev/null +++ b/test/__mocks__/pingback-discover-test.html @@ -0,0 +1,12 @@ + + +... + +... + + +.... +pingback +... + + diff --git a/test/linkdiscoverer.test.js b/test/linkdiscoverer.test.js index 9eb47f5..4a3bb6d 100644 --- a/test/linkdiscoverer.test.js +++ b/test/linkdiscoverer.test.js @@ -3,6 +3,45 @@ const { discover } = require('../src/linkdiscoverer') describe("link discoverer", () => { + test("discover nothing if no link is present", async() => { + const result = await discover("https://brainbaking.com/link-discover-test-none.html") + expect(result).toBeUndefined() + }) + + test("prefer webmentions over pingbacks if both links are present", async () => { + const result = await discover("https://brainbaking.com/link-discover-bothtypes.html") + expect(result).toEqual({ + link: "http://aaronpk.example/webmention-endpoint", + type: "webmention" + }) + }) + + describe("discovers pingback links", () => { + test("discover link if present in header", async () => { + const result = await discover("https://brainbaking.com/pingback-discover-test.html") + expect(result).toEqual({ + link: "http://aaronpk.example/pingback-endpoint", + type: "pingback" + }) + }) + + test("discover link if sole entry somewhere in html", async () => { + const result = await discover("https://brainbaking.com/pingback-discover-test-single.html") + expect(result).toEqual({ + link: "http://aaronpk.example/pingback-endpoint-body", + type: "pingback" + }) + }) + + test("use link in header if multiple present in html", async () => { + const result = await discover("https://brainbaking.com/pingback-discover-test-multiple.html") + expect(result).toEqual({ + link: "http://aaronpk.example/pingback-endpoint-header", + type: "pingback" + }) + }) + }) + describe("discovers webmention links", () => { test("discover link if present in header", async () => { const result = await discover("https://brainbaking.com/link-discover-test.html") @@ -12,11 +51,6 @@ describe("link discoverer", () => { }) }) - test("discover nothing if no webmention link is present", async() => { - const result = await discover("https://brainbaking.com/link-discover-test-none.html") - expect(result).toBeUndefined() - }) - test("discover link if sole entry somewhere in html", async () => { const result = await discover("https://brainbaking.com/link-discover-test-single.html") expect(result).toEqual({ diff --git a/test/webmention/send.test.js b/test/webmention/send.test.js index 663ad71..241a8d0 100644 --- a/test/webmention/send.test.js +++ b/test/webmention/send.test.js @@ -5,13 +5,13 @@ const { send } = require('../../src/webmention/send') describe("webmention send scenarios", () => { - test("webmention send integration test", async () => { + test("webmention send integration test that can send both webmentions and pingbacks", async () => { got.post = jest.fn() // fetches index.xml await send("brainbaking.com", '2021-03-16T16:00:00.000Z') - expect(got.post).toHaveBeenCalledTimes(2) + expect(got.post).toHaveBeenCalledTimes(3) expect(got.post).toHaveBeenCalledWith("http://aaronpk.example/webmention-endpoint-header", { contentType: "x-www-form-urlencoded", form: { @@ -23,6 +23,25 @@ describe("webmention send scenarios", () => { methods: ["POST"] } }) + expect(got.post).toHaveBeenCalledWith("http://aaronpk.example/pingback-endpoint-body", { + contentType: "text/xml", + body: ` +