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

Refactoring code in src/middleware/admin.js to reduce cognitive complexity from 19 to 15 #406

Open
wants to merge 41 commits into
base: f24
Choose a base branch
from

Conversation

Driftedboat
Copy link

@Driftedboat Driftedboat commented Sep 3, 2024

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".
UI

Log Screenshot

The printing statement is embeded in the refractored code and here is the log screenshot. The statement is on the last line:
log

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.

@Driftedboat Driftedboat changed the title Refactoring code in src/middleware/admin.js #399Feature Refactoring code in src/middleware/admin.js Sep 3, 2024
@coveralls
Copy link

coveralls commented Sep 3, 2024

Pull Request Test Coverage Report for Build 10729957510

Details

  • 25 of 30 (83.33%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.04%) to 82.709%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/middleware/admin.js 25 30 83.33%
Totals Coverage Status
Change from base Build 10607818019: 0.04%
Covered Lines: 22336
Relevant Lines: 25586

💛 - Coveralls

Copy link

sonarcloud bot commented Sep 6, 2024

@Driftedboat 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
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants