1d89858e4c
* Backend: Add API endpoint for getting files by sha1 hash * Test: Add test for Api.GetFile
24 lines
666 B
Go
24 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)
|
|
})
|
|
}
|