test: add utility tests and fix advanced search handling#2615
test: add utility tests and fix advanced search handling#2615samuelcney wants to merge 4 commits into
Conversation
…on handlers and error response utilities
…, createJid, and createMetaErrorResponse utilities
…ion, and findBotByTrigger utilities
Reviewer's GuideThis PR introduces Jest-based automated testing for key utility and exception logic, adds targeted unit tests with supporting mocks, and hardens the advanced text search utility to safely ignore empty or malformed operators. File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- In package.json devDependencies, ts-jest and ts-node are listed twice; remove the duplicates to keep the configuration clean and avoid confusion.
- In jest.config.ts, you’re overriding several TypeScript compiler options inside ts-jest; consider referencing the existing tsconfig instead of redefining options to avoid divergence between test and production builds.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In package.json devDependencies, ts-jest and ts-node are listed twice; remove the duplicates to keep the configuration clean and avoid confusion.
- In jest.config.ts, you’re overriding several TypeScript compiler options inside ts-jest; consider referencing the existing tsconfig instead of redefining options to avoid divergence between test and production builds.
## Individual Comments
### Comment 1
<location path="jest.config.ts" line_range="47-44" />
<code_context>
+ },
+
+ // ts-jest configuration
+ transform: {
+ '^.+\\.tsx?$': [
+ 'ts-jest',
+ {
+ tsconfig: {
+ // Relax strict mode for tests
+ strict: false,
+ strictNullChecks: false,
+ esModuleInterop: true,
+ // Point rootDir to project root so test files are included
+ rootDir: './',
+ },
+ },
+ ],
</code_context>
<issue_to_address>
**suggestion:** Consider pointing ts-jest at the existing tsconfig instead of an inline override.
The custom tsconfig block here (e.g., strict: false, rootDir: './') can drift from tsconfig.json and cause tests to compile differently from the app. Prefer using ts-jest’s `tsconfig` option to point at the main tsconfig (or a dedicated test tsconfig) so the configuration stays consistent and easier to maintain.
Suggested implementation:
```typescript
'^@utils/(.*)$': '<rootDir>/src/utils/$1',
'^@validate/(.*)$': '<rootDir>/src/validate/$1',
},
// ts-jest configuration
transform: {
'^.+\\.tsx?$': [
'ts-jest',
{
// Use the main TypeScript configuration to keep tests aligned
// with the application compilation settings.
tsconfig: '<rootDir>/tsconfig.json',
},
],
},
// Map TypeScript path aliases to actual paths (mirrors tsconfig.json paths)
moduleNameMapper: {
```
- If you have a dedicated test TypeScript configuration (e.g., `tsconfig.test.json`), update the `tsconfig` path accordingly: `tsconfig: '<rootDir>/tsconfig.test.json'`.
- Make sure `ts-jest` is correctly set up in the rest of `jest.config.ts` (e.g., `preset: 'ts-jest'` if you are using the preset); adjust as needed to match existing project conventions.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| '^@libs/(.*)$': '<rootDir>/src/libs/$1', | ||
| '^@utils/(.*)$': '<rootDir>/src/utils/$1', | ||
| '^@validate/(.*)$': '<rootDir>/src/validate/$1', | ||
| }, |
There was a problem hiding this comment.
suggestion: Consider pointing ts-jest at the existing tsconfig instead of an inline override.
The custom tsconfig block here (e.g., strict: false, rootDir: './') can drift from tsconfig.json and cause tests to compile differently from the app. Prefer using ts-jest’s tsconfig option to point at the main tsconfig (or a dedicated test tsconfig) so the configuration stays consistent and easier to maintain.
Suggested implementation:
'^@utils/(.*)$': '<rootDir>/src/utils/$1',
'^@validate/(.*)$': '<rootDir>/src/validate/$1',
},
// ts-jest configuration
transform: {
'^.+\\.tsx?$': [
'ts-jest',
{
// Use the main TypeScript configuration to keep tests aligned
// with the application compilation settings.
tsconfig: '<rootDir>/tsconfig.json',
},
],
},
// Map TypeScript path aliases to actual paths (mirrors tsconfig.json paths)
moduleNameMapper: {- If you have a dedicated test TypeScript configuration (e.g.,
tsconfig.test.json), update thetsconfigpath accordingly:tsconfig: '<rootDir>/tsconfig.test.json'. - Make sure
ts-jestis correctly set up in the rest ofjest.config.ts(e.g.,preset: 'ts-jest'if you are using the preset); adjust as needed to match existing project conventions.
Description
This PR adds an initial automated test setup and unit test coverage for selected utility functions in the Evolution API project.
The work was developed as part of an academic Software Testing assignment, using the project as a real-world open-source codebase to apply testing techniques in practice.
Changes
Added Jest configuration with TypeScript support.
Added unit tests for utility functions related to:
Added mocks to isolate external dependencies such as:
Bug fix
While writing structural tests for the advanced text search logic, an issue was found in the handling of empty or malformed search operators.
This PR adds safer handling for these cases, preventing invalid query parts from affecting the expected search behavior.
Notes
The goal of this contribution is to provide an initial testing foundation for critical utility logic, making it easier to validate future changes and expand test coverage over time.
Summary by Sourcery
Introduce Jest-based testing infrastructure and add initial unit tests for critical utility and exception handling logic, while tightening advanced search operator input validation.
Bug Fixes:
Build:
Tests: