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