@@ -239,29 +239,68 @@ func (suite *TestSuiteStandard) TestAccountsV3GetFilter() {
239239}
240240
241241func (suite * TestSuiteStandard ) TestAccountsV3CreateFails () {
242+ // Test account for uniqueness
243+ a := suite .createTestAccountV3 (suite .T (), controllers.AccountCreateV3 {
244+ Name : "Unique Account Name for Budget" ,
245+ })
246+
242247 tests := []struct {
243- name string
244- body any
245- status int // expected HTTP status
248+ name string
249+ body any
250+ status int // expected HTTP status
251+ testFunc func (t * testing.T , a controllers.AccountCreateResponseV3 ) // tests to perform against the updated account resource
246252 }{
247- {"Broken Body" , `[{ "note": 2 }]` , http .StatusBadRequest },
248- {"No body" , "" , http .StatusBadRequest },
253+ {"Broken Body" , `[{ "note": 2 }]` , http .StatusBadRequest , func (t * testing.T , a controllers.AccountCreateResponseV3 ) {
254+ assert .Equal (t , "json: cannot unmarshal number into Go struct field AccountCreateV3.note of type string" , * a .Error )
255+ }},
256+ {
257+ "No body" , "" , http .StatusBadRequest ,
258+ func (t * testing.T , a controllers.AccountCreateResponseV3 ) {
259+ assert .Equal (t , "the request body must not be empty" , * a .Error )
260+ },
261+ },
249262 {
250263 "No Budget" ,
251264 `[{ "note": "Some text" }]` ,
252265 http .StatusBadRequest ,
266+ func (t * testing.T , a controllers.AccountCreateResponseV3 ) {
267+ assert .Equal (t , "no Budget ID specified" , * a .Data [0 ].Error )
268+ },
253269 },
254270 {
255271 "Non-existing Budget" ,
256272 `[{ "budgetId": "ea85ad1a-3679-4ced-b83b-89566c12ece9" }]` ,
273+ http .StatusNotFound ,
274+ func (t * testing.T , a controllers.AccountCreateResponseV3 ) {
275+ assert .Equal (t , "there is no Budget with this ID" , * a .Data [0 ].Error )
276+ },
277+ },
278+ {
279+ "Duplicate name for budget" ,
280+ []controllers.AccountCreateV3 {
281+ {
282+ Name : a .Data .Name ,
283+ BudgetID : a .Data .BudgetID ,
284+ },
285+ },
257286 http .StatusBadRequest ,
287+ func (t * testing.T , a controllers.AccountCreateResponseV3 ) {
288+ assert .Equal (t , "the account name must be unique for the budget" , * a .Data [0 ].Error )
289+ },
258290 },
259291 }
260292
261293 for _ , tt := range tests {
262294 suite .T ().Run (tt .name , func (t * testing.T ) {
263- recorder := test .Request (suite .controller , t , http .MethodPost , "http://example.com/v3/accounts" , tt .body )
264- assertHTTPStatus (t , & recorder , tt .status )
295+ r := test .Request (suite .controller , t , http .MethodPost , "http://example.com/v3/accounts" , tt .body )
296+ assertHTTPStatus (t , & r , tt .status )
297+
298+ var a controllers.AccountCreateResponseV3
299+ decodeResponse (t , & r , & a )
300+
301+ if tt .testFunc != nil {
302+ tt .testFunc (t , a )
303+ }
265304 })
266305 }
267306}
0 commit comments