2020-05-06 12:56:13 +02:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/tidwall/gjson"
|
|
|
|
"net/http"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestCreateZip(t *testing.T) {
|
|
|
|
t.Run("successful request", func(t *testing.T) {
|
2020-06-25 14:54:04 +02:00
|
|
|
app, router, _ := NewApiTest()
|
|
|
|
CreateZip(router)
|
2020-05-06 12:56:13 +02:00
|
|
|
r := PerformRequestWithBody(app, "POST", "/api/v1/zip", `{"photos": ["pt9jtdre2lvl0y12", "pt9jtdre2lvl0y11"]}`)
|
|
|
|
val := gjson.Get(r.Body.String(), "message")
|
2020-07-07 10:51:55 +02:00
|
|
|
assert.Contains(t, val.String(), "Zip created")
|
2020-05-06 12:56:13 +02:00
|
|
|
assert.Equal(t, http.StatusOK, r.Code)
|
|
|
|
})
|
2020-05-25 19:10:44 +02:00
|
|
|
t.Run("no items selected", func(t *testing.T) {
|
2020-06-25 14:54:04 +02:00
|
|
|
app, router, _ := NewApiTest()
|
|
|
|
CreateZip(router)
|
2020-05-06 12:56:13 +02:00
|
|
|
r := PerformRequestWithBody(app, "POST", "/api/v1/zip", `{"photos": []}`)
|
|
|
|
val := gjson.Get(r.Body.String(), "error")
|
2020-05-25 19:10:44 +02:00
|
|
|
assert.Equal(t, "No items selected", val.String())
|
2020-05-06 12:56:13 +02:00
|
|
|
assert.Equal(t, http.StatusBadRequest, r.Code)
|
|
|
|
})
|
|
|
|
t.Run("invalid request", func(t *testing.T) {
|
2020-06-25 14:54:04 +02:00
|
|
|
app, router, _ := NewApiTest()
|
|
|
|
CreateZip(router)
|
2020-05-06 12:56:13 +02:00
|
|
|
r := PerformRequestWithBody(app, "POST", "/api/v1/zip", `{"photos": [123, "pt9jtdre2lvl0yxx"]}`)
|
|
|
|
assert.Equal(t, http.StatusBadRequest, r.Code)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDownloadZip(t *testing.T) {
|
2020-06-25 14:54:04 +02:00
|
|
|
app, router, _ := NewApiTest()
|
|
|
|
CreateZip(router)
|
2020-05-06 12:56:13 +02:00
|
|
|
r := PerformRequestWithBody(app, "POST", "/api/v1/zip", `{"photos": ["pt9jtdre2lvl0y12", "pt9jtdre2lvl0y11"]}`)
|
2020-05-25 19:10:44 +02:00
|
|
|
// filename := gjson.Get(r.Body.String(), "filename")
|
|
|
|
assert.Equal(t, http.StatusNotFound, r.Code) // TODO: Should be http.StatusOK
|
2020-05-06 12:56:13 +02:00
|
|
|
|
2020-05-25 19:10:44 +02:00
|
|
|
// Todo @graciousgray: Files must exist for this to be successful
|
|
|
|
/*
|
2020-05-26 09:02:19 +02:00
|
|
|
t.Run("successful request", func(t *testing.T) {
|
|
|
|
app, router, conf := NewApiTest()
|
|
|
|
DownloadZip(router, conf)
|
|
|
|
r := PerformRequest(app, "GET", "/api/v1/zip/"+filename.String())
|
|
|
|
assert.Equal(t, http.StatusOK, r.Code)
|
|
|
|
})
|
|
|
|
*/
|
2020-05-06 12:56:13 +02:00
|
|
|
|
|
|
|
t.Run("zip not existing", func(t *testing.T) {
|
|
|
|
app, router, conf := NewApiTest()
|
2020-06-25 14:54:04 +02:00
|
|
|
DownloadZip(router)
|
2020-05-27 19:38:40 +02:00
|
|
|
r := PerformRequest(app, "GET", "/api/v1/zip/xxx?t="+conf.DownloadToken())
|
2020-05-06 12:56:13 +02:00
|
|
|
assert.Equal(t, http.StatusNotFound, r.Code)
|
|
|
|
})
|
|
|
|
}
|