@@ -45,23 +45,6 @@ var _ = Describe("CreateUser", func() {
4545 Expect (session .Err ).To (Say ("The positional argument USERNAME must be specified." ))
4646 })
4747
48- It ("requires a family name (last name)" , func () {
49- session := runCommand ("create-user" , "woodstock" )
50-
51- Eventually (session ).Should (Exit (1 ))
52- Expect (session .Err ).To (Say ("Missing argument `familyName` must be specified." ))
53- })
54-
55- It ("requires a given name (first name)" , func () {
56- session := runCommand ("create-user" ,
57- "woodstock" ,
58- "--familyName" , "Bird" ,
59- )
60-
61- Eventually (session ).Should (Exit (1 ))
62- Expect (session .Err ).To (Say ("Missing argument `givenName` must be specified." ))
63- })
64-
6548 It ("requires an email address" , func () {
6649 session := runCommand ("create-user" ,
6750 "woodstock" ,
@@ -73,17 +56,17 @@ var _ = Describe("CreateUser", func() {
7356 Expect (session .Err ).To (Say ("Missing argument `email` must be specified." ))
7457 })
7558 })
76-
7759 Describe ("CreateUserCmd" , func () {
78- It ("performs POST with user data and bearer token" , func () {
79- server .RouteToHandler ("POST" , "/Users" , CombineHandlers (
80- RespondWith (http .StatusOK , fixtures .MarcusUserResponse ),
81- VerifyRequest ("POST" , "/Users" ),
82- VerifyHeaderKV ("Authorization" , "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9.TJVA95OrM7E2cBab30RMHrHDcEfxjoYZgeFONFh7HgQ" ),
83- VerifyHeaderKV ("Accept" , "application/json" ),
84- VerifyHeaderKV ("Content-Type" , "application/json" ),
85- VerifyHeaderKV ("X-Identity-Zone-Id" , "twilight-zone" ),
86- VerifyJSON (`
60+ Describe ("With name" , func () {
61+ It ("performs POST with user data and bearer token" , func () {
62+ server .RouteToHandler ("POST" , "/Users" , CombineHandlers (
63+ RespondWith (http .StatusOK , fixtures .MarcusUserResponse ),
64+ VerifyRequest ("POST" , "/Users" ),
65+ VerifyHeaderKV ("Authorization" , "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9.TJVA95OrM7E2cBab30RMHrHDcEfxjoYZgeFONFh7HgQ" ),
66+ VerifyHeaderKV ("Accept" , "application/json" ),
67+ VerifyHeaderKV ("Content-Type" , "application/json" ),
68+ VerifyHeaderKV ("X-Identity-Zone-Id" , "twilight-zone" ),
69+ VerifyJSON (`
8770 {
8871 "userName": "marcus",
8972 "password": "secret",
@@ -107,57 +90,141 @@ var _ = Describe("CreateUser", func() {
10790 }]
10891 }
10992 ` ),
110- ))
111-
112- session := runCommand ("create-user" , "marcus" ,
113- "--givenName" , "Marcus" ,
114- "--familyName" , "Aurelius" ,
115- "--email" , "marcus@philosophy.com" ,
116- "--email" , "marcusA@gmail.com" ,
117- "--phone" , "555-5555" ,
118- "--phone" , "666-6666" ,
119- "--password" , "secret" ,
120- "--origin" , "uaa" ,
121- "--zone" , "twilight-zone" ,
122- )
123-
124- Expect (server .ReceivedRequests ()).To (HaveLen (1 ))
125- Expect (session ).To (Exit (0 ))
93+ ))
94+
95+ session := runCommand ("create-user" , "marcus" ,
96+ "--givenName" , "Marcus" ,
97+ "--familyName" , "Aurelius" ,
98+ "--email" , "marcus@philosophy.com" ,
99+ "--email" , "marcusA@gmail.com" ,
100+ "--phone" , "555-5555" ,
101+ "--phone" , "666-6666" ,
102+ "--password" , "secret" ,
103+ "--origin" , "uaa" ,
104+ "--zone" , "twilight-zone" ,
105+ )
106+
107+ Expect (server .ReceivedRequests ()).To (HaveLen (1 ))
108+ Expect (session ).To (Exit (0 ))
109+ })
110+
111+ It ("prints the created user json" , func () {
112+ server .RouteToHandler ("POST" , "/Users" , CombineHandlers (
113+ RespondWith (http .StatusOK , fixtures .MarcusUserResponse ),
114+ VerifyRequest ("POST" , "/Users" ),
115+ ))
116+
117+ session := runCommand ("create-user" , "marcus" ,
118+ "--givenName" , "Marcus" ,
119+ "--familyName" , "Aurelius" ,
120+ "--email" , "marcus@philosophy.com" ,
121+ "--email" , "marcusA@gmail.com" ,
122+ )
123+
124+ Expect (server .ReceivedRequests ()).To (HaveLen (1 ))
125+ Expect (session ).To (Exit (0 ))
126+ Expect (session .Out .Contents ()).To (MatchJSON (fixtures .MarcusUserResponse ))
127+ })
128+
129+ It ("displays an error if there is a problem during create" , func () {
130+ server .RouteToHandler ("POST" , "/Users" , CombineHandlers (
131+ RespondWith (http .StatusBadRequest , "" ),
132+ VerifyRequest ("POST" , "/Users" ),
133+ ))
134+
135+ session := runCommand ("create-user" , "marcus" ,
136+ "--givenName" , "Marcus" ,
137+ "--familyName" , "Aurelius" ,
138+ "--email" , "marcus@philosophy.com" ,
139+ "--email" , "marcusA@gmail.com" ,
140+ )
141+
142+ Expect (server .ReceivedRequests ()).To (HaveLen (1 ))
143+ Expect (session ).To (Exit (1 ))
144+ })
126145 })
127146
128- It ("prints the created user json" , func () {
129- server .RouteToHandler ("POST" , "/Users" , CombineHandlers (
130- RespondWith (http .StatusOK , fixtures .MarcusUserResponse ),
131- VerifyRequest ("POST" , "/Users" ),
132- ))
133-
134- session := runCommand ("create-user" , "marcus" ,
135- "--givenName" , "Marcus" ,
136- "--familyName" , "Aurelius" ,
137- "--email" , "marcus@philosophy.com" ,
138- "--email" , "marcusA@gmail.com" ,
139- )
140-
141- Expect (server .ReceivedRequests ()).To (HaveLen (1 ))
142- Expect (session ).To (Exit (0 ))
143- Expect (session .Out .Contents ()).To (MatchJSON (fixtures .MarcusUserResponse ))
147+ Describe ("Without name" , func () {
148+ It ("performs POST with user data and bearer token" , func () {
149+ server .RouteToHandler ("POST" , "/Users" , CombineHandlers (
150+ RespondWith (http .StatusOK , fixtures .MarcusUserResponse ),
151+ VerifyRequest ("POST" , "/Users" ),
152+ VerifyHeaderKV ("Authorization" , "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9.TJVA95OrM7E2cBab30RMHrHDcEfxjoYZgeFONFh7HgQ" ),
153+ VerifyHeaderKV ("Accept" , "application/json" ),
154+ VerifyHeaderKV ("Content-Type" , "application/json" ),
155+ VerifyHeaderKV ("X-Identity-Zone-Id" , "twilight-zone" ),
156+ VerifyJSON (`
157+ {
158+ "userName": "marcus",
159+ "password": "secret",
160+ "origin": "uaa",
161+ "name" : {},
162+ "emails": [
163+ {
164+ "value": "marcus@philosophy.com",
165+ "primary": true
166+ },
167+ {
168+ "value": "marcusA@gmail.com",
169+ "primary": false
170+ }
171+ ],
172+ "phoneNumbers": [{
173+ "value": "555-5555"
174+ },
175+ {
176+ "value": "666-6666"
177+ }]
178+ }
179+ ` ),
180+ ))
181+
182+ session := runCommand ("create-user" , "marcus" ,
183+ "--email" , "marcus@philosophy.com" ,
184+ "--email" , "marcusA@gmail.com" ,
185+ "--phone" , "555-5555" ,
186+ "--phone" , "666-6666" ,
187+ "--password" , "secret" ,
188+ "--origin" , "uaa" ,
189+ "--zone" , "twilight-zone" ,
190+ )
191+
192+ Expect (server .ReceivedRequests ()).To (HaveLen (1 ))
193+ Expect (session ).To (Exit (0 ))
194+ })
195+
196+ It ("prints the created user json" , func () {
197+ server .RouteToHandler ("POST" , "/Users" , CombineHandlers (
198+ RespondWith (http .StatusOK , fixtures .AnonyMarcusUserResponse ),
199+ VerifyRequest ("POST" , "/Users" ),
200+ ))
201+
202+ session := runCommand ("create-user" , "marcus" ,
203+ "--email" , "marcus@philosophy.com" ,
204+ "--email" , "marcusA@gmail.com" ,
205+ )
206+
207+ Expect (server .ReceivedRequests ()).To (HaveLen (1 ))
208+ Expect (session ).To (Exit (0 ))
209+ Expect (session .Out .Contents ()).To (MatchJSON (fixtures .AnonyMarcusUserResponse ))
210+ })
211+
212+ It ("displays an error if there is a problem during create" , func () {
213+ server .RouteToHandler ("POST" , "/Users" , CombineHandlers (
214+ RespondWith (http .StatusBadRequest , "" ),
215+ VerifyRequest ("POST" , "/Users" ),
216+ ))
217+
218+ session := runCommand ("create-user" , "marcus" ,
219+ "--email" , "marcus@philosophy.com" ,
220+ "--email" , "marcusA@gmail.com" ,
221+ )
222+
223+ Expect (server .ReceivedRequests ()).To (HaveLen (1 ))
224+ Expect (session ).To (Exit (1 ))
225+ })
144226 })
145227
146- It ("displays an error if there is a problem during create" , func () {
147- server .RouteToHandler ("POST" , "/Users" , CombineHandlers (
148- RespondWith (http .StatusBadRequest , "" ),
149- VerifyRequest ("POST" , "/Users" ),
150- ))
151-
152- session := runCommand ("create-user" , "marcus" ,
153- "--givenName" , "Marcus" ,
154- "--familyName" , "Aurelius" ,
155- "--email" , "marcus@philosophy.com" ,
156- "--email" , "marcusA@gmail.com" ,
157- )
158-
159- Expect (server .ReceivedRequests ()).To (HaveLen (1 ))
160- Expect (session ).To (Exit (1 ))
161- })
162228 })
229+
163230})
0 commit comments