2018-11-17 08:28:50 +01:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestGetPhotos(t *testing.T) {
|
2019-05-03 18:57:28 +02:00
|
|
|
app, router, ctx := NewApiTest()
|
2018-11-17 08:28:50 +01:00
|
|
|
|
2019-05-03 18:57:28 +02:00
|
|
|
GetPhotos(router, ctx)
|
2018-11-17 08:28:50 +01:00
|
|
|
|
2018-11-18 19:18:19 +01:00
|
|
|
result := PerformRequest(app, "GET", "/api/v1/photos?count=10")
|
2018-11-17 08:28:50 +01:00
|
|
|
|
|
|
|
assert.Equal(t, http.StatusOK, result.Code)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestLikePhoto(t *testing.T) {
|
2019-05-03 18:57:28 +02:00
|
|
|
app, router, ctx := NewApiTest()
|
2018-11-17 08:28:50 +01:00
|
|
|
|
2019-05-03 18:57:28 +02:00
|
|
|
LikePhoto(router, ctx)
|
2018-11-17 08:28:50 +01:00
|
|
|
|
2018-11-18 19:18:19 +01:00
|
|
|
result := PerformRequest(app, "POST", "/api/v1/photos/1/like")
|
2018-11-17 08:28:50 +01:00
|
|
|
|
2019-04-26 04:25:00 +02:00
|
|
|
// TODO: Test database can be empty
|
|
|
|
if result.Code != http.StatusNotFound {
|
|
|
|
assert.Equal(t, http.StatusOK, result.Code)
|
|
|
|
}
|
2018-11-17 08:28:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestDislikePhoto(t *testing.T) {
|
2019-05-03 18:57:28 +02:00
|
|
|
app, router, ctx := NewApiTest()
|
2018-11-17 08:28:50 +01:00
|
|
|
|
2019-05-03 18:57:28 +02:00
|
|
|
DislikePhoto(router, ctx)
|
2018-11-17 08:28:50 +01:00
|
|
|
|
2018-11-18 19:18:19 +01:00
|
|
|
result := PerformRequest(app, "DELETE", "/api/v1/photos/1/like")
|
2018-11-17 08:28:50 +01:00
|
|
|
|
2019-04-26 04:25:00 +02:00
|
|
|
// TODO: Test database can be empty
|
|
|
|
if result.Code != http.StatusNotFound {
|
|
|
|
assert.Equal(t, http.StatusOK, result.Code)
|
|
|
|
}
|
2018-11-17 08:28:50 +01:00
|
|
|
}
|