photoprism/internal/api/file_test.go
thielepaul 1d89858e4c
Backend: Add API endpoint for getting files by sha1 hash (#259)
* Backend: Add API endpoint for getting files by sha1 hash

* Test: Add test for Api.GetFile
2020-02-26 17:50:28 +01:00

25 lines
666 B
Go

package api
import (
"net/http"
"testing"
"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)
result := PerformRequest(app, "GET", "/api/v1/files/123xxx")
assert.Equal(t, http.StatusOK, result.Code)
assert.Contains(t, result.Body.String(), "\"FileName\":\"exampleFileName.jpg\"")
})
t.Run("search for not existing file", func(t *testing.T) {
app, router, ctx := NewApiTest()
GetFile(router, ctx)
result := PerformRequest(app, "GET", "/api/v1/files/111")
assert.Equal(t, http.StatusNotFound, result.Code)
})
}