2018-11-17 08:28:50 +01:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"testing"
|
|
|
|
|
2020-11-21 18:08:41 +01:00
|
|
|
"github.com/tidwall/gjson"
|
|
|
|
|
2018-11-17 08:28:50 +01:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
2021-09-18 15:32:39 +02:00
|
|
|
func TestSearchPhotos(t *testing.T) {
|
2022-10-13 22:11:02 +02:00
|
|
|
t.Run("Ok", func(t *testing.T) {
|
2020-06-25 14:54:04 +02:00
|
|
|
app, router, _ := NewApiTest()
|
2021-09-18 15:32:39 +02:00
|
|
|
SearchPhotos(router)
|
2020-05-15 13:14:50 +02:00
|
|
|
r := PerformRequest(app, "GET", "/api/v1/photos?count=10")
|
2020-05-22 16:29:12 +02:00
|
|
|
count := gjson.Get(r.Body.String(), "#")
|
|
|
|
assert.LessOrEqual(t, int64(2), count.Int())
|
2020-05-15 13:14:50 +02:00
|
|
|
assert.Equal(t, http.StatusOK, r.Code)
|
2019-07-17 16:44:21 +02:00
|
|
|
})
|
|
|
|
|
2022-03-30 20:36:25 +02:00
|
|
|
t.Run("ViewerJSON", func(t *testing.T) {
|
|
|
|
app, router, _ := NewApiTest()
|
|
|
|
SearchPhotos(router)
|
|
|
|
r := PerformRequest(app, "GET", "/api/v1/photos?count=10&format=view")
|
|
|
|
body := r.Body.String()
|
|
|
|
|
|
|
|
t.Logf("response body: %s", body)
|
|
|
|
|
|
|
|
count := gjson.Get(body, "#")
|
|
|
|
assert.LessOrEqual(t, int64(2), count.Int())
|
|
|
|
assert.Equal(t, http.StatusOK, r.Code)
|
|
|
|
})
|
|
|
|
|
2021-09-18 15:32:39 +02:00
|
|
|
t.Run("InvalidRequest", func(t *testing.T) {
|
2020-06-25 14:54:04 +02:00
|
|
|
app, router, _ := NewApiTest()
|
2021-09-18 15:32:39 +02:00
|
|
|
SearchPhotos(router)
|
2019-07-17 16:44:21 +02:00
|
|
|
result := PerformRequest(app, "GET", "/api/v1/photos?xxx=10")
|
|
|
|
assert.Equal(t, http.StatusBadRequest, result.Code)
|
|
|
|
})
|
2018-11-17 08:28:50 +01:00
|
|
|
}
|