Skip to content

Add unit tests for Workflow Manager#169

Merged
sthanikan2000 merged 2 commits intoOpenNSW:mainfrom
ginaxu1:153-unit-test-Workflow
Feb 25, 2026
Merged

Add unit tests for Workflow Manager#169
sthanikan2000 merged 2 commits intoOpenNSW:mainfrom
ginaxu1:153-unit-test-Workflow

Conversation

@ginaxu1
Copy link
Contributor

@ginaxu1 ginaxu1 commented Feb 19, 2026

Summary

Add Unit Tests to backend/internal/workflow

Testing

go test -coverprofile=coverage.out ./internal/workflow/...       
ok      github.com/OpenNSW/nsw/internal/workflow        0.578s  coverage: 73.0% of statements
ok      github.com/OpenNSW/nsw/internal/workflow/model  0.184s  coverage: 91.4% of statements
ok      github.com/OpenNSW/nsw/internal/workflow/router 0.761s  coverage: 64.8% of statements
ok      github.com/OpenNSW/nsw/internal/workflow/service        0.387s  coverage: 76.3% of statements

Related Issues

Related to #153

@ginaxu1 ginaxu1 marked this pull request as draft February 19, 2026 07:47
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @ginaxu1, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the test suite for the backend's workflow module. By introducing dedicated unit tests for key components, it aims to improve code reliability, catch regressions early, and ensure the correct functioning of workflow orchestration, consignment management, and state transitions. The addition of new testing libraries facilitates robust and isolated testing of database interactions and complex logic.

Highlights

  • Comprehensive Unit Test Coverage: Added extensive unit tests for the backend/internal/workflow module, covering its manager, models, and various service components, including ConsignmentService, HSCodeService, PreConsignmentService, StateMachine, TemplateService, and WorkflowNodeService.
  • New Testing Dependencies: Introduced github.com/DATA-DOG/go-sqlmock for mocking SQL database interactions and github.com/stretchr/testify for assertion and mocking utilities, enhancing test reliability and ease of writing.
  • Task Manager Tests: Included unit tests for the task/manager package, ensuring the correct behavior of task initialization, execution, retrieval, and cache management.
Changelog
  • backend/go.mod
    • Added github.com/DATA-DOG/go-sqlmock for database mocking.
    • Added github.com/stretchr/testify for enhanced testing assertions and mocks.
  • backend/go.sum
    • Updated Go module checksums to include new testing dependencies.
  • backend/internal/task/manager/manager_test.go
    • Added unit tests for taskManager functionalities, including task initialization, execution, retrieval, and internal caching mechanisms.
  • backend/internal/workflow/manager_test.go
    • Added unit tests for the workflowManager, covering state conversions and various HTTP handler methods for workflow and consignment operations.
  • backend/internal/workflow/model/model_test.go
    • Added unit tests for WorkflowTemplate model methods, specifically GetNodeTemplateIDs.
  • backend/internal/workflow/service/consignment_service_test.go
    • Added unit tests for ConsignmentService methods, including consignment initialization, updates, and workflow node state propagation.
  • backend/internal/workflow/service/hs_code_service_test.go
    • Added unit tests for HSCodeService methods, covering retrieval of HS codes by ID and filtered lists.
  • backend/internal/workflow/service/pre_consignment_service_test.go
    • Added unit tests for PreConsignmentService methods, including pre-consignment initialization, retrieval, and workflow node state propagation with context synchronization.
  • backend/internal/workflow/service/state_machine_test.go
    • Added unit tests for the WorkflowNodeStateMachine, verifying state transitions (Completed, Failed, InProgress) and node initialization logic.
  • backend/internal/workflow/service/template_service_test.go
    • Added unit tests for TemplateService methods, covering retrieval of workflow templates and node templates.
  • backend/internal/workflow/service/workflow_node_service_test.go
    • Added unit tests for WorkflowNodeService methods, covering various CRUD and query operations for workflow nodes within and outside transactions.
Ignored Files
  • Ignored by pattern: .github/workflows/** (1)
    • .github/workflows/backend-ci.yml
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@ginaxu1 ginaxu1 changed the title Add Unit Tests to backend/internal/workflow Add unit tests for Workflow Manager Feb 19, 2026
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request adds a comprehensive suite of unit tests for the backend/internal/workflow and related packages, which is a great step towards improving code quality and reliability. The tests cover various services, models, and managers, using mocks and sqlmock effectively. My review includes a few suggestions to enhance the new tests by improving robustness and maintainability, such as replacing time.Sleep with more reliable synchronization and consolidating duplicated test helper functions.

@ginaxu1 ginaxu1 force-pushed the 153-unit-test-Workflow branch 3 times, most recently from d08047b to 8b72995 Compare February 20, 2026 04:01
@ginaxu1 ginaxu1 marked this pull request as ready for review February 20, 2026 04:03
@mushrafmim
Copy link
Contributor

Still most of the files are under 80%

@ginaxu1 ginaxu1 force-pushed the 153-unit-test-Workflow branch 2 times, most recently from df955a6 to 8dddae2 Compare February 21, 2026 04:45
@ginaxu1 ginaxu1 force-pushed the 153-unit-test-Workflow branch from 8dddae2 to 41f433f Compare February 21, 2026 04:45
@ginaxu1 ginaxu1 added the draft label Feb 23, 2026
@ginaxu1 ginaxu1 marked this pull request as draft February 23, 2026 20:20
@ginaxu1 ginaxu1 marked this pull request as ready for review February 24, 2026 04:11
@ginaxu1 ginaxu1 removed the draft label Feb 24, 2026
@sthanikan2000 sthanikan2000 merged commit ce7d51a into OpenNSW:main Feb 25, 2026
3 checks passed
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.

3 participants