2017-03-30 18:43:18 +02:00
|
|
|
package http
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/genofire/hs_master-kss-monolith/lib/database"
|
2017-03-30 19:05:33 +02:00
|
|
|
"github.com/genofire/hs_master-kss-monolith/models"
|
2017-03-30 18:43:18 +02:00
|
|
|
|
|
|
|
"github.com/genofire/hs_master-kss-monolith/test"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestReview(t *testing.T) {
|
|
|
|
assertion, router := test.Init(t)
|
2017-03-30 19:05:33 +02:00
|
|
|
|
2017-03-30 18:43:18 +02:00
|
|
|
BindAPI(router)
|
|
|
|
session := test.NewSession(router)
|
|
|
|
|
2017-03-30 19:05:33 +02:00
|
|
|
result, w := session.JSONRequest("GET", "/api/review/a", nil)
|
|
|
|
assertion.Equal(http.StatusNotAcceptable, w.StatusCode)
|
|
|
|
|
|
|
|
result, w = session.JSONRequest("GET", "/api/review/1", nil)
|
|
|
|
assertion.Equal(http.StatusNotFound, w.StatusCode)
|
|
|
|
|
|
|
|
database.Write.Create(&models.Review{
|
|
|
|
ProductID: 3,
|
|
|
|
FirstName: "Max",
|
|
|
|
LastName: "Mustmann",
|
|
|
|
RatingStars: 3,
|
|
|
|
Text: "blub",
|
|
|
|
})
|
|
|
|
|
|
|
|
result, w = session.JSONRequest("GET", "/api/review/3", nil)
|
2017-03-30 18:43:18 +02:00
|
|
|
assertion.Equal(http.StatusOK, w.StatusCode)
|
2017-03-30 19:05:33 +02:00
|
|
|
assertion.Len(result, 1)
|
|
|
|
|
|
|
|
test.Close()
|
2017-03-30 18:43:18 +02:00
|
|
|
}
|