-
Notifications
You must be signed in to change notification settings - Fork 0
/
accountgroup.go
57 lines (48 loc) · 1.92 KB
/
accountgroup.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
54
55
56
57
package tests
import (
"bytes"
"encoding/json"
"github.com/revel/revel"
"github.com/stsmedia/thingbricks/app/models"
"net/http"
)
type AccountGroupTests struct {
revel.TestSuite
}
func (t *AccountGroupTests) TestCreateAccountGroup() {
body, _ := json.Marshal(&models.AccountGroup{Name: "foo", AccountId: 1})
t.Post("/accounts/1/groups", contentType, bytes.NewBufferString(string(body)))
t.AssertOk()
}
func (t *AccountGroupTests) TestCreateAccountGroupInvalidJson() {
t.Post("/accounts/1/groups", contentType, bytes.NewBufferString("{\"name1\":\"foo\"}"))
t.AssertStatus(http.StatusNotAcceptable)
// t.AssertContains("Account group name required")
}
func (t *AccountGroupTests) TestUpdateAccountGroup() {
body, _ := json.Marshal(&models.AccountGroup{Id: 1, Name: "foo1", AccountId: 1})
t.Put("/accounts/1/groups/1", contentType, bytes.NewBufferString(string(body)))
t.AssertOk()
t.AssertContains("foo1")
}
func (t *AccountGroupTests) TestUpdateAccountGroupNotMatchingIds() {
body, _ := json.Marshal(&models.AccountGroup{Id: 2, Name: "foo", AccountId: 1})
t.Put("/accounts/1/groups/1", contentType, bytes.NewBufferString(string(body)))
t.AssertStatus(http.StatusNotAcceptable)
t.AssertContains("Entity ID and URL ID don't match")
}
func (t *AccountGroupTests) TestUpdateAccountGroupNotMatchingAccountIds() {
body, _ := json.Marshal(&models.AccountGroup{Id: 2, Name: "foo", AccountId: 2})
t.Put("/accounts/1/groups/1", contentType, bytes.NewBufferString(string(body)))
t.AssertStatus(http.StatusNotAcceptable)
t.AssertContains("Entity ID and URL ID don't match")
}
func (t *AccountGroupTests) TestUpdateAccountGroupInvalidJson() {
t.Put("/accounts/1/groups/1", contentType, bytes.NewBufferString("{\"id\":1, \"name1\":\"foo\"}"))
t.AssertStatus(http.StatusNotAcceptable)
// t.AssertContains("Account group name required")
}
func (t *AccountGroupTests) TestDeleteAccountGroup() {
t.Delete("/accounts/1/groups/1")
t.AssertOk()
}