From c80adf4bf3c74f70604d2387813db361c912f0d7 Mon Sep 17 00:00:00 2001 From: Jan-Lukas Else Date: Mon, 28 Nov 2022 20:45:57 +0100 Subject: [PATCH] Add test for Bridgy likes --- testdata/bridgymastodon.html | 29 +++++++++++++++++++++++++++ webmentionVerification_test.go | 36 ++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 testdata/bridgymastodon.html diff --git a/testdata/bridgymastodon.html b/testdata/bridgymastodon.html new file mode 100644 index 0000000..adfaf93 --- /dev/null +++ b/testdata/bridgymastodon.html @@ -0,0 +1,29 @@ + + + + + +Bridgy Response + +
+ tag:example.com,2013:109404425715413954_favorited_by_327512 + + + + + Jan-Lukas Else + jle + + + +
+ +
+ + + + + +
+ + diff --git a/webmentionVerification_test.go b/webmentionVerification_test.go index d96643c..cbb6e4d 100644 --- a/webmentionVerification_test.go +++ b/webmentionVerification_test.go @@ -87,6 +87,42 @@ func Test_verifyMentionBridgy(t *testing.T) { require.Equal(t, "m4rk", m.Author) } +func Test_verifyMastodonLikeBridgy(t *testing.T) { + + testHtmlBytes, err := os.ReadFile("testdata/bridgymastodon.html") + require.NoError(t, err) + testHtml := string(testHtmlBytes) + + mockClient := newFakeHttpClient() + mockClient.setFakeResponse(http.StatusOK, testHtml) + + app := &goBlog{ + httpClient: mockClient.Client, + cfg: createDefaultTestConfig(t), + d: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + // do nothing + }), + } + app.cfg.Server.PublicAddress = "https://example.org" + + _ = app.initConfig(false) + + m := &mention{ + Source: "https://example.com/@abc/109404425715413954#favorited-by-327512", + Target: "https://example.org/notes/2022-11-25-yijsn", + } + + err = app.verifyMention(m) + require.NoError(t, err) + + require.Equal(t, "https://example.org/notes/2022-11-25-yijsn", m.Target) + require.Equal(t, "https://example.com/@abc/109404425715413954#favorited-by-327512", m.Source) + require.Equal(t, "https://example.com/@abc/109404425715413954#favorited-by-327512", m.Url) + require.Equal(t, "Bridgy Response", m.Title) + require.Equal(t, "", m.Content) + require.Equal(t, "Jan-Lukas Else", m.Author) +} + func Test_verifyMentionColin(t *testing.T) { testHtmlBytes, err := os.ReadFile("testdata/colin.html")