Skip to content

[O2B-1623] Migrate the status and tag use cases to services - #2277

Open
graduta wants to merge 2 commits into
mainfrom
refactor/O2B-1623/migrate-status-and-tags-use-cases-to-services
Open

graduta wants to merge 2 commits into
mainfrom
refactor/O2B-1623/migrate-status-and-tags-use-cases-to-services

Conversation

@graduta

@graduta graduta commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

I have a JIRA ticket

  • branch and/or PR name(s) include(s) JIRA ID
  • issue has "Fix version" assigned
  • issue "Status" is set to "In review"
  • PR labels are selected

docs/backend-architecture.md plans to replace the usecases by controllers and services. This PR migrates two more resources that were still read through use cases, the ones found while documenting the HTTP API (O2B-1623): status and tags (the run types ones were migrated in #2267).

Notable changes for users:

  • None: the responses of /api/status/* and /api/tags/* are unchanged, including the 404 bodies of the tags endpoints (the GUI and the tests rely on them).

Notable changes for developers:

  • StatusService (getGuiStatus, getDatabaseStatus) replaces GetGuiStatusUseCase and GetDatabaseStatusUseCase. The service receives the host and the port instead of the express request. The 501 branches of the controller are removed, they could not happen as the use cases never returned null.
  • TagService (getAll, getByIdentifier, create, update, remove, getLogs) replaces the seven tag use cases. It is built on two small functions returning models, getTag and getAllTags, like it is done for detectors, and uses dataSource.transaction like the other services. The user id and the new values are given explicitly instead of a DTO with a session, and create no longer mutates the values it receives.
  • lib/usecases/status, lib/usecases/tag and their tests are removed, replaced by StatusService and TagService tests (the tests creating or updating a tag through a use case use the service). The unreachable-database test now restores its database.ping stub instead of leaving it replaced for the following tests.
  • Checked with the repositories stubbed (no database available when writing it): ordering and filters of getAll, null for a missing tag, the errors messages of create and update. The new and moved tests have not been run, only the CI does.

Changes made to the database:

  • None

@graduta
graduta requested a review from isaachilly as a code owner October 22, 2026 10:11
@graduta graduta added backend test Label to be used when PR is only about tests labels Oct 22, 2026
`GetGuiStatusUseCase` and `GetDatabaseStatusUseCase` are replaced by a `StatusService` (`getGuiStatus`, `getDatabaseStatus`), like the other resources read through
services. The service receives the host and the port instead of the express request, and the controller no longer has the 501 branches, which could never
happen as the use cases never returned null. The responses are unchanged.

The use case tests are replaced by `StatusService` tests. The test of an unreachable database now restores the `database.ping` stub, instead of leaving it
replaced for the following tests.
The seven tag use cases are replaced by a `TagService` (`getAll`, `getByIdentifier`, `create`, `update`, `remove`, `getLogs`) built on two small functions returning
models, `getTag` and `getAllTags`, as it is done for run types and detectors. The services use `dataSource.transaction` like the other services.

The responses of the tags endpoints are unchanged, including the 404 bodies of the endpoints that read or remove a tag, which the GUI and the tests rely on.
The service takes the user id and the new values explicitly instead of a DTO with a session: `create` does not modify the values it receives anymore.

The use case tests are replaced by `TagService` tests, and the tests that created or updated a tag through a use case now use the service.
@graduta
graduta force-pushed the refactor/O2B-1623/migrate-status-and-tags-use-cases-to-services branch from 517e12c to 43754e3 Compare October 22, 2026 10:11
@codecov

codecov Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 46.16%. Comparing base (19720a1) to head (43754e3).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2277      +/-   ##
==========================================
- Coverage   46.36%   46.16%   -0.20%     
==========================================
  Files        1049     1042       -7     
  Lines       17351    17295      -56     
  Branches     3160     3157       -3     
==========================================
- Hits         8044     7984      -60     
- Misses       9307     9311       +4     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend test Label to be used when PR is only about tests

Development

Successfully merging this pull request may close these issues.

1 participant