Feature/maintenance updates - #2
Merged
Merged
Conversation
- Ensure `Idempotency` and `AuthRefresh` middleware are properly registered in the Faraday connection, enabling automatic `request_id` generation and 401 retry behavior. - Corrected a bug in `AuthRefresh` related to the 401-retry guard. - Update CI configuration to trigger on pushes to `main` instead of `master`. - Refactor `Client#request` to delegate `Authorization` header management to the `AuthRefresh` middleware. - Update dependencies in `Gemfile.lock` for improved compatibility and performance.
eddyjaga
approved these changes
Aug 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two middleware classes (
Idempotency,AuthRefresh) existed in the codebase but were never registered on the Faraday connection, so the behavior the README documents — automaticrequest_idgeneration and retry-once-on-401 — never actually happened at runtime. This PR wires both in, fixes a crash bug found in the process, and cleans up a large amount of duplicated test setup along the way.Fixes
IdempotencyandAuthRefreshmiddleware are now actually active. Both were fully implemented and tested in isolation, but neither was ever passed toconn.useinClient#connection— dead code with no effect on real requests. Now registered in the correct order (Idempotencybefore JSON body encoding so it sees aHash;AuthRefreshclosest to the adapter).AuthRefresh. Its 401-retry guard usedenv[:request][:auth_retry], butenv[:request]is aFaraday::RequestOptionsstruct with a fixed set of members —:auth_retryisn't one of them, so the first real 401 response would have raisedNoMethodError. Replaced with a self-contained method (no state needs to persist across calls, so no guard flag is needed at all).main. Workflow was configured forpush: branches: [master]; the repo's default branch ismain, so direct pushes never ran CI (only PRs did, sincepull_request:has no branch filter).Client#authenticate!.req.headers.delete("Authorization")was deleting a key from a hash that can never contain it — verified empirically thatFaraday::Connection#build_requestalways starts each request from a fresh.dupof the connection's persistent default headers, which never includeAuthorization.Changed
Client#requestno longer manually manages theAuthorizationheader or callsensure_authenticated!— both are now owned by theAuthRefreshmiddleware./api/v1/authentication/loginpath intoClient::LOGIN_PATH, referenced from bothclient.rbandauth_refresh.rbinstead of being duplicated as a string literal.bundle update— patch/minor dependency bumps only (faraday, rubocop, webmock, etc.), no Gemfile changes required.Test suite cleanup
The same login-stub
beforeblock (and often an identicallet(:auth_response)) was copy-pasted into ~19 spec files, alongside 153 literal occurrences of the sandbox host URL. Centralized both intospec/support/airwallex_test_helpers.rb:BASE_URL/LOGIN_PATHconstants (sourced from the realAirwallex::Configuration::SANDBOX_API_URL/Airwallex::Client::LOGIN_PATH, not re-hardcoded)stub_loginhelper, auto-applied via a globalconfig.beforehook so individual specs no longer need to stub it themselvesAdded
spec/airwallex/middleware/auth_refresh_spec.rb— there was previously zero test coverage for this middleware.Testing
bundle exec rake(rspec + rubocop): 286 examples, 0 failures, rubocop cleanrequest_idis now injected into POST bodies, and the 401 → re-authenticate → retry-once flow workslocal_tests/smoke_test.rb, gitignored) acrossauthenticate!,Balance.list,Rate.retrieve, and severallist()calls — all passingNeed help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.