@@ -55,7 +55,13 @@ func TestCategoryInvalidIDs(t *testing.T) {
5555 r := test .Request (t , "GET" , "/v1/budgets/1/categories/-557" , "" )
5656 test .AssertHTTPStatus (t , http .StatusBadRequest , & r )
5757
58- r = test .Request (t , "GET" , "/v1/budgets/1/categories/HanShotFirst" , "" )
58+ r = test .Request (t , "GET" , "/v1/budgets/1/categories/NFTsAreAScam" , "" )
59+ test .AssertHTTPStatus (t , http .StatusBadRequest , & r )
60+
61+ r = test .Request (t , "GET" , "/v1/budgets/-574/categories/56" , "" )
62+ test .AssertHTTPStatus (t , http .StatusBadRequest , & r )
63+
64+ r = test .Request (t , "GET" , "/v1/budgets/NoReallyNFTsAreAScam/categories/1" , "" )
5965 test .AssertHTTPStatus (t , http .StatusBadRequest , & r )
6066}
6167
@@ -68,6 +74,25 @@ func TestNonexistingBudgetCategories404(t *testing.T) {
6874 test .AssertHTTPStatus (t , http .StatusNotFound , & recorder )
6975}
7076
77+ // TestCategoryParentChecked is a regression test for https://github.com/envelope-zero/backend/issues/90.
78+ //
79+ // It verifies that the category details endpoint for a budget only returns categorys that belong to the
80+ // budget.
81+ func TestCategoryParentChecked (t * testing.T ) {
82+ r := test .Request (t , "POST" , "/v1/budgets" , `{ "name": "New Budget", "note": "More tests something something" }` )
83+ test .AssertHTTPStatus (t , http .StatusCreated , & r )
84+
85+ var budget BudgetDetailResponse
86+ test .DecodeResponse (t , & r , & budget )
87+
88+ path := fmt .Sprintf ("/v1/budgets/%v" , budget .Data .ID )
89+ r = test .Request (t , "GET" , path + "/categories/1" , "" )
90+ test .AssertHTTPStatus (t , http .StatusNotFound , & r )
91+
92+ r = test .Request (t , "DELETE" , path , "" )
93+ test .AssertHTTPStatus (t , http .StatusNoContent , & r )
94+ }
95+
7196func TestCreateCategory (t * testing.T ) {
7297 recorder := test .Request (t , "POST" , "/v1/budgets/1/categories" , `{ "name": "New Category", "note": "More tests something something" }` )
7398 test .AssertHTTPStatus (t , http .StatusCreated , & recorder )
0 commit comments