This repository has been archived by the owner on Apr 9, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
/
organization_test.go
91 lines (62 loc) · 1.96 KB
/
organization_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
package stormpath
import (
"encoding/json"
"testing"
"github.com/stretchr/testify/assert"
)
func TestOrganizationJsonMarshaling(t *testing.T) {
t.Parallel()
organization := NewOrganization("name", "nameKey")
jsonData, _ := json.Marshal(organization)
assert.Equal(t, "{\"name\":\"name\",\"nameKey\":\"nameKey\"}", string(jsonData))
}
func TestUpdateOrganization(t *testing.T) {
t.Parallel()
org := createTestOrganization(t)
defer org.Delete()
org.Name = "new-name" + randomName()
err := org.Update()
assert.NoError(t, err)
updatedOrg, err := GetOrganization(org.Href, MakeOrganizationCriteria())
assert.NoError(t, err)
assert.Equal(t, org.Name, updatedOrg.Name)
}
func TestRefreshOrganization(t *testing.T) {
t.Parallel()
org := createTestOrganization(t)
defer org.Delete()
newName := "new-name" + randomName()
org.Name = newName
err := org.Refresh()
assert.NoError(t, err)
assert.NotEqual(t, newName, org.Name)
}
func TestGetOrganizationDefaultAccountStoreMapping(t *testing.T) {
t.Parallel()
org := createTestOrganization(t)
defer org.Delete()
directory := createTestDirectory(t)
defer directory.Delete()
mapping := NewOrganizationAccountStoreMapping(org.Href, directory.Href)
mapping.IsDefaultAccountStore = true
mapping.Save()
org.Refresh()
defaultMapping, err := org.GetDefaultAccountStoreMapping(MakeOrganizationAccountStoreMappingCriteria())
assert.NoError(t, err)
assert.Equal(t, org.Href, defaultMapping.Organization.Href)
assert.Equal(t, directory.Href, defaultMapping.AccountStore.Href)
}
func TestOrganizationRegisterAccount(t *testing.T) {
t.Parallel()
org := createTestOrganization(t)
defer org.Delete()
directory := createTestDirectory(t)
defer directory.Delete()
mapping := NewOrganizationAccountStoreMapping(org.Href, directory.Href)
mapping.IsDefaultAccountStore = true
mapping.Save()
account := newTestAccount()
err := org.RegisterAccount(account)
assert.NoError(t, err)
assert.NotEmpty(t, account.Href)
}