|
|
|
@ -193,7 +193,7 @@ func TestPersistWebmention(t *testing.T) { |
|
|
|
|
func TestAddWebmentionCreatesFile(t *testing.T) { |
|
|
|
|
repo := getTestRepo() |
|
|
|
|
repo.Retriever = &MockHttpRetriever{} |
|
|
|
|
repo.Parser = &MockMicroformatParser{} |
|
|
|
|
repo.Parser = &MockHttpParser{} |
|
|
|
|
user, _ := repo.CreateUser("testuser") |
|
|
|
|
post, _ := user.CreateNewPost("testpost") |
|
|
|
|
|
|
|
|
@ -211,7 +211,7 @@ func TestAddWebmentionCreatesFile(t *testing.T) { |
|
|
|
|
func TestAddWebmentionNotOverwritingFile(t *testing.T) { |
|
|
|
|
repo := getTestRepo() |
|
|
|
|
repo.Retriever = &MockHttpRetriever{} |
|
|
|
|
repo.Parser = &MockMicroformatParser{} |
|
|
|
|
repo.Parser = &MockHttpParser{} |
|
|
|
|
user, _ := repo.CreateUser("testuser") |
|
|
|
|
post, _ := user.CreateNewPost("testpost") |
|
|
|
|
|
|
|
|
@ -241,7 +241,7 @@ func TestAddWebmentionNotOverwritingFile(t *testing.T) { |
|
|
|
|
func TestAddWebmentionAddsParsedTitle(t *testing.T) { |
|
|
|
|
repo := getTestRepo() |
|
|
|
|
repo.Retriever = &MockHttpRetriever{} |
|
|
|
|
repo.Parser = &MockMicroformatParser{} |
|
|
|
|
repo.Parser = &MockHttpParser{} |
|
|
|
|
user, _ := repo.CreateUser("testuser") |
|
|
|
|
post, _ := user.CreateNewPost("testpost") |
|
|
|
|
|
|
|
|
@ -303,3 +303,52 @@ func TestApprovedWebmentions(t *testing.T) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func TestScanningForLinks(t *testing.T) { |
|
|
|
|
repo := getTestRepo() |
|
|
|
|
user, _ := repo.CreateUser("testuser") |
|
|
|
|
post, _ := user.CreateNewPost("testpost") |
|
|
|
|
|
|
|
|
|
content := "---\n" |
|
|
|
|
content += "title: test\n" |
|
|
|
|
content += "date: Wed, 17 Aug 2022 10:50:02 +0000\n" |
|
|
|
|
content += "---\n" |
|
|
|
|
content += "\n" |
|
|
|
|
content += "[Hello](https://example.com/hello)\n" |
|
|
|
|
os.WriteFile(post.ContentFile(), []byte(content), 0644) |
|
|
|
|
|
|
|
|
|
post.ScanForLinks() |
|
|
|
|
webmentions := post.OutgoingWebmentions() |
|
|
|
|
if len(webmentions) != 1 { |
|
|
|
|
t.Errorf("Expected 1 webmention, got %d", len(webmentions)) |
|
|
|
|
} |
|
|
|
|
if webmentions[0].Target != "https://example.com/hello" { |
|
|
|
|
t.Errorf("Expected target: %s, got %s", "https://example.com/hello", webmentions[0].Target) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func TestScanningForLinksDoesNotAddDuplicates(t *testing.T) { |
|
|
|
|
repo := getTestRepo() |
|
|
|
|
user, _ := repo.CreateUser("testuser") |
|
|
|
|
post, _ := user.CreateNewPost("testpost") |
|
|
|
|
|
|
|
|
|
content := "---\n" |
|
|
|
|
content += "title: test\n" |
|
|
|
|
content += "date: Wed, 17 Aug 2022 10:50:02 +0000\n" |
|
|
|
|
content += "---\n" |
|
|
|
|
content += "\n" |
|
|
|
|
content += "[Hello](https://example.com/hello)\n" |
|
|
|
|
content += "[Hello](https://example.com/hello)\n" |
|
|
|
|
os.WriteFile(post.ContentFile(), []byte(content), 0644) |
|
|
|
|
|
|
|
|
|
post.ScanForLinks() |
|
|
|
|
post.ScanForLinks() |
|
|
|
|
post.ScanForLinks() |
|
|
|
|
webmentions := post.OutgoingWebmentions() |
|
|
|
|
if len(webmentions) != 1 { |
|
|
|
|
t.Errorf("Expected 1 webmention, got %d", len(webmentions)) |
|
|
|
|
} |
|
|
|
|
if webmentions[0].Target != "https://example.com/hello" { |
|
|
|
|
t.Errorf("Expected target: %s, got %s", "https://example.com/hello", webmentions[0].Target) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|