238 lines
4.7 KiB
Go
Raw Normal View History

2017-06-14 20:13:30 +00:00
package main
2017-06-30 16:12:14 +00:00
import (
"errors"
"reflect"
"github.com/aerogo/api"
"github.com/animenotifier/arn"
)
var routeTests = map[string][]string{
2017-06-14 20:13:30 +00:00
// User
2017-06-21 18:33:57 +00:00
"/user/:nick": []string{
2017-06-14 20:13:30 +00:00
"/+Akyoto",
2017-06-21 18:33:57 +00:00
},
2017-06-14 20:13:30 +00:00
2017-06-21 18:33:57 +00:00
"/user/:nick/threads": []string{
2017-06-14 20:13:30 +00:00
"/+Akyoto/threads",
2017-06-21 18:33:57 +00:00
},
2017-06-14 20:13:30 +00:00
2017-06-23 15:15:48 +00:00
"/user/:nick/posts": []string{
"/+Akyoto/posts",
},
2017-06-30 16:12:14 +00:00
"/user/:nick/tracks": []string{
"/+Akyoto/tracks",
},
2017-06-21 18:33:57 +00:00
"/user/:nick/animelist": []string{
2017-06-20 12:16:23 +00:00
"/+Akyoto/animelist",
2017-06-21 18:33:57 +00:00
},
2017-06-20 12:16:23 +00:00
2017-07-05 19:23:59 +00:00
"/user/:nick/animelist/anime/:id": []string{
2017-06-20 12:16:23 +00:00
"/+Akyoto/animelist/7929",
2017-06-21 18:33:57 +00:00
},
2017-06-20 12:16:23 +00:00
2017-07-05 19:23:59 +00:00
"/user/:nick/animelist/watching": []string{
"/+Akyoto/animelist/watching",
},
"/user/:nick/animelist/completed": []string{
"/+Akyoto/animelist/completed",
},
"/user/:nick/animelist/planned": []string{
"/+Akyoto/animelist/planned",
},
"/user/:nick/animelist/hold": []string{
"/+Akyoto/animelist/hold",
},
"/user/:nick/animelist/dropped": []string{
"/+Akyoto/animelist/dropped",
},
2017-06-14 20:13:30 +00:00
// Pages
2017-06-21 18:33:57 +00:00
"/anime/:id": []string{
2017-06-14 20:13:30 +00:00
"/anime/1",
2017-06-21 18:33:57 +00:00
},
2017-06-14 20:13:30 +00:00
2017-06-21 18:33:57 +00:00
"/threads/:id": []string{
2017-06-14 20:13:30 +00:00
"/threads/HJgS7c2K",
2017-06-21 18:33:57 +00:00
},
2017-06-14 20:13:30 +00:00
2017-06-21 18:33:57 +00:00
"/posts/:id": []string{
2017-06-14 20:13:30 +00:00
"/posts/B1RzshnK",
2017-06-21 18:33:57 +00:00
},
2017-06-14 20:13:30 +00:00
2017-06-21 18:33:57 +00:00
"/forum/:tag": []string{
2017-06-14 20:13:30 +00:00
"/forum/general",
2017-06-21 18:33:57 +00:00
},
2017-06-14 20:13:30 +00:00
2017-06-21 18:33:57 +00:00
"/search/:term": []string{
2017-06-21 00:02:30 +00:00
"/search/Dragon Ball",
2017-06-21 18:33:57 +00:00
},
2017-06-21 00:02:30 +00:00
2017-06-30 16:12:14 +00:00
"/tracks/:id": []string{
"/tracks/h0ac8sKkg",
},
2017-06-14 20:13:30 +00:00
// API
2017-06-21 18:33:57 +00:00
"/api/anime/:id": []string{
2017-06-14 20:13:30 +00:00
"/api/anime/1",
2017-06-21 18:33:57 +00:00
},
2017-06-14 20:13:30 +00:00
2017-06-21 18:33:57 +00:00
"/api/thread/:id": []string{
2017-06-14 20:13:30 +00:00
"/api/thread/HJgS7c2K",
2017-06-21 18:33:57 +00:00
},
2017-06-14 20:13:30 +00:00
2017-06-21 18:33:57 +00:00
"/api/post/:id": []string{
2017-06-14 20:13:30 +00:00
"/api/post/B1RzshnK",
2017-06-21 18:33:57 +00:00
},
2017-06-14 20:13:30 +00:00
2017-06-21 18:33:57 +00:00
"/api/animelist/:id": []string{
2017-06-14 20:13:30 +00:00
"/api/animelist/4J6qpK1ve",
2017-06-21 18:33:57 +00:00
},
2017-06-14 20:13:30 +00:00
2017-06-23 15:15:48 +00:00
"/api/animelist/:id/get/:item": []string{
"/api/animelist/4J6qpK1ve/get/7929",
},
"/api/animelist/:id/get/:item/:property": []string{
"/api/animelist/4J6qpK1ve/get/7929/Episodes",
},
2017-06-21 18:33:57 +00:00
"/api/settings/:id": []string{
2017-06-14 20:13:30 +00:00
"/api/settings/4J6qpK1ve",
2017-06-21 18:33:57 +00:00
},
2017-06-14 20:13:30 +00:00
2017-06-21 18:33:57 +00:00
"/api/user/:id": []string{
2017-06-14 20:13:30 +00:00
"/api/user/4J6qpK1ve",
2017-06-21 18:33:57 +00:00
},
2017-06-14 20:13:30 +00:00
2017-06-21 18:33:57 +00:00
"/api/emailtouser/:id": []string{
2017-06-16 22:33:27 +00:00
"/api/emailtouser/e.urbach@gmail.com",
2017-06-21 18:33:57 +00:00
},
2017-06-16 22:33:27 +00:00
2017-06-21 18:33:57 +00:00
"/api/googletouser/:id": []string{
2017-06-16 22:33:27 +00:00
"/api/googletouser/106530160120373282283",
2017-06-21 18:33:57 +00:00
},
2017-06-16 22:33:27 +00:00
2017-07-03 20:50:04 +00:00
"/api/facebooktouser/:id": []string{
"/api/facebooktouser/10207576239700188",
},
2017-06-21 18:33:57 +00:00
"/api/nicktouser/:id": []string{
2017-06-16 22:33:27 +00:00
"/api/nicktouser/Akyoto",
2017-06-21 18:33:57 +00:00
},
2017-06-16 22:33:27 +00:00
2017-06-21 18:33:57 +00:00
"/api/searchindex/:id": []string{
2017-06-21 00:02:30 +00:00
"/api/searchindex/Anime",
2017-06-21 18:33:57 +00:00
},
2017-06-21 00:02:30 +00:00
2017-06-30 16:12:14 +00:00
"/api/analytics/:id": []string{
"/api/analytics/4J6qpK1ve",
},
"/api/soundtrack/:id": []string{
"/api/soundtrack/h0ac8sKkg",
},
"/api/soundcloudtosoundtrack/:id": []string{
"/api/soundcloudtosoundtrack/145918628",
},
"/api/youtubetosoundtrack/:id": []string{
"/api/youtubetosoundtrack/hU2wqJuOIp4",
},
2017-06-16 22:33:27 +00:00
// Images
2017-06-21 18:33:57 +00:00
"/images/avatars/large/:file": []string{
2017-06-18 12:52:50 +00:00
"/images/avatars/large/4J6qpK1ve.webp",
2017-06-21 18:33:57 +00:00
},
2017-06-18 12:52:50 +00:00
2017-06-21 18:33:57 +00:00
"/images/avatars/small/:file": []string{
2017-06-18 12:52:50 +00:00
"/images/avatars/small/4J6qpK1ve.webp",
2017-06-21 18:33:57 +00:00
},
2017-06-18 12:52:50 +00:00
2017-06-21 18:33:57 +00:00
"/images/brand/:file": []string{
2017-06-18 12:52:50 +00:00
"/images/brand/64.webp",
2017-06-21 18:33:57 +00:00
},
2017-06-16 22:33:27 +00:00
2017-06-21 18:33:57 +00:00
"/images/login/:file": []string{
2017-06-16 22:33:27 +00:00
"/images/login/google",
2017-06-21 18:33:57 +00:00
},
2017-06-16 22:33:27 +00:00
2017-06-21 18:33:57 +00:00
"/images/cover/:file": []string{
2017-06-14 20:13:30 +00:00
"/images/cover/default",
2017-06-21 18:33:57 +00:00
},
2017-06-14 20:13:30 +00:00
2017-06-21 18:33:57 +00:00
"/images/elements/:file": []string{
"/images/elements/no-avatar.svg",
2017-06-21 18:33:57 +00:00
},
2017-06-14 20:13:30 +00:00
2017-06-30 16:12:14 +00:00
// Disable these tests because they require authorization
2017-07-08 00:41:13 +00:00
"/auth/google": nil,
"/auth/google/callback": nil,
"/auth/facebook": nil,
"/auth/facebook/callback": nil,
"/import": nil,
"/import/anilist/animelist": nil,
"/import/anilist/animelist/finish": nil,
"/import/myanimelist/animelist": nil,
"/import/myanimelist/animelist/finish": nil,
"/anime/:id/edit": nil,
"/new/thread": nil,
"/new/soundtrack": nil,
"/user": nil,
"/settings": nil,
"/extension/embed": nil,
2017-06-21 18:33:57 +00:00
}
2017-06-30 16:12:14 +00:00
// API interfaces
var creatable = reflect.TypeOf((*api.Creatable)(nil)).Elem()
var updatable = reflect.TypeOf((*api.Updatable)(nil)).Elem()
var collection = reflect.TypeOf((*api.Collection)(nil)).Elem()
// Required interface implementations
var interfaceImplementations = map[string][]reflect.Type{
"User": []reflect.Type{
updatable,
},
"Thread": []reflect.Type{
creatable,
2017-07-06 14:54:10 +00:00
updatable,
2017-06-30 16:12:14 +00:00
},
"Post": []reflect.Type{
creatable,
2017-07-06 14:54:10 +00:00
updatable,
2017-06-30 16:12:14 +00:00
},
"SoundTrack": []reflect.Type{
creatable,
},
"Analytics": []reflect.Type{
creatable,
},
"AnimeList": []reflect.Type{
collection,
},
}
2017-06-21 18:33:57 +00:00
func init() {
// Specify test routes
2017-06-30 16:12:14 +00:00
for route, examples := range routeTests {
2017-06-21 18:33:57 +00:00
app.Test(route, examples)
}
2017-06-30 16:12:14 +00:00
// Check interface implementations
for typeName, interfaces := range interfaceImplementations {
for _, requiredInterface := range interfaces {
if !reflect.PtrTo(arn.DB.Type(typeName)).Implements(requiredInterface) {
panic(errors.New(typeName + " does not implement interface " + requiredInterface.Name()))
}
}
}
2017-06-14 20:13:30 +00:00
}