-
Notifications
You must be signed in to change notification settings - Fork 224
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
Refactoring code in src/middleware/admin.js to reduce cognitive complexity from 19 to 15 #406
Open
Driftedboat
wants to merge
41
commits into
CMU-313:f24
Choose a base branch
from
Driftedboat:feature
base: f24
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains 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
Driftedboat
changed the title
Refactoring code in src/middleware/admin.js #399Feature
Refactoring code in src/middleware/admin.js
Sep 3, 2024
Pull Request Test Coverage Report for Build 10729957510Details
💛 - Coveralls |
Quality Gate passedIssues Measures |
Driftedboat
changed the title
Refactoring code in src/middleware/admin.js
Refactoring code in src/middleware/admin.js to reduce cognitive complexity from 19 to 15
Sep 6, 2024
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.
Overall Description
The code I refractored resolved the issue #371. In order to reduce the cognitive complexity from 19 to below 15, I break down the function by using several helper functions. The helper functions include isAccessDenied, hasNoPassword, handleReLogin, and extendLogOutTimer.
Manual Testing
The admin.js file inside middleware is mainly set up for checking the priviledge of the administrator, setting threshold.
To trigger the refractored code in UI, go to the "homepage"->then "groups" -> then choose an "administrator" -> then click on "administrator control panel".
Log Screenshot
The printing statement is embeded in the refractored code and here is the log screenshot. The statement is on the last line:
Coverage
Overall the coverage maintained and passed the check. The tests covered almost all the lines of code, except for part of the callback and next logics inside the code file.
The lines, callbacks and next() calls, are difficult to fully cover because they depend on specific conditions, like errors or unusual data states, which are hard to simulate reliably in tests. In addition, the asynchronous nature of callbacks also introduces side effects, causing the function to exit or alter flow unexpectedly, making these lines particularly challenging to reach compared to other code.