@@ -81,6 +81,22 @@ func TestNoTransactionNotFound(t *testing.T) {
8181 test .AssertHTTPStatus (t , http .StatusNotFound , & recorder )
8282}
8383
84+ // TestTransactionInvalidIDs verifies that on non-number requests for transaction IDs,
85+ // the API returs a Bad Request status code.
86+ func TestTransactionInvalidIDs (t * testing.T ) {
87+ r := test .Request (t , "GET" , "/v1/budgets/1/transactions/-56" , "" )
88+ test .AssertHTTPStatus (t , http .StatusBadRequest , & r )
89+
90+ r = test .Request (t , "GET" , "/v1/budgets/1/transactions/notANumber" , "" )
91+ test .AssertHTTPStatus (t , http .StatusBadRequest , & r )
92+
93+ r = test .Request (t , "GET" , "/v1/budgets/-61/transactions/56" , "" )
94+ test .AssertHTTPStatus (t , http .StatusBadRequest , & r )
95+
96+ r = test .Request (t , "GET" , "/v1/budgets/RandomStringThatIsNotAUint64/transactions/1" , "" )
97+ test .AssertHTTPStatus (t , http .StatusBadRequest , & r )
98+ }
99+
84100// TestNonexistingBudgetTransactions404 is a regression test for https://github.com/envelope-zero/backend/issues/89.
85101//
86102// It verifies that for a non-existing budget, the accounts endpoint raises a 404
@@ -90,6 +106,25 @@ func TestNonexistingBudgetTransactions404(t *testing.T) {
90106 test .AssertHTTPStatus (t , http .StatusNotFound , & recorder )
91107}
92108
109+ // TestTransactionParentChecked is a regression test for https://github.com/envelope-zero/backend/issues/90.
110+ //
111+ // It verifies that the transaction details endpoint for a budget only returns transactions that belong to the
112+ // budget.
113+ func TestTransactionParentChecked (t * testing.T ) {
114+ r := test .Request (t , "POST" , "/v1/budgets" , `{ "name": "New Budget", "note": "More tests something something" }` )
115+ test .AssertHTTPStatus (t , http .StatusCreated , & r )
116+
117+ var budget BudgetDetailResponse
118+ test .DecodeResponse (t , & r , & budget )
119+
120+ path := fmt .Sprintf ("/v1/budgets/%v" , budget .Data .ID )
121+ r = test .Request (t , "GET" , path + "/transactions/1" , "" )
122+ test .AssertHTTPStatus (t , http .StatusNotFound , & r )
123+
124+ r = test .Request (t , "DELETE" , path , "" )
125+ test .AssertHTTPStatus (t , http .StatusNoContent , & r )
126+ }
127+
93128func TestCreateTransaction (t * testing.T ) {
94129 recorder := test .Request (t , "POST" , "/v1/budgets/1/transactions" , `{ "note": "More tests something something", "amount": 1253.17 }` )
95130 test .AssertHTTPStatus (t , http .StatusCreated , & recorder )
0 commit comments