Skip to content

Unit Tests for Server App#24

Merged
Rubinskiy merged 37 commits intostagingfrom
15-testing-in-cicd
Jan 17, 2026
Merged

Unit Tests for Server App#24
Rubinskiy merged 37 commits intostagingfrom
15-testing-in-cicd

Conversation

@Rubinskiy
Copy link
Member

Comprehensive coverage of the server app MessageProcessor's class with 25+ test cases:

  • Isolation using mocks: Mocked the config module to avoid real dependencies
  • Tests all methods: filterMessage, validateMessage, processChatMessage, createSystemMessage, createHistoryEndMessage, formatHistoryMessage
  • Edge cases covered: Invalid inputs, boundary conditions, profanity filtering, message length limits

@Rubinskiy Rubinskiy self-assigned this Jan 17, 2026
Copilot AI review requested due to automatic review settings January 17, 2026 11:10
@Rubinskiy Rubinskiy added the testing Testing code or others label Jan 17, 2026
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces comprehensive unit testing for the server's MessageProcessor class and restructures the codebase into a modular architecture.

Changes:

  • Added 25+ test cases for MessageProcessor covering validation, filtering, message processing, and edge cases
  • Refactored server and consumer into modular architecture with separate services, utilities, and configuration
  • Added performance testing infrastructure, documentation, and CI/CD improvements

Reviewed changes

Copilot reviewed 52 out of 55 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
server/tests/messageProcessor.test.js New comprehensive test suite for MessageProcessor with 25+ test cases
server/services/messageProcessor.js New modular MessageProcessor service extracted from monolithic code
server/services/redis.js New Redis service with connection management and stream operations
server/services/database.js New database service with connection pooling and message queries
server/services/chatService.js New chat service orchestrating message handling across services
server/utils/logger.js New centralized logging utility with color-coded output
server/config/index.js New configuration management with environment validation
consumer/consumer.js Refactored consumer with modular architecture and graceful shutdown
consumer/services/* New modular consumer services (redis, database, batchProcessor)
tests/* New performance and load testing infrastructure
package.json Updated dependencies including Jest, Socket.io, and p-limit
Comments suppressed due to low confidence (3)

server/tests/messageProcessor.test.js:1

  • This assertion will fail intermittently due to timing differences. Date.now() is called twice - once inside formatHistoryMessage and once in the test assertion - resulting in different values. Use a range check or mock Date.now() instead.
    server/services/redis.js:1
  • The deprecation notice should specify which newer method to use instead. Add a reference to the recommended alternative method.
    server/package.json:1
  • Using set for environment variables is Windows-specific and will fail on Unix-based systems. Use the cross-env package (already listed in devDependencies) to make the commands cross-platform: cross-env NODE_OPTIONS=--experimental-vm-modules npx jest

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copilot AI review requested due to automatic review settings January 17, 2026 11:45
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 52 out of 55 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (1)

sonar-project.properties:1

  • Duplicate 'sonar.sources' property on lines 3 and 7. Remove the duplicate definition to avoid configuration ambiguity.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copilot AI review requested due to automatic review settings January 17, 2026 12:22
Copilot AI review requested due to automatic review settings January 17, 2026 13:42
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 53 out of 57 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (1)

sonar-project.properties:1

  • The sonar.sources property is defined twice (lines 3 and 7). Remove the duplicate definition to avoid potential configuration conflicts.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copilot AI review requested due to automatic review settings January 17, 2026 13:52
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 53 out of 57 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (2)

sonar-project.properties:1

  • The sonar.sources property is duplicated on lines 3 and 7. Remove the duplicate on line 7 to avoid configuration conflicts.
    server/tests/messageProcessor.test.js:1
  • This test assertion will fail due to timing issues. Date.now() will return a different value when the expectation runs compared to when the timestamp was set. Use a range check or mock Date.now() instead.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copilot AI review requested due to automatic review settings January 17, 2026 14:19
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 53 out of 57 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (2)

server/tests/messageProcessor.test.js:1

  • The test compares result.timestamp to Date.now() directly, which will fail due to timing differences. Use a range check or mock Date.now() instead.
    sonar-project.properties:1
  • The sonar.sources property is defined twice (lines 3 and 7). Remove the duplicate declaration on line 7.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


try {
// Send welcome message
const welcomeMessage = messageProcessor.createSystemMessage('Welcome to the chat! Version 1.0.2');
Copy link

Copilot AI Jan 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The version string is hardcoded. Consider moving it to the configuration file for easier version management.

Suggested change
const welcomeMessage = messageProcessor.createSystemMessage('Welcome to the chat! Version 1.0.2');
const appVersion = SERVER_CONFIG.VERSION ?? '1.0.2';
const welcomeMessage = messageProcessor.createSystemMessage(`Welcome to the chat! Version ${appVersion}`);

Copilot uses AI. Check for mistakes.
@sonarqubecloud
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
0.0% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

Copilot AI review requested due to automatic review settings January 17, 2026 14:33
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 53 out of 57 changed files in this pull request and generated 2 comments.

Comments suppressed due to low confidence (1)

sonar-project.properties:1

  • Duplicate sonar.sources property on lines 3 and 7. Remove the duplicate declaration to avoid configuration conflicts.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

"redis": "^5.9.0",
"uWebSockets.js": "uNetworking/uWebSockets.js#v20.44.0"
"socket.io": "^4.8.1",
"uWebSockets.js": "github:uNetworking/uWebSockets.js#v20.44.0",
Copy link

Copilot AI Jan 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent dependency specification format. Line 17 uses github: prefix while other dependencies use standard npm registry format. Consider using consistent format throughout.

Copilot uses AI. Check for mistakes.
Comment on lines +4 to 7
push:
branches:
- main

Copy link

Copilot AI Jan 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed workflow trigger from workflow_dispatch to automatic push on main branch. This will trigger builds on every push to main, which may increase CI costs and could deploy untested changes. Consider adding a manual approval step or keeping workflow_dispatch for production deployments.

Suggested change
push:
branches:
- main
workflow_dispatch:

Copilot uses AI. Check for mistakes.
Copilot AI review requested due to automatic review settings January 17, 2026 14:54
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 53 out of 57 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (4)

server/services/redis.js:1

  • The deprecation warning should include information about what method should be used instead. Add a recommendation for the replacement method to help developers migrate away from this deprecated functionality.
    sonar-project.properties:1
  • The sonar.sources property is duplicated on lines 3 and 7. Remove the duplicate declaration to avoid potential configuration conflicts.
    sonar-project.properties:1
  • The sonar.sources property is duplicated on lines 3 and 7. Remove the duplicate declaration to avoid potential configuration conflicts.
    server/tests/messageProcessor.test.js:1
  • This assertion will be flaky because Date.now() is called at test definition time, not when the method executes. The values will almost never match exactly. Use expect.any(Number) or check that the timestamp is within a reasonable range instead.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

* @param {number} blockMs - Block timeout in milliseconds
* @returns {Promise<Array>} Array of messages
*/
async readMessages(count = 500, blockMs = 10) {
Copy link

Copilot AI Jan 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default blockMs value of 10 milliseconds is very low and may cause excessive CPU usage from rapid polling. Consider increasing this to at least 1000ms (1 second) for better efficiency, or make it configurable based on workload requirements.

Suggested change
async readMessages(count = 500, blockMs = 10) {
async readMessages(count = 500, blockMs = 1000) {

Copilot uses AI. Check for mistakes.
@Rubinskiy Rubinskiy merged commit de0f6e2 into staging Jan 17, 2026
7 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

testing Testing code or others

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants