@@ -19,7 +19,7 @@ func TestSetGeneralConfigHandler(t *testing.T) {
1919 useCase .EXPECT ().Run (mock .Anything , mock .Anything ).Return (nil )
2020
2121 handler := handlers .NewSetGeneralConfigHandler (useCase )
22- reqBody := `{"configuration": {"btcConfirmations": {"5": 10}, "rskConfirmations": {"10": 20}, "publicLiquidityCheck": true, "maxLiquidity": "1000"}}`
22+ reqBody := `{"configuration": {"btcConfirmations": {"5": 10}, "rskConfirmations": {"10": 20}, "publicLiquidityCheck": true, "maxLiquidity": "1000", "excessToleranceFixed": "0", "excessTolerancePercentage": 0 }}`
2323 req := httptest .NewRequest (http .MethodPost , "/configuration" , strings .NewReader (reqBody ))
2424 req .Header .Set ("Content-Type" , "application/json" )
2525 w := httptest .NewRecorder ()
@@ -116,7 +116,7 @@ func TestSetGeneralConfigHandler(t *testing.T) {
116116
117117 handler := handlers .NewSetGeneralConfigHandler (useCase )
118118 // 1 RBTC in wei (18 decimal places) - valid large integer
119- reqBody := `{"configuration": {"btcConfirmations": {"5": 10}, "rskConfirmations": {"10": 20}, "publicLiquidityCheck": true, "maxLiquidity": "1000000000000000000"}}`
119+ reqBody := `{"configuration": {"btcConfirmations": {"5": 10}, "rskConfirmations": {"10": 20}, "publicLiquidityCheck": true, "maxLiquidity": "1000000000000000000", "excessToleranceFixed": "0", "excessTolerancePercentage": 0 }}`
120120 req := httptest .NewRequest (http .MethodPost , "/configuration" , strings .NewReader (reqBody ))
121121 req .Header .Set ("Content-Type" , "application/json" )
122122 w := httptest .NewRecorder ()
@@ -129,12 +129,98 @@ func TestSetGeneralConfigHandler(t *testing.T) {
129129 useCase .EXPECT ().Run (mock .Anything , mock .Anything ).Return (assert .AnError )
130130
131131 handler := handlers .NewSetGeneralConfigHandler (useCase )
132- reqBody := `{"configuration": {"btcConfirmations": {"5": 10}, "rskConfirmations": {"10": 20}, "publicLiquidityCheck": true, "maxLiquidity": "1000"}}`
132+ reqBody := `{"configuration": {"btcConfirmations": {"5": 10}, "rskConfirmations": {"10": 20}, "publicLiquidityCheck": true, "maxLiquidity": "1000", "excessToleranceFixed": "0", "excessTolerancePercentage": 0 }}`
133133 req := httptest .NewRequest (http .MethodPost , "/configuration" , strings .NewReader (reqBody ))
134134 req .Header .Set ("Content-Type" , "application/json" )
135135 w := httptest .NewRecorder ()
136136 handler (w , req )
137137 assert .Equal (t , http .StatusInternalServerError , w .Code )
138138 useCase .AssertExpectations (t )
139139 })
140+ t .Run ("should return success with valid excessToleranceFixed" , func (t * testing.T ) {
141+ useCase := new (mocks.SetGeneralConfigUseCaseMock )
142+ useCase .EXPECT ().Run (mock .Anything , mock .Anything ).Return (nil )
143+
144+ handler := handlers .NewSetGeneralConfigHandler (useCase )
145+ reqBody := `{"configuration": {"btcConfirmations": {"5": 10}, "rskConfirmations": {"10": 20}, "publicLiquidityCheck": true, "maxLiquidity": "1000", "excessToleranceFixed": "5000000000000000000", "excessTolerancePercentage": 0}}`
146+ req := httptest .NewRequest (http .MethodPost , "/configuration" , strings .NewReader (reqBody ))
147+ req .Header .Set ("Content-Type" , "application/json" )
148+ w := httptest .NewRecorder ()
149+ handler (w , req )
150+ assert .Equal (t , http .StatusNoContent , w .Code )
151+ useCase .AssertExpectations (t )
152+ })
153+ t .Run ("should return success with valid excessTolerancePercentage" , func (t * testing.T ) {
154+ useCase := new (mocks.SetGeneralConfigUseCaseMock )
155+ useCase .EXPECT ().Run (mock .Anything , mock .Anything ).Return (nil )
156+
157+ handler := handlers .NewSetGeneralConfigHandler (useCase )
158+ reqBody := `{"configuration": {"btcConfirmations": {"5": 10}, "rskConfirmations": {"10": 20}, "publicLiquidityCheck": true, "maxLiquidity": "1000", "excessToleranceFixed": "0", "excessTolerancePercentage": 5.5}}`
159+ req := httptest .NewRequest (http .MethodPost , "/configuration" , strings .NewReader (reqBody ))
160+ req .Header .Set ("Content-Type" , "application/json" )
161+ w := httptest .NewRecorder ()
162+ handler (w , req )
163+ assert .Equal (t , http .StatusNoContent , w .Code )
164+ useCase .AssertExpectations (t )
165+ })
166+ t .Run ("should return bad request if excessToleranceFixed is negative" , func (t * testing.T ) {
167+ useCase := new (mocks.SetGeneralConfigUseCaseMock )
168+
169+ handler := handlers .NewSetGeneralConfigHandler (useCase )
170+ reqBody := `{"configuration": {"btcConfirmations": {"5": 10}, "rskConfirmations": {"10": 20}, "publicLiquidityCheck": true, "maxLiquidity": "1000", "excessToleranceFixed": "-100", "excessTolerancePercentage": 0}}`
171+ req := httptest .NewRequest (http .MethodPost , "/configuration" , strings .NewReader (reqBody ))
172+ req .Header .Set ("Content-Type" , "application/json" )
173+ w := httptest .NewRecorder ()
174+ handler (w , req )
175+ assert .Equal (t , http .StatusBadRequest , w .Code )
176+ useCase .AssertNotCalled (t , "Run" )
177+ })
178+ t .Run ("should return bad request if excessToleranceFixed is not a number" , func (t * testing.T ) {
179+ useCase := new (mocks.SetGeneralConfigUseCaseMock )
180+
181+ handler := handlers .NewSetGeneralConfigHandler (useCase )
182+ reqBody := `{"configuration": {"btcConfirmations": {"5": 10}, "rskConfirmations": {"10": 20}, "publicLiquidityCheck": true, "maxLiquidity": "1000", "excessToleranceFixed": "not_a_number", "excessTolerancePercentage": 0}}`
183+ req := httptest .NewRequest (http .MethodPost , "/configuration" , strings .NewReader (reqBody ))
184+ req .Header .Set ("Content-Type" , "application/json" )
185+ w := httptest .NewRecorder ()
186+ handler (w , req )
187+ assert .Equal (t , http .StatusBadRequest , w .Code )
188+ useCase .AssertNotCalled (t , "Run" )
189+ })
190+ t .Run ("should return bad request if excessToleranceFixed has decimal places" , func (t * testing.T ) {
191+ useCase := new (mocks.SetGeneralConfigUseCaseMock )
192+
193+ handler := handlers .NewSetGeneralConfigHandler (useCase )
194+ reqBody := `{"configuration": {"btcConfirmations": {"5": 10}, "rskConfirmations": {"10": 20}, "publicLiquidityCheck": true, "maxLiquidity": "1000", "excessToleranceFixed": "100.5", "excessTolerancePercentage": 0}}`
195+ req := httptest .NewRequest (http .MethodPost , "/configuration" , strings .NewReader (reqBody ))
196+ req .Header .Set ("Content-Type" , "application/json" )
197+ w := httptest .NewRecorder ()
198+ handler (w , req )
199+ assert .Equal (t , http .StatusBadRequest , w .Code )
200+ useCase .AssertNotCalled (t , "Run" )
201+ })
202+ t .Run ("should return bad request if excessTolerancePercentage is negative" , func (t * testing.T ) {
203+ useCase := new (mocks.SetGeneralConfigUseCaseMock )
204+
205+ handler := handlers .NewSetGeneralConfigHandler (useCase )
206+ reqBody := `{"configuration": {"btcConfirmations": {"5": 10}, "rskConfirmations": {"10": 20}, "publicLiquidityCheck": true, "maxLiquidity": "1000", "excessToleranceFixed": "0", "excessTolerancePercentage": -5}}`
207+ req := httptest .NewRequest (http .MethodPost , "/configuration" , strings .NewReader (reqBody ))
208+ req .Header .Set ("Content-Type" , "application/json" )
209+ w := httptest .NewRecorder ()
210+ handler (w , req )
211+ assert .Equal (t , http .StatusBadRequest , w .Code )
212+ useCase .AssertNotCalled (t , "Run" )
213+ })
214+ t .Run ("should return bad request if excessTolerancePercentage exceeds 100" , func (t * testing.T ) {
215+ useCase := new (mocks.SetGeneralConfigUseCaseMock )
216+
217+ handler := handlers .NewSetGeneralConfigHandler (useCase )
218+ reqBody := `{"configuration": {"btcConfirmations": {"5": 10}, "rskConfirmations": {"10": 20}, "publicLiquidityCheck": true, "maxLiquidity": "1000", "excessToleranceFixed": "0", "excessTolerancePercentage": 150}}`
219+ req := httptest .NewRequest (http .MethodPost , "/configuration" , strings .NewReader (reqBody ))
220+ req .Header .Set ("Content-Type" , "application/json" )
221+ w := httptest .NewRecorder ()
222+ handler (w , req )
223+ assert .Equal (t , http .StatusBadRequest , w .Code )
224+ useCase .AssertNotCalled (t , "Run" )
225+ })
140226}
0 commit comments