-
Notifications
You must be signed in to change notification settings - Fork 12
/
response_test.go
53 lines (40 loc) · 1.07 KB
/
response_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package jsh
import (
"encoding/json"
"net/http"
"net/http/httptest"
"strconv"
"testing"
. "github.com/smartystreets/goconvey/convey"
)
func TestSend(t *testing.T) {
Convey("Send Tests", t, func() {
writer := httptest.NewRecorder()
request := &http.Request{}
object := &Object{
ID: "1234",
Type: "user",
Attributes: json.RawMessage(`{"foo":"bar"}`),
}
Convey("Success Handlers", func() {
Convey("->Send()", func() {
Convey("should send a proper HTTP JSON response", func() {
request.Method = "GET"
err := Send(writer, request, object)
So(err, ShouldBeNil)
So(writer.Code, ShouldEqual, http.StatusOK)
contentLength, convErr := strconv.Atoi(writer.HeaderMap.Get("Content-Length"))
So(convErr, ShouldBeNil)
So(contentLength, ShouldBeGreaterThan, 0)
So(writer.HeaderMap.Get("Content-Type"), ShouldEqual, ContentType)
})
})
})
Convey("->Ok()", func() {
doc := Ok()
err := SendDocument(writer, request, doc)
So(err, ShouldBeNil)
So(writer.Code, ShouldEqual, http.StatusOK)
})
})
}