@@ -40,57 +40,54 @@ var _ = Describe("Create", func() {
4040 }
4141 fakeUserManager .CreateUserReturns (testUser , nil )
4242 })
43- Describe ("user create " , func () {
44- Context ("user create with not enough parameters " , func () {
45- It ("return error " , func () {
43+ Describe ("User Create Command " , func () {
44+ Context ("Invalid Paramter Checks " , func () {
45+ It ("Needs one argument " , func () {
4646 err := testhelpers .RunCobraCommand (cliCommand .Command )
4747 Expect (err ).To (HaveOccurred ())
48- Expect (strings . Contains ( err .Error (), "Incorrect Usage: This command requires one argument" )). To ( BeTrue ( ))
48+ Expect (err .Error ()). To ( ContainSubstring ( "Incorrect Usage: This command requires one argument" ))
4949 })
5050 })
51-
52- Context ("create user with fail confirmation" , func () {
53- It ("return error" , func () {
51+ Context ("Input Checks" , func () {
52+ It ("Not Y/N" , func () {
5453 fakeUI .Inputs ("123456" )
5554 err := testhelpers .RunCobraCommand (cliCommand .Command , "createdUser@email.com" , "--email" , "createdUser@email.com" , "--password" , "MyPassWord" )
5655 Expect (err ).To (HaveOccurred ())
5756 Expect (fakeUI .Outputs ()).To (ContainSubstring ("You are about to create the following user: createdUser@email.com. Do you wish to continue?" ))
5857 Expect (err .Error ()).To (ContainSubstring ("input must be 'y', 'n', 'yes' or 'no'" ))
5958 })
60- })
61-
62- Context ("create user with No confirmation" , func () {
63- It ("return error" , func () {
59+ It ("No confirmation" , func () {
6460 fakeUI .Inputs ("No" )
6561 err := testhelpers .RunCobraCommand (cliCommand .Command , "createdUser@email.com" , "--email" , "createdUser@email.com" , "--password" , "MyPassWord" )
6662 Expect (err ).NotTo (HaveOccurred ())
6763 Expect (fakeUI .Outputs ()).To (ContainSubstring ("You are about to create the following user: createdUser@email.com. Do you wish to continue?" ))
6864 Expect (fakeUI .Outputs ()).To (ContainSubstring ("Aborted." ))
6965 })
7066 })
71-
72- Context ("User Create error" , func () {
73- It ("return error" , func () {
67+ Context ("Error Handling" , func () {
68+ It ("API Error" , func () {
7469 fakeUserManager .CreateUserReturns (datatypes.User_Customer {}, errors .New ("Internal server error" ))
7570 err := testhelpers .RunCobraCommand (cliCommand .Command , "createdUser@email.com" , "--email" , "createdUser@email.com" , "--password" , "MyPassWord" , "-f" )
7671 Expect (err ).To (HaveOccurred ())
7772 Expect (err .Error ()).To (ContainSubstring ("Failed to add user." ))
7873 })
74+ It ("Bad Template" , func () {
75+ err := testhelpers .RunCobraCommand (cliCommand .Command , "createdUser@email.com" , "--email" , "createdUser@email.com" , "--password" , "MyPassWord" , "-f" , "--template" , `` )
76+ Expect (err ).To (HaveOccurred ())
77+ Expect (err .Error ()).To (ContainSubstring ("Unable to unmarshal template json: unexpected end of JSON input" ))
78+ })
7979 })
8080
81- Context ("Basic User Create usage " , func () {
82- It ("Create a user" , func () {
81+ Context ("Happy Path Tests " , func () {
82+ It ("Create a user --force " , func () {
8383 err := testhelpers .RunCobraCommand (cliCommand .Command , "createdUser@email.com" , "--email" , "createdUser@email.com" , "--password" , "MyPassWord" , "-f" )
8484 Expect (err ).NotTo (HaveOccurred ())
8585 Expect (fakeUI .Outputs ()).To (ContainSubstring ("name value" ))
8686 Expect (fakeUI .Outputs ()).To (ContainSubstring ("Username createdUser" ))
8787 Expect (fakeUI .Outputs ()).To (ContainSubstring ("Email createdUser@email.com" ))
8888 Expect (fakeUI .Outputs ()).To (ContainSubstring ("Password MyPassWord" ))
8989 })
90- })
91-
92- Context ("User Create" , func () {
93- It ("Create a user" , func () {
90+ It ("Create a user with confirmation" , func () {
9491 fakeUI .Inputs ("Y" )
9592 err := testhelpers .RunCobraCommand (cliCommand .Command , "createdUser@email.com" , "--email" , "createdUser@email.com" , "--password" , "MyPassWord" )
9693 Expect (err ).NotTo (HaveOccurred ())
@@ -100,10 +97,7 @@ var _ = Describe("Create", func() {
10097 Expect (fakeUI .Outputs ()).To (ContainSubstring ("Email createdUser@email.com" ))
10198 Expect (fakeUI .Outputs ()).To (ContainSubstring ("Password MyPassWord" ))
10299 })
103- })
104-
105- Context ("User Create from user" , func () {
106- It ("Create a user" , func () {
100+ It ("Create a user from another user" , func () {
107101 fakeUI .Inputs ("Y" )
108102 err := testhelpers .RunCobraCommand (cliCommand .Command , "createdUser@email.com" , "--from-user" , "456" , "--password" , "MyPassWord" , "-f" )
109103 Expect (err ).NotTo (HaveOccurred ())
@@ -112,18 +106,7 @@ var _ = Describe("Create", func() {
112106 Expect (fakeUI .Outputs ()).To (ContainSubstring ("Email createdUser@email.com" ))
113107 Expect (fakeUI .Outputs ()).To (ContainSubstring ("Password MyPassWord" ))
114108 })
115- })
116-
117- Context ("User Create from wrong template" , func () {
118- It ("Create a user" , func () {
119- err := testhelpers .RunCobraCommand (cliCommand .Command , "createdUser@email.com" , "--email" , "createdUser@email.com" , "--password" , "MyPassWord" , "-f" , "--template" , `` )
120- Expect (err ).To (HaveOccurred ())
121- Expect (err .Error ()).To (ContainSubstring ("Unable to unmarshal template json: unexpected end of JSON input" ))
122- })
123- })
124-
125- Context ("User Create from template" , func () {
126- It ("Create a user" , func () {
109+ It ("Create a user from a template" , func () {
127110 testUser := datatypes.User_Customer {
128111 Id : sl .Int (6666 ),
129112 Username : sl .String ("createdUser" ),
@@ -138,12 +121,8 @@ var _ = Describe("Create", func() {
138121 Expect (fakeUI .Outputs ()).To (ContainSubstring ("Username createdUser" ))
139122 Expect (fakeUI .Outputs ()).To (ContainSubstring ("Email createdUser@email.com" ))
140123 Expect (fakeUI .Outputs ()).To (ContainSubstring ("Password MyPassWord" ))
141-
142124 })
143- })
144-
145- Context ("User Create with generated password" , func () {
146- It ("Create a user" , func () {
125+ It ("Create a user with a generated password" , func () {
147126 err := testhelpers .RunCobraCommand (cliCommand .Command , "createdUser@email.com" , "--email" , "createdUser@email.com" , "--password" , "generate" , "-f" )
148127 Expect (err ).NotTo (HaveOccurred ())
149128 Expect (fakeUI .Outputs ()).To (ContainSubstring ("name value" ))
@@ -152,64 +131,36 @@ var _ = Describe("Create", func() {
152131 Expect (fakeUI .Outputs ()).To (ContainSubstring ("Password" ))
153132 })
154133 })
155-
156134 })
157135
158- Describe ("structAssignment" , func () {
159-
160- A1 := "11"
161- A2 := "12"
162- B1 := "21"
163- B2 := "22"
164- var S1 , S2 datatypes.User_Customer
165- Context ("structAssignment" , func () {
166- BeforeEach (func () {
167- S1 = datatypes.User_Customer {Address1 : & A1 , Address2 : & A2 }
168- S2 = datatypes.User_Customer {Address1 : & B1 , Address2 : nil }
169- })
170-
171- It ("return succ" , func () {
172- user .StructAssignment (& S1 , & S2 )
173- Expect (* S1 .Address1 ).To (Equal ("21" ))
174- Expect (* S1 .Address2 ).To (Equal ("12" ))
175- })
176- })
177- Context ("structAssignment" , func () {
178- BeforeEach (func () {
179- S1 = datatypes.User_Customer {Address1 : & A1 , Address2 : & A2 }
180- S2 = datatypes.User_Customer {Address1 : & B1 , Address2 : & B2 }
181- })
182-
183- It ("return succ" , func () {
184- user .StructAssignment (& S1 , & S2 )
185- Expect (* S1 .Address1 ).To (Equal ("21" ))
186- Expect (* S1 .Address2 ).To (Equal ("22" ))
187- })
188- })
189- Context ("structAssignment" , func () {
190- BeforeEach (func () {
191- S1 = datatypes.User_Customer {Address1 : nil , Address2 : & A2 }
192- S2 = datatypes.User_Customer {Address1 : & B1 , Address2 : & B2 }
193- })
194-
195- It ("return succ" , func () {
196- user .StructAssignment (& S1 , & S2 )
197- Expect (* S1 .Address1 ).To (Equal ("21" ))
198- Expect (* S1 .Address2 ).To (Equal ("22" ))
199- })
200- })
201-
202- Context ("structAssignment" , func () {
203- BeforeEach (func () {
204- S1 = datatypes.User_Customer {Address1 : & A1 , Address2 : & A2 }
205- S2 = datatypes.User_Customer {Address1 : nil , Address2 : & B2 }
206- })
207-
208- It ("return succ" , func () {
209- user .StructAssignment (& S1 , & S2 )
210- Expect (* S1 .Address1 ).To (Equal ("11" ))
211- Expect (* S1 .Address2 ).To (Equal ("22" ))
212- })
213- })
214- })
136+ // dataValues are a set of 4 strings we set Default and UserValues to
137+ // expected is a set of 2 strings that we check were set properly
138+ DescribeTable ("StructAssignment Tests" ,
139+ func (dataValues []string , expected []string ) {
140+ Expect (len (dataValues )).To (Equal (4 ))
141+ Expect (len (expected )).To (Equal (2 ))
142+ Default := datatypes.User_Customer {Address1 : & dataValues [0 ], Address2 : & dataValues [1 ]}
143+ UserValues := datatypes.User_Customer {Address1 : & dataValues [2 ], Address2 : & dataValues [3 ]}
144+ // Can't set nil in the dataValues value because its a string, so we just do this
145+ if dataValues [0 ] == "nil" {
146+ Default .Address1 = nil
147+ }
148+ if dataValues [1 ] == "nil" {
149+ Default .Address2 = nil
150+ }
151+ if dataValues [2 ] == "nil" {
152+ UserValues .Address1 = nil
153+ }
154+ if dataValues [3 ] == "nil" {
155+ UserValues .Address2 = nil
156+ }
157+ user .StructAssignment (& Default , & UserValues )
158+ Expect (* Default .Address1 ).To (Equal (expected [0 ]))
159+ Expect (* Default .Address2 ).To (Equal (expected [1 ]))
160+ },
161+ Entry ("Test1" , []string {"Def1" , "Def2" , "UserInput1" , "nil" }, []string {"UserInput1" , "Def2" }),
162+ Entry ("Test2" , []string {"Def1" , "Def2" , "nil" , "UserInput2" }, []string {"Def1" , "UserInput2" }),
163+ Entry ("Test3" , []string {"Def1" , "nil" , "UserInput1" , "UserInput2" }, []string {"UserInput1" , "UserInput2" }),
164+ Entry ("Test4" , []string {"nil" , "Def2" , "UserInput1" , "UserInput2" }, []string {"UserInput1" , "UserInput2" }),
165+ )
215166})
0 commit comments