notify.moe/main_test.go

124 lines
2.5 KiB
Go
Raw Normal View History

2017-06-22 14:08:34 +00:00
package main
import (
"net/http"
"net/http/httptest"
2019-06-02 03:30:25 +00:00
"strings"
2017-06-22 14:08:34 +00:00
"testing"
2024-03-12 11:56:30 +00:00
"git.akyoto.dev/go/assert"
2019-06-03 09:32:43 +00:00
"github.com/animenotifier/notify.moe/arn"
"github.com/animenotifier/notify.moe/server"
2018-03-27 23:32:49 +00:00
"github.com/animenotifier/notify.moe/utils/routetests"
2017-06-22 14:08:34 +00:00
)
2018-04-25 21:45:11 +00:00
func TestRoutes(t *testing.T) {
app := server.New()
2019-06-01 15:28:22 +00:00
app.BindMiddleware()
2017-06-22 14:08:34 +00:00
2018-03-21 19:22:57 +00:00
// Iterate through every route
2018-03-27 23:32:49 +00:00
for _, examples := range routetests.All() {
2018-03-21 19:22:57 +00:00
// Iterate through every example specified for that route
2017-06-25 10:05:32 +00:00
for _, example := range examples {
fetch(t, app, example)
2017-10-01 22:31:44 +00:00
}
}
}
2018-04-25 21:45:11 +00:00
func TestAnime(t *testing.T) {
app := server.New()
2019-06-01 15:28:22 +00:00
app.BindMiddleware()
2018-04-25 21:45:11 +00:00
for anime := range arn.StreamAnime() {
2020-02-12 04:17:29 +00:00
if anime.IsDraft {
continue
}
2019-11-19 06:19:25 +00:00
assert.True(t, anime.Title.Canonical != "")
fetch(t, app, anime.Link())
2018-04-25 21:45:11 +00:00
}
}
func TestSoundTracks(t *testing.T) {
app := server.New()
2019-06-01 15:28:22 +00:00
app.BindMiddleware()
2018-04-25 21:45:11 +00:00
for soundtrack := range arn.StreamSoundTracks() {
2018-11-08 17:34:04 +00:00
assert.NotNil(t, soundtrack.Creator())
2019-11-19 06:19:25 +00:00
fetch(t, app, soundtrack.Link())
2018-04-25 21:45:11 +00:00
}
}
func TestAMVs(t *testing.T) {
app := server.New()
2019-06-01 15:28:22 +00:00
app.BindMiddleware()
2018-04-25 21:45:11 +00:00
for amv := range arn.StreamAMVs() {
2018-11-08 17:34:04 +00:00
assert.NotNil(t, amv.Creator())
2019-11-19 06:19:25 +00:00
fetch(t, app, amv.Link())
2018-04-25 21:45:11 +00:00
}
}
func TestCompanies(t *testing.T) {
app := server.New()
2019-06-01 15:28:22 +00:00
app.BindMiddleware()
2018-04-25 21:45:11 +00:00
for company := range arn.StreamCompanies() {
fetch(t, app, company.Link())
2018-04-25 21:45:11 +00:00
}
}
func TestThreads(t *testing.T) {
app := server.New()
2019-06-01 15:28:22 +00:00
app.BindMiddleware()
2018-04-25 21:45:11 +00:00
for thread := range arn.StreamThreads() {
2018-11-08 17:34:04 +00:00
assert.NotNil(t, thread.Creator())
2019-11-19 06:19:25 +00:00
fetch(t, app, thread.Link())
2018-04-25 21:45:11 +00:00
}
}
func TestPosts(t *testing.T) {
app := server.New()
2019-06-01 15:28:22 +00:00
app.BindMiddleware()
2018-04-25 21:45:11 +00:00
for post := range arn.StreamPosts() {
2018-11-08 17:34:04 +00:00
assert.NotNil(t, post.Creator())
2019-11-19 06:19:25 +00:00
fetch(t, app, post.Link())
2018-04-25 21:45:11 +00:00
}
}
func TestQuotes(t *testing.T) {
app := server.New()
2019-06-01 15:28:22 +00:00
app.BindMiddleware()
2018-04-25 21:45:11 +00:00
for quote := range arn.StreamQuotes() {
2018-11-08 17:34:04 +00:00
assert.NotNil(t, quote.Creator())
2021-11-22 09:58:13 +00:00
fetch(t, app, quote.Link())
2018-04-25 21:45:11 +00:00
}
}
2019-11-19 06:19:25 +00:00
func TestUsers(t *testing.T) {
app := server.New()
app.BindMiddleware()
2019-11-19 05:20:18 +00:00
2019-11-19 06:19:25 +00:00
for user := range arn.StreamUsers() {
assert.True(t, user.Nick != "")
// fetch(t, app, user.Link())
}
}
2018-04-25 22:06:13 +00:00
func fetch(t *testing.T, app http.Handler, route string) {
2019-06-02 03:30:25 +00:00
request := httptest.NewRequest("GET", strings.ReplaceAll(route, " ", "%20"), nil)
2019-06-01 15:28:22 +00:00
response := httptest.NewRecorder()
app.ServeHTTP(response, request)
status := response.Code
2018-04-25 21:45:11 +00:00
switch status {
2019-06-03 09:36:59 +00:00
case http.StatusOK, http.StatusTemporaryRedirect, http.StatusPermanentRedirect:
// OK
2018-04-25 21:45:11 +00:00
default:
2019-06-05 07:18:04 +00:00
t.Fatalf("%s | Wrong status code | %v instead of %v", route, status, http.StatusOK)
2018-04-25 21:45:11 +00:00
}
}