-
Notifications
You must be signed in to change notification settings - Fork 0
/
delete_test.go
46 lines (35 loc) · 939 Bytes
/
delete_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
package bongoz
import (
. "github.com/smartystreets/goconvey/convey"
"net/http"
"net/http/httptest"
"strings"
"testing"
)
func TestDelete(t *testing.T) {
conn := getConnection()
collection := conn.Collection("pages")
defer conn.Session.Close()
Convey("DELETE", t, func() {
endpoint := NewEndpoint("/api/pages", conn, "pages")
Convey("Basic delete", func() {
endpoint.Factory = Factory
router := endpoint.GetRouter()
w := httptest.NewRecorder()
obj := &Page{
Content: "Foo",
IntValue: 5,
}
err := collection.Save(obj)
So(err, ShouldEqual, nil)
req, _ := http.NewRequest("DELETE", strings.Join([]string{"/api/pages", obj.Id.Hex()}, "/"), nil)
router.ServeHTTP(w, req)
So(w.Code, ShouldEqual, 200)
pagination, _ := collection.Find(nil).Paginate(50, 1)
So(pagination.TotalRecords, ShouldEqual, 0)
})
Reset(func() {
conn.Session.DB("bongoz").DropDatabase()
})
})
}