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/render.js to Reduce Cognitive Complexity from 16 to 15 #489

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

Conversation

vickyc2266
Copy link

@vickyc2266 vickyc2266 commented Sep 4, 2024

Reduced cognitive complexity of the renderMethod which is within the processRender function of the render.js file by taking away a conditional that appears in the code more than once and putting it into a helper function with an intuitive title called checkHeadersSent(res). The function here is supposed to provide the same exact logic as the original code but just putting it in into a function and calling that function where it is needed.
resolves #340

UI Test

  1. Login Successfully as admin
  2. Able to Run Server Successfully
  3. Able to access different and render different UI pages

…s 71 with the checkHeadersSent(res) helper method to reduce cognitive complexity
…oes) and saw that the coverage displayed increased coverage in lines and function compared to previously
…e original code just to see if it'll work and pass test cases now
@coveralls
Copy link

coveralls commented Sep 5, 2024

Pull Request Test Coverage Report for Build 10722278560

Details

  • 6 of 7 (85.71%) changed or added relevant lines in 1 file are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage increased (+0.003%) to 82.674%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/middleware/render.js 6 7 85.71%
Files with Coverage Reduction New Missed Lines %
src/meta/errors.js 1 76.74%
Totals Coverage Status
Change from base Build 10607818019: 0.003%
Covered Lines: 22327
Relevant Lines: 25585

💛 - Coveralls

Copy link

sonarcloud bot commented Sep 5, 2024

@vickyc2266 vickyc2266 changed the title Render method refactor Refactoring code in src/middleware/render.js Sep 5, 2024
@vickyc2266
Copy link
Author

vickyc2266 commented Sep 6, 2024

I'm not sure why I'm missing a line of code coverage (from the pull request details above) from the code I've added to the file because this issue I've chosen is extremely difficult to test since it has to do with the rendering of the UI users sees and validates whether a response header has been sent. In the test > middleware.js file where I believe locates all the test cases for code that's in the middleware folder of src, I tried to add test cases that tests the code I've added (regarding the conditions of the resHeader) by making mock data and mock headers. Although I've set these headers to true and asserted the outcome to be true, the coverage file for some reason is still warning me that I haven't tested when the case is true.

Screenshot 2024-09-05 at 11 14 47 PM

From the screenshot provided above, the only line of code that's written by me and highlighted red would be "return true" statement which I do test in the test case example provided in the screenshot below:
Screenshot 2024-09-05 at 11 19 01 PM

@vickyc2266 vickyc2266 changed the title Refactoring code in src/middleware/render.js Refactoring code in src/middleware/render.js to Reduce Cognitive Complexity from 16 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.

Refactoring code in src/middleware/render.js
2 participants