foss42 / apidash

API Dash is a beautiful open-source cross-platform API Client built using Flutter which can help you easily create & customize your API requests, visually inspect responses and generate API integration code. A lightweight alternative to postman/insomnia.
https://apidash.dev
Apache License 2.0
1.43k stars 269 forks source link

Improve http service #361

Closed sixtusagbo closed 5 months ago

sixtusagbo commented 5 months ago

PR Description

I was trying to mock the request made on the app by mocking the http.request() method because parts of it that makes the request using http.Client object and it needs to be replaced to avoid making actual requests in the case of unit and widget tests.

I went through the code in http_service.dart and it does not accept as a parameter http.Client object. And collectionStateNotifierProvider does not accept http.Client object as a parameter too. If it accepts a client object (as a parameter), anyone will be able to override the client when testing in order mock the http request or to unit test the service http_service.dart.

Related Issues

Checklist

Added/updated tests?

We encourage you to add relevant test cases.

ashitaprasad commented 5 months ago

We will currently not make any changes to the http_service. Instead of mocking the request you can send an actual request in the tests as these apis are also maintained by us.

sixtusagbo commented 5 months ago

Okay, I've removed the mocks. I am sending actual requests now. I've completed test cases for codePaneVisibleStateProvider

animator commented 5 months ago

Just like we have defined example request models in https://github.com/foss42/apidash/blob/main/test/request_models.dart, you need to add constants like the URL used in tests in https://github.com/foss42/apidash/blob/main/test/test_consts.dart Also, use api.apidash.dev not api.foss42.com

sixtusagbo commented 5 months ago

Okay Sir, I just updated the files now.

animator commented 5 months ago

LGTM 🚀