Skip to content

Changed members API tests to avoid rewire#28654

Merged
9larsons merged 3 commits into
mainfrom
codex/de-rewire-members-api
Jun 17, 2026
Merged

Changed members API tests to avoid rewire#28654
9larsons merged 3 commits into
mainfrom
codex/de-rewire-members-api

Conversation

@9larsons

Copy link
Copy Markdown
Contributor

Summary

  • Added an explicit optional dependency seam to the members API factory
  • Updated the members API unit test to import the module normally instead of using rewire

Tests

  • pnpm test:vitest test/unit/server/services/members/members-api/members-api.test.js
  • pnpm test:single test/unit/server/services/members/members-api/members-api.test.js
  • pnpm exec eslint --ignore-path .eslintignore core/server/services/members/members-api/members-api.js --cache
  • pnpm exec eslint -c test/.eslintrc.js --ignore-path test/.eslintignore test/unit/server/services/members/members-api/members-api.test.js --cache

no ref

Replaced module mutation in the members API unit test with an explicit dependency seam on the members API factory.
@coderabbitai

coderabbitai Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 549ff79e-23c5-48c0-9b0b-b880191b6e71

📥 Commits

Reviewing files that changed from the base of the PR and between 667a801 and 456c767.

📒 Files selected for processing (1)
  • ghost/core/test/unit/server/services/members/members-api/members-api.test.js

Walkthrough

The members-api.test.js file is refactored to remove the rewire-based module injection pattern. MembersAPI and its collaborators (MagicLink, GeolocationService, MemberRepository, MemberBREADService, DomainEvents) are now directly required and passed to MembersAPI via an explicit dependency-injection object in buildMembersAPI. In beforeEach, all stubs are moved to prototype-level methods. Gift redemption test cases are updated so assertions reference MagicLink.prototype.getDataFromToken, MemberBREADService.prototype.read, and MemberRepository.prototype.create (with status: 'gift' and { transacting: 'trx' } options).

Possibly related PRs

  • TryGhost/Ghost#28651: Applies the same pattern of removing rewire and switching to direct service instantiation with stub collaborators in a different unit test file.
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and concisely describes the main change: refactoring members API tests to remove rewire usage.
Description check ✅ Passed The description clearly relates to the changeset, explaining the rewire removal and new dependency injection approach used in the refactored tests.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/de-rewire-members-api

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@nx-cloud

nx-cloud Bot commented Jun 16, 2026

Copy link
Copy Markdown

🤖 Nx Cloud AI Fix

Ensure the fix-ci command is configured to always run in your CI pipeline to get automatic fixes in future runs. For more information, please see https://nx.dev/ci/features/self-healing-ci


View your CI Pipeline Execution ↗ for commit 456c767

Command Status Duration Result
nx run-many -t test:unit -p ghost ✅ Succeeded 32s View ↗
nx run-many -t lint -p ghost ✅ Succeeded 42s View ↗

💡 Verify your cache is correct by running tasks in a sandbox. Read docs ↗


☁️ Nx Cloud last updated this comment at 2026-06-17 14:37:20 UTC

@9larsons 9larsons marked this pull request as ready for review June 17, 2026 14:19
9larsons added 2 commits June 17, 2026 09:28
no ref

The rewire replacement should not expose every internal constructor as a second production argument. Moving the magic-link member resolution into a focused helper keeps the MembersAPI constructor unchanged while giving the gift redemption behavior a real test boundary.
no ref

The de-rewire pass does not need a new magic-link helper or constructor seam here. Stubbing the existing class prototypes keeps the test on real module boundaries while leaving the MembersAPI implementation unchanged.
@9larsons 9larsons merged commit fca6c63 into main Jun 17, 2026
30 checks passed
@9larsons 9larsons deleted the codex/de-rewire-members-api branch June 17, 2026 14:46
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.

1 participant