2021-08-09 11:09:45 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func Test_webmentions(t *testing.T) {
|
|
|
|
app := &goBlog{
|
2022-07-16 19:09:43 +00:00
|
|
|
cfg: createDefaultTestConfig(t),
|
|
|
|
}
|
|
|
|
app.cfg.Server.PublicAddress = "https://example.com"
|
|
|
|
app.cfg.Blogs = map[string]*configBlog{
|
|
|
|
"en": {
|
|
|
|
Lang: "en",
|
2021-08-09 11:09:45 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2022-07-16 19:09:43 +00:00
|
|
|
_ = app.initConfig(false)
|
2021-08-09 11:09:45 +00:00
|
|
|
|
2021-08-18 08:28:17 +00:00
|
|
|
_ = app.db.insertWebmention(&mention{
|
2021-08-09 11:09:45 +00:00
|
|
|
Source: "https://example.net/test",
|
|
|
|
Target: "https://example.com/täst",
|
|
|
|
Created: time.Now().Unix(),
|
|
|
|
Title: "Test-Title",
|
|
|
|
Content: "Test-Content",
|
|
|
|
Author: "Test-Author",
|
|
|
|
}, webmentionStatusVerified)
|
|
|
|
|
|
|
|
mentions, err := app.db.getWebmentions(&webmentionsRequestConfig{
|
|
|
|
sourcelike: "example.xyz",
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
assert.Len(t, mentions, 0)
|
|
|
|
|
|
|
|
count, err := app.db.countWebmentions(&webmentionsRequestConfig{
|
|
|
|
sourcelike: "example.net",
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
assert.Equal(t, 1, count)
|
|
|
|
|
2021-11-19 16:36:03 +00:00
|
|
|
exists := app.db.webmentionExists(&mention{Source: "Https://Example.net/test", Target: "Https://Example.com/TÄst"})
|
2021-08-09 11:09:45 +00:00
|
|
|
assert.True(t, exists)
|
|
|
|
|
|
|
|
mentions = app.db.getWebmentionsByAddress("https://example.com/täst")
|
|
|
|
assert.Len(t, mentions, 0)
|
|
|
|
|
2021-11-22 15:56:40 +00:00
|
|
|
mentions = app.db.getWebmentionsByAddress("")
|
|
|
|
assert.Len(t, mentions, 0)
|
|
|
|
|
2021-08-09 11:09:45 +00:00
|
|
|
mentions, err = app.db.getWebmentions(&webmentionsRequestConfig{
|
|
|
|
sourcelike: "example.net",
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
if assert.Len(t, mentions, 1) {
|
2021-11-19 16:36:03 +00:00
|
|
|
_ = app.db.approveWebmentionId(mentions[0].ID)
|
2021-08-09 11:09:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
mentions = app.db.getWebmentionsByAddress("https://example.com/täst")
|
|
|
|
assert.Len(t, mentions, 1)
|
|
|
|
|
2022-03-28 16:02:16 +00:00
|
|
|
mentions = app.db.getWebmentionsByAddress("https://example.com/t%C3%A4st")
|
|
|
|
assert.Len(t, mentions, 1)
|
|
|
|
|
2022-03-31 12:55:36 +00:00
|
|
|
err = app.db.deleteWebmention(&mention{
|
2022-03-28 16:02:16 +00:00
|
|
|
Source: "https://example.net/test",
|
|
|
|
Target: "https://example.com/T%C3%84ST",
|
|
|
|
})
|
2022-03-31 12:55:36 +00:00
|
|
|
assert.NoError(t, err)
|
2022-03-28 16:02:16 +00:00
|
|
|
|
|
|
|
mentions = app.db.getWebmentionsByAddress("https://example.com/täst")
|
|
|
|
assert.Len(t, mentions, 0)
|
|
|
|
|
2021-08-09 11:09:45 +00:00
|
|
|
}
|