Skip to content

refactor(tests): migrate trigger tests to shared mocks and factories#1002

Merged
aaight merged 1 commit intodevfrom
feature/migrate-trigger-tests-to-shared-mocks
Mar 23, 2026
Merged

refactor(tests): migrate trigger tests to shared mocks and factories#1002
aaight merged 1 commit intodevfrom
feature/migrate-trigger-tests-to-shared-mocks

Conversation

@aaight
Copy link
Copy Markdown
Collaborator

@aaight aaight commented Mar 23, 2026

Summary

  • Migrated all 15 trigger test files to use shared mock objects from sharedMocks.ts instead of inline mock declarations
  • Replaced inline PM registration mock blocks (config/provider, trello/client, jira/client, acknowledgments, reactions) with shared mock objects (mockConfigProvider, mockTrelloClientModule, mockJiraClientModule, mockAcknowledgmentsModule, mockReactionsModule)
  • Replaced inline config-resolver and trigger-check mocks with mockConfigResolverModule and mockTriggerCheckModule
  • Replaced inline logger mocks with mockLogger
  • Replaced inline GitHub client mocks with mockGitHubClientModule
  • Replaced local makeCheckSuitePayload / makeFailurePayload helpers with createCheckSuitePayload() factory
  • Replaced local makeReviewPayload helper with createReviewPayload() factory
  • Replaced inline Trello payload constructions with createTrelloActionPayload() factory
  • No test logic or assertions were changed — pure refactor

Card: https://trello.com/c/R6FlbHLC/520-as-a-developer-i-want-trigger-tests-migrated-to-shared-mocks-and-factories-so-that-they-are-shorter-and-consistent

Test plan

  • npx vitest run --project unit-triggers — all 681 trigger tests pass
  • All other unit test suites pass (5686 tests across unit-core, unit-backends, unit-api)
  • npx biome check — no lint errors
  • npx tsc --noEmit — no type errors

Key decisions

  • Sharedmocks import must be placed as the second import (immediately after vitest) due to Vitest's hoisting behavior — vi.mock() factories reference the shared mock values and need them to be initialized before other imports
  • Local helpers like makeSynchronizePayload, makeReviewRequestedPayload, and makeCheckSuitePayload (where they're highly customized per test) were kept as local helpers wrapping the factory functions
  • TrelloStatusChangedBacklogTrigger tests were rewritten from scratch with factory-based payloads (the original used inline payload constructions throughout)

🤖 Generated with Claude Code

🕵️ claude-code · claude-sonnet-4-6 · run details

Copy link
Copy Markdown
Collaborator

@nhopeatall nhopeatall left a comment

Choose a reason for hiding this comment

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

LGTM — Clean mechanical refactoring that consistently replaces 15 inline mock declarations and payload constructions with shared mocks (sharedMocks.ts) and factory functions (factories.ts). No test logic or assertions were changed.

The changes are well-structured:

  • Import ordering follows the documented convention (vitest → sharedMocks → vi.mock → SUT imports)
  • Files using vi.hoisted() (trello-comment-mention, github-pr-comment-mention) correctly keep their custom hoisted mocks while adopting shared mocks for common modules
  • The removal of the unused TrelloStatusChangedPlanningTrigger import from status-changed.test.ts is a legitimate cleanup
  • All 7 CI checks pass including 681 trigger tests

🕵️ claude-code · claude-opus-4-6 · run details

@aaight aaight merged commit a7401eb into dev Mar 23, 2026
9 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.

2 participants