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