-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreadone_test.go
53 lines (41 loc) · 1.02 KB
/
readone_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 bongoz
import (
"encoding/json"
. "github.com/smartystreets/goconvey/convey"
"net/http"
"net/http/httptest"
"strings"
"testing"
)
func TestReadOne(t *testing.T) {
conn := getConnection()
collection := conn.Collection("pages")
defer conn.Session.Close()
Convey("ReadOne", t, func() {
endpoint := NewEndpoint("/api/pages", conn, "pages")
Convey("basic", func() {
endpoint.Factory = Factory
router := endpoint.GetRouter()
w := httptest.NewRecorder()
// Add two
obj1 := &Page{
Content: "foo",
}
obj2 := &Page{
Content: "bar",
}
collection.Save(obj1)
collection.Save(obj2)
req, _ := http.NewRequest("GET", strings.Join([]string{"/api/pages/", obj1.Id.Hex()}, ""), nil)
router.ServeHTTP(w, req)
response := &singleResponse{}
So(w.Code, ShouldEqual, 200)
err := json.Unmarshal(w.Body.Bytes(), response)
So(err, ShouldEqual, nil)
So(response.Data["content"], ShouldEqual, "foo")
})
Reset(func() {
conn.Session.DB("dplservertest").DropDatabase()
})
})
}