forked from jarias/stormpath-sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
account_test.go
136 lines (107 loc) · 3.8 KB
/
account_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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
package stormpath_test
import (
"encoding/json"
. "github.com/jarias/stormpath-sdk-go"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Account", func() {
Describe("JSON", func() {
It("should marshal a minimum JSON with only the account required fields", func() {
acc := NewAccount("[email protected]", "123", "[email protected]", "test", "test")
jsonData, _ := json.Marshal(acc)
Expect(string(jsonData)).To(Equal("{\"username\":\"[email protected]\",\"email\":\"[email protected]\",\"password\":\"123\",\"givenName\":\"test\",\"surname\":\"test\"}"))
})
})
Describe("Save", func() {
It("should update an existing account", func() {
account := newTestAccount()
app.RegisterAccount(account)
account.GivenName = "julio"
err := account.Save()
Expect(err).NotTo(HaveOccurred())
Expect(account.GivenName).To(Equal("julio"))
})
})
Describe("Delete", func() {
It("should delete an existing account", func() {
account := newTestAccount()
app.RegisterAccount(account)
err := account.Delete()
Expect(err).NotTo(HaveOccurred())
})
})
Describe("AddToGroup", func() {
It("should add an account to an existing group", func() {
group := newTestGroup()
app.CreateGroup(group)
_, err := account.AddToGroup(group)
gm, _ := account.GetGroupMemberships(MakeAccountCriteria().Offset(0).Limit(25))
Expect(err).NotTo(HaveOccurred())
Expect(gm.Items).To(HaveLen(1))
account.RemoveFromGroup(group)
group.Delete()
})
})
Describe("RemoveFromGroup", func() {
It("should remove an account from an existing group", func() {
account := newTestAccount()
app.RegisterAccount(account)
var groupCountBefore int
group := newTestGroup()
app.CreateGroup(group)
gm, _ := account.GetGroupMemberships(MakeAccountCriteria().Offset(0).Limit(25))
groupCountBefore = len(gm.Items)
account.AddToGroup(group)
err := account.RemoveFromGroup(group)
gm, _ = account.GetGroupMemberships(MakeAccountCriteria().Offset(0).Limit(25))
Expect(err).NotTo(HaveOccurred())
Expect(gm.Items).To(HaveLen(groupCountBefore))
group.Delete()
})
})
Describe("GetGroupMemberships", func() {
It("should allow expanding the account", func() {
acct := registerTestAccount()
group := addAccountToGroup(acct)
groupMemberships, err := acct.GetGroupMemberships(MakeGroupMemershipCriteria().WithAccount().Offset(0).Limit(25))
Expect(err).NotTo(HaveOccurred())
for _, gm := range groupMemberships.Items {
Expect(gm.Account).To(BeEquivalentTo(*acct))
Expect(gm.Group).NotTo(BeEquivalentTo(*group))
}
})
//It("should allow expanding the group", func() {
// account := registerTestAccount()
// group := addAccountToGroup(account)
//
// groupMemberships, err := account.GetGroupMemberships(NewDefaultPageRequest(), "group")
//
// Expect(err).NotTo(HaveOccurred())
// for _, gm := range groupMemberships.Items {
// Expect(gm.Account).To(BeEquivalentTo(account))
// Expect(gm.Group.Name).To(BeEquivalentTo(group.Name))
// }
//})
})
Describe("GetCustomData", func() {
It("should retrieve an account custom data", func() {
customData, err := account.GetCustomData()
Expect(err).NotTo(HaveOccurred())
Expect(customData).NotTo(BeEmpty())
})
})
Describe("UpdateCustomData", func() {
It("should set an account custom data", func() {
customData, err := account.UpdateCustomData(map[string]interface{}{"custom": "data"})
Expect(err).NotTo(HaveOccurred())
Expect(customData["custom"]).To(Equal("data"))
})
It("should update an account custom data", func() {
account.UpdateCustomData(map[string]interface{}{"custom": "data"})
customData, err := account.UpdateCustomData(map[string]interface{}{"custom": "nodata"})
Expect(err).NotTo(HaveOccurred())
Expect(customData["custom"]).To(Equal("nodata"))
})
})
})