2020-02-26 17:50:28 +01:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
2020-05-01 14:15:15 +02:00
|
|
|
"github.com/tidwall/gjson"
|
2020-02-26 17:50:28 +01:00
|
|
|
"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)
|
2020-05-01 14:15:15 +02:00
|
|
|
result := PerformRequest(app, "GET", "/api/v1/files/2cad9168fa6acc5c5c2965ddf6ec465ca42fd818")
|
2020-02-26 17:50:28 +01:00
|
|
|
assert.Equal(t, http.StatusOK, result.Code)
|
2020-05-01 14:15:15 +02:00
|
|
|
|
|
|
|
val := gjson.Get(result.Body.String(), "FileName")
|
|
|
|
assert.Equal(t, "exampleFileName.jpg", val.String())
|
2020-02-26 17:50:28 +01:00
|
|
|
})
|
|
|
|
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)
|
|
|
|
})
|
|
|
|
}
|