Skip to content

Add unit tests for dataset, revision and task services (#686)#692

Merged
wheelsandcogs merged 1 commit into
mainfrom
issue-686-service-tests
Jun 2, 2026
Merged

Add unit tests for dataset, revision and task services (#686)#692
wheelsandcogs merged 1 commit into
mainfrom
issue-686-service-tests

Conversation

@wheelsandcogs

@wheelsandcogs wheelsandcogs commented Jun 2, 2026

Copy link
Copy Markdown
Collaborator

Summary

Adds unit tests for three under-covered services flagged in #686, bringing each above the 70% statement-coverage target used across the testing initiative.

File Before After
src/services/dataset.ts 50.2% 99.6%
src/services/revision.ts 30.9% 93.5%
src/services/task.ts 14.0% 100%

84 new tests covering both happy and unhappy paths across each service's public methods — task lifecycle and status transitions, revision draft/approval flows, and dataset fact-table replacement.

Source changes

src/services/dataset.ts:

  • Switched the draft-revision delete path from getFileService() to the injected this.fileService, so the path can be exercised in a unit test.
  • Kept the revisionIndex === 1 guard around the dimension/measure reset as a deliberate defensive backstop. The outer guard in updateFactTable already throws for any revision other than the first, so the inner check is currently redundant — but it stays as cheap protection against that outer guard being relaxed later, so we never reset a non-first revision's dimensions/measure.

jest.config.ts:

  • Raised the global coverage thresholds to match the new floor: statements 79, branches 67, functions 75, lines 79. Full-suite coverage now sits at 80.97% / 68.2% / 76.7% / 80.8%.

Scope

This PR covers the three services from #686. The four controllers (admin, build-log, measure, translation) are handled separately in #693.

Verification

  • jest --coverage — 1551 tests pass, global thresholds met.
  • tsc build and lint clean.

Part of #686.

Copilot AI review requested due to automatic review settings June 2, 2026 09:46

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 improves the unit-test coverage of three core service modules (dataset, revision, task) identified in #686, and makes two small DatasetService adjustments to remove unreachable logic and improve testability. It also raises the global Jest coverage thresholds to reflect the improved baseline.

Changes:

  • Added comprehensive unit tests covering happy/unhappy paths for DatasetService, revision service helpers, and TaskService.
  • Simplified DatasetService.updateFactTable() by removing an unreachable revisionIndex === 1 branch and always resetting dimensions/measure after the existing guard.
  • Updated DatasetService.deleteDraftRevision() to use the injected fileService (instead of creating a new one internally), and raised Jest global coverage thresholds.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
test/unit/services/task.test.ts Adds unit tests for TaskService covering task creation, status transitions, and archive/unarchive/unpublish flows.
test/unit/services/revision.test.ts Adds unit tests for revision service functions including validation-cube flows, rebuild flows, and revision-task updates.
test/unit/services/dataset.test.ts Adds unit tests for DatasetService including metadata updates, publication flows, draft deletion cleanup, and history/tasklist behavior.
src/services/dataset.ts Removes unreachable branch in fact-table replacement and uses injected fileService for draft-revision cleanup.
jest.config.ts Raises global coverage thresholds in line with improved suite coverage.

Brings the three under-covered services up to the testing-initiative
target:

- dataset.ts:  50% -> 99.6% statements
- revision.ts: 31% -> 93.5% statements
- task.ts:     14% -> 100% statements

Covers happy and unhappy paths across each service's public methods,
including task lifecycle and status transitions, revision draft/approval
flows and dataset fact-table replacement.

dataset.ts: use the injected this.fileService instead of getFileService()
so the draft-revision delete path is unit-testable. The redundant
revisionIndex === 1 guard around the dimension/measure reset is kept as a
defensive backstop -- the outer guard already guarantees the first
revision, but the explicit check protects against that guard being
relaxed later.

Raise the global coverage thresholds in jest.config.ts to match the new
floor (statements 79, branches 67, functions 75, lines 79).
@wheelsandcogs wheelsandcogs force-pushed the issue-686-service-tests branch from 1d5b0b6 to 4dfbb55 Compare June 2, 2026 10:25

@j-maynard j-maynard left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM 🤘🏻

@wheelsandcogs wheelsandcogs merged commit 2a2d8c4 into main Jun 2, 2026
6 checks passed
@wheelsandcogs wheelsandcogs deleted the issue-686-service-tests branch June 2, 2026 10:51
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