Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix missing expectation in map not causing test failures #118

Merged
merged 6 commits into from
Jul 21, 2021

Conversation

kuhnroyal
Copy link
Collaborator

@kuhnroyal kuhnroyal commented Jul 17, 2021

Description

Fixes #117 and now causes unmatched expectations in header/query-params (everything that is matched via a map) to cause test failures. Previously they were just ignored.

Additionally this change gives the adapter/interceptor access to the BaseOptions in order to access default values which allows easy reuse of existing Dio instances and their configuration.

Also removed a lot of unused code in request matchers/handlers.

* the map of request signature to `MockResponse` is unused 
* the request signature in the the `RequestHandler` is unused
* it is not ideal to instantiate the adapter/interceptor like this but it is the only way to get access to the `BaseOptions`
* the `BaseOptions` contain information on default values, content-type and headers
@codecov-commenter
Copy link

codecov-commenter commented Jul 17, 2021

Codecov Report

Merging #118 (a18662f) into develop (85a01fc) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##           develop      #118   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           24        23    -1     
  Lines          251       255    +4     
=========================================
+ Hits           251       255    +4     
Impacted Files Coverage Δ
lib/src/adapters/dio_adapter.dart 100.00% <100.00%> (ø)
lib/src/extensions/matches_request.dart 100.00% <100.00%> (ø)
lib/src/handlers/request_handler.dart 100.00% <100.00%> (ø)
lib/src/interceptors/dio_interceptor.dart 100.00% <100.00%> (ø)
lib/src/mixins/recording.dart 100.00% <100.00%> (ø)
lib/src/mixins/request_handling.dart 100.00% <100.00%> (ø)
lib/src/request.dart 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 85a01fc...a18662f. Read the comment docs.

@LukaGiorgadze LukaGiorgadze added the bug Something isn't working label Jul 19, 2021
@LukaGiorgadze LukaGiorgadze added this to the Version 1.0.0 milestone Jul 19, 2021
theiskaa
theiskaa previously approved these changes Jul 19, 2021
Copy link
Contributor

@theiskaa theiskaa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything is ok for me, Thanks for the PR!

Copy link
Contributor

@GiorgiBeriashvili GiorgiBeriashvili left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, thank you for your work!

I added a suggestion to raise test coverage to 100% just for the sake of it, though it's just superficial. By trying edit tests for aforementioned reason, I noticed some difference between an adapter and an interceptor, namely how an adapter adds content-length automatically to the request headers, where an interceptors requires manual assignment. It is unrelated to your changes but it's good to know as it could be modified later to mock both cases in a similar way.

Relatedly, code base could also use some refactoring later for developer experience based on your changes, since it's MockServer server instead of request now, and dart automatically fills in the server instead of now-old request, rendering existing documentation/tests a bit outdated in a sense.

test/interceptors/dio_interceptor_test.dart Show resolved Hide resolved
* improve construction of `DioAdapter` and `DioInterceptor` and pass the full `Dio` instance - this additionally allows access to the configured `transformer`
* configure default headers in one place in `RequestHandling` which are usually set by `DioMixin`
* move `onRoute` implementation to `RequestHandling` as it is now the same for adapter and interceptor
* simplify `MatchesRequest` implementation
* apply new naming to tests, example and README
@kuhnroyal
Copy link
Collaborator Author

I added some further changes since I noticed due to @GiorgiBeriashvili's comment, that there was still a problem with some headers being added automatically and some not. I mainly created a central place where request headers are added, which are usually added by default by Dio.
Also the onRoute implementation is now the same for both DioAdapter and DioInterceptor - this simplifies things a lot.

  • improve construction of DioAdapter and DioInterceptor and pass the full Dio instance - this additionally allows access to the configured transformer
  • configure default headers in one place in RequestHandling which are usually set by DioMixin
  • move onRoute implementation to RequestHandling as it is now the same for adapter and interceptor
  • simplify MatchesRequest implementation
  • apply new naming to tests, example and README

Again there are no changes to test logic which should mean that there is no change in behavior.

lib/src/mixins/request_handling.dart Show resolved Hide resolved
lib/src/mixins/request_handling.dart Show resolved Hide resolved
lib/src/mixins/request_handling.dart Outdated Show resolved Hide resolved
@kuhnroyal
Copy link
Collaborator Author

Coverage is 100% now. Since most of the behavior is now in RequestHandling, we can probably run the exact same test suit against DioAdapter and DioInterceptor but this should be done in a separate PR.

@kuhnroyal
Copy link
Collaborator Author

After looking at #111 I think we should no longer add any default matchers on headers. This was needed because when matching the headers the code iterated over the actual headers and not the expectations (see #117). This is no longer the case, so we don't need the default matchers, this would make everything lot more transparent and prevent issues like in #111.

I will prepare this also in a separate PR once this one is merged.

Copy link
Contributor

@GiorgiBeriashvili GiorgiBeriashvili left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After looking at #111 I think we should no longer add any default matchers on headers. This was needed because when matching the headers the code iterated over the actual headers and not the expectations (see #117). This is no longer the case, so we don't need the default matchers, this would make everything lot more transparent and prevent issues like in #111.

I will prepare this also in a separate PR once this one is merged.

Agreed. Everything is more than acceptable for me.

Copy link
Contributor

@theiskaa theiskaa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved! (again :D)

Thanks for contributing!

@kuhnroyal
Copy link
Collaborator Author

Would be great if you guys can cut a release with this. Kinda need this in OpenAPITools/openapi-generator#9975 :)

@GiorgiBeriashvili
Copy link
Contributor

Would be great if you guys can cut a release with this. Kinda need this in OpenAPITools/openapi-generator#9975 :)

It's live now, sorry for the delay.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants