photoprism/internal/api/download_test.go

29 lines
776 B
Go
Raw Normal View History

2020-02-02 17:41:18 +00:00
package api
import (
2020-05-04 12:40:58 +00:00
"github.com/tidwall/gjson"
2020-02-02 17:41:18 +00:00
"net/http"
"testing"
"github.com/stretchr/testify/assert"
)
func TestGetDownload(t *testing.T) {
2020-05-04 12:40:58 +00:00
t.Run("download not existing file", func(t *testing.T) {
2020-02-02 17:41:18 +00:00
app, router, conf := NewApiTest()
GetDownload(router)
2020-02-02 17:41:18 +00:00
r := PerformRequest(app, "GET", "/api/v1/dl/123xxx?t="+conf.DownloadToken())
2020-05-04 12:40:58 +00:00
val := gjson.Get(r.Body.String(), "error")
assert.Equal(t, "record not found", val.String())
assert.Equal(t, http.StatusNotFound, r.Code)
2020-02-02 17:41:18 +00:00
})
2020-05-04 12:40:58 +00:00
t.Run("could not find original", func(t *testing.T) {
2020-02-02 17:41:18 +00:00
app, router, conf := NewApiTest()
GetDownload(router)
r := PerformRequest(app, "GET", "/api/v1/dl/3cad9168fa6acc5c5c2965ddf6ec465ca42fd818?t="+conf.DownloadToken())
2020-05-04 12:40:58 +00:00
assert.Equal(t, http.StatusNotFound, r.Code)
2020-02-02 17:41:18 +00:00
})
}