photoprism/internal/api/file_test.go
Michael Mayer 722d7dd421 Improve link sharing dialog and api #18
Signed-off-by: Michael Mayer <michael@liquidbytes.net>
2020-06-22 15:16:26 +02:00

28 lines
726 B
Go

package api
import (
"net/http"
"testing"
"github.com/tidwall/gjson"
"github.com/stretchr/testify/assert"
)
func TestGetFile(t *testing.T) {
t.Run("search for existing file", func(t *testing.T) {
app, router, ctx := NewApiTest()
GetFile(router, ctx)
r := PerformRequest(app, "GET", "/api/v1/files/2cad9168fa6acc5c5c2965ddf6ec465ca42fd818")
assert.Equal(t, http.StatusOK, r.Code)
val := gjson.Get(r.Body.String(), "Name")
assert.Equal(t, "exampleFileName.jpg", val.String())
})
t.Run("search for not existing file", func(t *testing.T) {
app, router, ctx := NewApiTest()
GetFile(router, ctx)
r := PerformRequest(app, "GET", "/api/v1/files/111")
assert.Equal(t, http.StatusNotFound, r.Code)
})
}