43 lines
887 B
Go
43 lines
887 B
Go
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/json"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
|
|
"git.andreafazzi.eu/andrea/testhub/models"
|
|
"git.andreafazzi.eu/andrea/testhub/store"
|
|
"github.com/remogatto/prettytest"
|
|
)
|
|
|
|
type integrationTestSuite struct {
|
|
prettytest.Suite
|
|
}
|
|
|
|
func (t *integrationTestSuite) TestPOSTQuestionAndGETQuestion() {
|
|
server := NewTestHubCollectorServer(store.NewMemoryTestHubCollectorStore())
|
|
|
|
// POST a new question using a JSON payload
|
|
|
|
question := &models.Question{
|
|
Text: "Question 1",
|
|
}
|
|
|
|
payload, err := json.Marshal(question)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
request, _ := http.NewRequest(http.MethodPost, "/questions", bytes.NewReader(payload))
|
|
response := httptest.NewRecorder()
|
|
|
|
returnedQuestion := new(models.Question)
|
|
err = json.Unmarshal(response.Body.Bytes, returnedQuestion)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
server.ServeHTTP(response, request)
|
|
|
|
}
|