@@ -54,6 +54,22 @@ func TestNoAllocationNotFound(t *testing.T) {
5454 test .AssertHTTPStatus (t , http .StatusNotFound , & recorder )
5555}
5656
57+ // TestAllocationInvalidIDs verifies that on non-number requests for allocation IDs,
58+ // the API returs a Bad Request status code.
59+ func TestAllocationInvalidIDs (t * testing.T ) {
60+ r := test .Request (t , "GET" , "/v1/budgets/1/categories/1/envelopes/1/allocations/-2" , "" )
61+ test .AssertHTTPStatus (t , http .StatusBadRequest , & r )
62+
63+ r = test .Request (t , "GET" , "/v1/budgets/1/categories/1/envelopes/1/allocations/RoadWorkAhead" , "" )
64+ test .AssertHTTPStatus (t , http .StatusBadRequest , & r )
65+
66+ r = test .Request (t , "GET" , "/v1/budgets/1/categories/1/envelopes/-755/allocations/1" , "" )
67+ test .AssertHTTPStatus (t , http .StatusBadRequest , & r )
68+
69+ r = test .Request (t , "GET" , "/v1/budgets/1/categories/1/envelopes/WhatDoYourElfEyesSee/allocations/1" , "" )
70+ test .AssertHTTPStatus (t , http .StatusBadRequest , & r )
71+ }
72+
5773// TestNonexistingEnvelopeAllocations404 is a regression test for https://github.com/envelope-zero/backend/issues/89.
5874//
5975// It verifies that for a non-existing envelope, no matter if the category or budget exists,
@@ -81,6 +97,25 @@ func TestNonexistingBudgetAllocations404(t *testing.T) {
8197 test .AssertHTTPStatus (t , http .StatusNotFound , & recorder )
8298}
8399
100+ // TestAllocationParentChecked is a regression test for https://github.com/envelope-zero/backend/issues/90.
101+ //
102+ // It verifies that the allocations details endpoint for an envelope only returns allocations that belong to the
103+ // envelope.
104+ func TestAllocationParentChecked (t * testing.T ) {
105+ r := test .Request (t , "POST" , "/v1/budgets/1/categories/1/envelopes" , `{ "name": "Testing envelope" }` )
106+ test .AssertHTTPStatus (t , http .StatusCreated , & r )
107+
108+ var envelope EnvelopeDetailResponse
109+ test .DecodeResponse (t , & r , & envelope )
110+
111+ path := fmt .Sprintf ("/v1/budgets/1/categories/1/envelopes/%v" , envelope .Data .ID )
112+ r = test .Request (t , "GET" , path + "/allocations/1" , "" )
113+ test .AssertHTTPStatus (t , http .StatusNotFound , & r )
114+
115+ r = test .Request (t , "DELETE" , path , "" )
116+ test .AssertHTTPStatus (t , http .StatusNoContent , & r )
117+ }
118+
84119func TestCreateAllocation (t * testing.T ) {
85120 recorder := test .Request (t , "POST" , "/v1/budgets/1/categories/1/envelopes/1/allocations" , `{ "month": 10, "year": 2022, "amount": 15.42 }` )
86121 test .AssertHTTPStatus (t , http .StatusCreated , & recorder )
0 commit comments