photoprism/internal/api/zip_test.go

40 lines
1.3 KiB
Go
Raw Normal View History

2020-05-06 12:56:13 +02:00
package api
import (
"net/http"
"testing"
2020-11-21 18:08:41 +01:00
"github.com/stretchr/testify/assert"
"github.com/tidwall/gjson"
2020-05-06 12:56:13 +02:00
)
func TestZip(t *testing.T) {
app, router, conf := NewApiTest()
ZipCreate(router)
ZipDownload(router)
t.Run("Download", func(t *testing.T) {
2020-05-06 12:56:13 +02:00
r := PerformRequestWithBody(app, "POST", "/api/v1/zip", `{"photos": ["pt9jtdre2lvl0y12", "pt9jtdre2lvl0y11"]}`)
message := gjson.Get(r.Body.String(), "message")
assert.Contains(t, message.String(), "Zip created")
2020-05-06 12:56:13 +02:00
assert.Equal(t, http.StatusOK, r.Code)
filename := gjson.Get(r.Body.String(), "filename")
dl := PerformRequest(app, "GET", "/api/v1/zip/"+filename.String()+"?t="+conf.DownloadToken())
assert.Equal(t, http.StatusOK, dl.Code)
2020-05-06 12:56:13 +02:00
})
t.Run("ErrNoItemsSelected", func(t *testing.T) {
2020-05-06 12:56:13 +02:00
r := PerformRequestWithBody(app, "POST", "/api/v1/zip", `{"photos": []}`)
val := gjson.Get(r.Body.String(), "error")
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("ErrBadRequest", func(t *testing.T) {
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)
})
t.Run("ErrNotFound", func(t *testing.T) {
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)
})
}