-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathwebmention_test.go
77 lines (61 loc) · 1.86 KB
/
webmention_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package main
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func Test_webmentions(t *testing.T) {
app := &goBlog{
cfg: createDefaultTestConfig(t),
}
app.cfg.Server.PublicAddress = "https://example.com"
app.cfg.Blogs = map[string]*configBlog{
"en": {
Lang: "en",
},
}
_ = app.initConfig(false)
_ = app.db.insertWebmention(&mention{
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.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)
exists := app.db.webmentionExists(&mention{Source: "Https://Example.net/test", Target: "Https://Example.com/TÄst"})
assert.True(t, exists)
mentions = app.getWebmentionsByAddress("https://example.com/täst")
assert.Len(t, mentions, 0)
mentions = app.getWebmentionsByAddress("")
assert.Len(t, mentions, 0)
mentions, err = app.getWebmentions(&webmentionsRequestConfig{
sourcelike: "example.net",
})
require.NoError(t, err)
if assert.Len(t, mentions, 1) {
_ = app.db.approveWebmentionId(mentions[0].ID)
}
mentions = app.getWebmentionsByAddress("https://example.com/täst")
assert.Len(t, mentions, 1)
mentions = app.getWebmentionsByAddress("https://example.com/t%C3%A4st")
assert.Len(t, mentions, 1)
err = app.db.deleteWebmention(&mention{
Source: "https://example.net/test",
Target: "https://example.com/T%C3%84ST",
})
assert.NoError(t, err)
mentions = app.getWebmentionsByAddress("https://example.com/täst")
assert.Len(t, mentions, 0)
}