Code clean-up #58
This commit is contained in:
parent
9872cfaa50
commit
2e746c833c
4 changed files with 12 additions and 10 deletions
|
@ -9,7 +9,8 @@ import (
|
||||||
"github.com/photoprism/photoprism/internal/test"
|
"github.com/photoprism/photoprism/internal/test"
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewTest() (app *gin.Engine, router *gin.RouterGroup, conf photoprism.Config) {
|
// API test helper
|
||||||
|
func NewApiTest() (app *gin.Engine, router *gin.RouterGroup, conf photoprism.Config) {
|
||||||
conf = test.NewConfig()
|
conf = test.NewConfig()
|
||||||
gin.SetMode(gin.TestMode)
|
gin.SetMode(gin.TestMode)
|
||||||
app = gin.New()
|
app = gin.New()
|
||||||
|
@ -19,7 +20,8 @@ func NewTest() (app *gin.Engine, router *gin.RouterGroup, conf photoprism.Config
|
||||||
return app, router, conf
|
return app, router, conf
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRequest(r http.Handler, method, path string) *httptest.ResponseRecorder {
|
// See https://medium.com/@craigchilds94/testing-gin-json-responses-1f258ce3b0b1
|
||||||
|
func PerformRequest(r http.Handler, method, path string) *httptest.ResponseRecorder {
|
||||||
req, _ := http.NewRequest(method, path, nil)
|
req, _ := http.NewRequest(method, path, nil)
|
||||||
w := httptest.NewRecorder()
|
w := httptest.NewRecorder()
|
||||||
r.ServeHTTP(w, req)
|
r.ServeHTTP(w, req)
|
|
@ -8,31 +8,31 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestGetPhotos(t *testing.T) {
|
func TestGetPhotos(t *testing.T) {
|
||||||
app, router, conf := NewTest()
|
app, router, conf := NewApiTest()
|
||||||
|
|
||||||
GetPhotos(router, conf)
|
GetPhotos(router, conf)
|
||||||
|
|
||||||
result := TestRequest(app, "GET", "/api/v1/photos?count=10")
|
result := PerformRequest(app, "GET", "/api/v1/photos?count=10")
|
||||||
|
|
||||||
assert.Equal(t, http.StatusOK, result.Code)
|
assert.Equal(t, http.StatusOK, result.Code)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLikePhoto(t *testing.T) {
|
func TestLikePhoto(t *testing.T) {
|
||||||
app, router, conf := NewTest()
|
app, router, conf := NewApiTest()
|
||||||
|
|
||||||
LikePhoto(router, conf)
|
LikePhoto(router, conf)
|
||||||
|
|
||||||
result := TestRequest(app, "POST", "/api/v1/photos/1/like")
|
result := PerformRequest(app, "POST", "/api/v1/photos/1/like")
|
||||||
|
|
||||||
assert.Equal(t, http.StatusAccepted, result.Code)
|
assert.Equal(t, http.StatusAccepted, result.Code)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDislikePhoto(t *testing.T) {
|
func TestDislikePhoto(t *testing.T) {
|
||||||
app, router, conf := NewTest()
|
app, router, conf := NewApiTest()
|
||||||
|
|
||||||
DislikePhoto(router, conf)
|
DislikePhoto(router, conf)
|
||||||
|
|
||||||
result := TestRequest(app, "DELETE", "/api/v1/photos/1/like")
|
result := PerformRequest(app, "DELETE", "/api/v1/photos/1/like")
|
||||||
|
|
||||||
assert.Equal(t, http.StatusAccepted, result.Code)
|
assert.Equal(t, http.StatusAccepted, result.Code)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package frontend
|
package frontend
|
||||||
|
|
||||||
// Config values for Web frontend
|
// HTTP client / Web UI config values
|
||||||
type Config map[string]interface{}
|
type Config map[string]interface{}
|
||||||
|
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"github.com/jinzhu/gorm"
|
"github.com/jinzhu/gorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
// A file that belongs to a photo
|
// An image or sidecar file that belongs to a photo
|
||||||
type File struct {
|
type File struct {
|
||||||
gorm.Model
|
gorm.Model
|
||||||
Photo *Photo
|
Photo *Photo
|
||||||
|
|
Loading…
Reference in a new issue