canove / whaticket-community

A very simple Ticket System based on WhatsApp messages, that allow multi-users in same WhatsApp account.
MIT License
1.61k stars 808 forks source link

Solving SonarCloud Critical / Major & Minor Errors - Improving Code Quality #572

Closed filypsdias closed 1 year ago

filypsdias commented 1 year ago

Description

This pull request addresses several code quality issues identified by SonarCloud and includes various code refactoring improvements. The changes made in this pull request enhance the overall maintainability and readability of the codebase, resolve existing issues, and ensure better adherence to best practices.

Overall, the number of issues fixed was:

image

Changes Made

1. Code Refactoring for Readability(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13):

2. Component Definition Optimization (1, 2, 3, 4):

As part of this pull request, we've addressed an issue related to defining components within the render phase in React. The error message "Do not define components during render" highlights the concern that React may interpret new component types during every render, leading to the destruction of DOM nodes and state within the entire subtree:

3. Cognitive Complexity Reduction(1, 2, 3):

Impact

Type of change

How Has This Been Tested?

Checklist:

Additional Notes

🥳 BONUS - Unit Tests Fix

Cool Stuff Added (Click to Open the Toggle) 1. [Sinon.JS](https://sinonjs.org/#get-started): Like Mockito, from Java development, Sinon is a JavaScript library used primarily for testing purposes, specifically in the context of unit testing and mocking. It was used more Stubs & Matchers - Stubs: Stubs are functions that replace the behavior of an existing function or method. You can use them to control the output of a function or simulate certain behaviors during testing. - Matchers: Sinon.js provides matchers that help you define expectations about function invocations, such as the arguments passed to them. Matchers make it easier to write tests that are more precise and targeted. 2. [Chai.js](https://www.chaijs.com/): Chai.js is another JavaScript library commonly used in testing, specifically in the context of behavior-driven development (BDD) and assertion testing 3. Changes to Package.json: In the latest version of the project, a significant improvement has been made to the testing process. Previously, it was necessary to run the sequelize seed command as a part of the pretest script. However, this approach led to validation errors if the seed had already been applied. To address this, the configuration has been adjusted. The sequelize seed command has been removed from the pretest script, ensuring a smoother testing experience without encountering validation conflicts due to redundant seeding. 4. Enhanced Testing Parallelism: A key enhancement has been introduced to the testing workflow. The test command now includes the ```--maxWorkers=1``` flag. This alteration has been made to promote testing singularity and prevent conflicts between different endpoints. By limiting the number of workers to one, the testing process operates in a more isolated manner. This adjustment minimizes the potential for interference and conflicts that might arise when multiple workers are executing tests concurrently. 5. Added tests for Contact Services: Just introducing some additional tests to the Contact Services to improve test coverage
image
sonarcloud[bot] commented 1 year ago

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 2 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication