refactor(tests): decompose getTestInstance to reduce complexity#8
Merged
refactor(tests): decompose getTestInstance to reduce complexity#8
Conversation
…cation The getAuthHeaders function contained two identical 8-line blocks for parsing session cookies from Set-Cookie headers. Extract this logic into a standalone helper function. Fallow report (before): test/helpers/test-instance.js:134-141 test/helpers/test-instance.js:159-166 Identical code blocks detected Fallow report (after): No duplication in test-instance.js This is the first step in reducing the complexity of getTestInstance.
The getAuthHeaders function had high cyclomatic (13) and cognitive (20)
complexity due to nested conditionals for handling 302 redirect errors.
Extract the cookie extraction logic from error responses into a dedicated
helper function.
Fallow health report (before):
test/helpers/test-instance.js:86 getAuthHeaders
13 cyclomatic 20 cognitive 66 lines
Functions exceeding cyclomatic or cognitive complexity thresholds
Fallow health report (after):
No high complexity functions
This refactoring separates the error handling concern and reduces the
cognitive load of the main getAuthHeaders function.
Extract the Better Auth configuration logic from getTestInstance into a dedicated createTestAuth factory function. This separates the auth setup concern from the orchestration logic. Key changes: - Created createTestAuth(db, magicLinksStore) function - Fixed closure issue by using external magicLinksStore array instead of auth._testMagicLinks property - getTestInstance now orchestrates rather than configures Fallow health improvement: - getTestInstance reduced from 120 lines to ~100 lines - Auth configuration now isolated and reusable
Extract the client helper creation logic from getTestInstance into a dedicated createTestClient factory function. This isolates the admin operations configuration. Key changes: - Created createTestClient(auth) function - Client helper logic now separated from main orchestration - Improves testability of admin operations Fallow health improvement: - getTestInstance further reduced in size - Client configuration now isolated and reusable
Extract the getAuthHeaders helper creation from getTestInstance into a dedicated createGetAuthHeaders factory function. This completes the decomposition of the large getTestInstance function. Key changes: - Created createGetAuthHeaders(auth, magicLinksStore) function - Returns the async getAuthHeaders function - Uses external magicLinksStore instead of auth._testMagicLinks Fallow health improvement: - getTestInstance reduced to ~20 lines (pure orchestration) - Large function warning completely resolved - All factory functions are independently testable
9a3ce33 to
1c4bda6
Compare
till
approved these changes
Apr 18, 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
Refactors
test/helpers/test-instance.jsto address code quality issues identified by fallow.Changes
parseSessionCookiehelper (eliminates duplication)extractCookieFromErrorhelper (reduces complexity)createTestAuthfactory functioncreateTestClientfactory functioncreateGetAuthHeadersfactory functionMeasured Improvements
All 28 tests pass.