-
Notifications
You must be signed in to change notification settings - Fork 0
/
admin_test.go
68 lines (57 loc) · 1.71 KB
/
admin_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
package themes
import (
"io"
"net/http/httptest"
"strings"
"testing"
radio "github.com/R-a-dio/valkyrie"
"github.com/R-a-dio/valkyrie/templates"
"github.com/R-a-dio/valkyrie/util"
"github.com/R-a-dio/valkyrie/website/admin"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
var adminInputs = []templates.TemplateSelectable{
admin.HomeInput{},
admin.PendingInput{},
admin.SongsInput{},
admin.SongsForm{},
admin.NewsInput{},
admin.NewsInputPost{},
admin.SelectedNewsMarkdown{Name: "body-render"},
admin.SelectedNewsMarkdown{Name: "header-render"},
admin.TitleNewsRender{},
admin.ProfileInput{},
admin.ProfileForm{},
admin.UsersInput{},
}
func TestAdminZeroInput(t *testing.T) {
status := util.NewStaticValue(radio.Status{})
tmpl, err := templates.FromDirectory(".", templates.NewStatefulFunctions(status))
require.NoError(t, err)
tmpl.Production = true
exec := tmpl.Executor()
req := httptest.NewRequest("GET", "/", nil)
for _, theme := range tmpl.ThemeNamesAdmin() {
if !strings.HasPrefix(string(theme), templates.ADMIN_PREFIX) {
continue
}
req = req.WithContext(templates.SetTheme(req.Context(), theme, true))
t.Run(string(theme), func(t *testing.T) {
for _, in := range adminInputs {
t.Run(in.TemplateBundle()+"/"+in.TemplateName(), func(t *testing.T) {
err := exec.Execute(io.Discard, req, in)
assert.NoError(t, err)
})
}
})
}
}
func TestAdminCSRFTokenInput(t *testing.T) {
status := util.NewStaticValue(radio.Status{})
tmpl, err := templates.FromDirectory(".", templates.NewStatefulFunctions(status))
require.NoError(t, err)
tmpl.Production = true
exec := tmpl.Executor()
runCSRFTokenTest(t, tmpl.ThemeNamesAdmin(), exec, adminInputs)
}