Skip to content

fix(test): un-skip 10 integration tests — WorkOS class mock, 404→403, DB subscription seed (#3321–3323)#3333

Merged
bokelley merged 2 commits into
mainfrom
claude/issue-3321-fix-skipped-integration-tests
Apr 27, 2026
Merged

fix(test): un-skip 10 integration tests — WorkOS class mock, 404→403, DB subscription seed (#3321–3323)#3333
bokelley merged 2 commits into
mainfrom
claude/issue-3321-fix-skipped-integration-tests

Conversation

@bokelley

Copy link
Copy Markdown
Contributor

Closes #3321
Closes #3322
Closes #3323

Summary

Un-skips 10 integration tests across 4 files by fixing three distinct root causes:

  1. @workos-inc/node class mock + env var priming (join-request-approval.test.ts, personal-workspace-restrictions.test.ts): Route handlers call new WorkOS() directly at request time — mocking the workos-client.js singleton had no effect on handler-constructed instances. Added vi.mock('@workos-inc/node', () => ({ WorkOS: class { ... } })) so every constructor call returns shared mock methods. WorkOS env vars (WORKOS_API_KEY, WORKOS_CLIENT_ID, WORKOS_COOKIE_PASSWORD) are now primed inside vi.hoisted so AUTH_ENABLED resolves to true before organizations.ts loads and calls new WorkOS(). Re-established listOrganizationMemberships.mockImplementation in beforeEach because vi.clearAllMocks() wipes all implementations.

  2. 404→403 assertion (self-service-delete.test.ts): The handler checks WorkOS membership before org existence — correct security behavior that prevents org-ID enumeration by probing deletions. Updated the test description and assertion to expect 403 Access denied for a non-existent org where the user has no membership.

  3. DB subscription seed instead of stripe-client mock (self-service-delete.test.ts, admin-endpoints.test.ts): OrganizationDatabase.getSubscriptionInfo reads subscription_status from the DB row; mocking the stripe-client import had no effect on this code path. Tests now seed subscription_status = 'active' directly in the organizations table and omit stripe_customer_id, so getSubscriptionInfo short-circuits on the local DB value without ever consulting Stripe.

Non-breaking justification

Test-only changes. No production code, protocol schema, or API surface modified. No migrations. Changeset is --empty (no package version bump).

Pre-PR review

  • code-reviewer: approved — no blockers; confirmed mockImplementation (without reset) in join-request-approval is correct since vi.clearAllMocks() already ran; confirmed personal-workspace-restrictions uses mockReset() correctly; confirmed admin-endpoints needs no WorkOS mock; confirmed is_personal flag test is unaffected (direct DB query)
  • internal-tools-strategist: approved — admin delete route uses requireAdmin (no WorkOS call); response body shapes verified (has_active_subscription: true, subscription_status: 'active'); DB-seed-only approach sufficient for the subscription guard

Triage-managed PR — opened by the AdCP triage agent. A human maintainer should review before merging. The agent does not self-merge.

https://claude.ai/code/session_016BZcwrfqhmnHT3mSWZ5cBN


Generated by Claude Code

… DB subscription seed (#3321–3323)

Closes #3321
Closes #3322
Closes #3323

Three root causes fixed:

1. @workos-inc/node class mock + env var priming (join-request-approval, personal-workspace-restrictions):
   Route handlers call `new WorkOS()` directly; mocking workos-client.js singleton had no effect.
   Added `vi.mock('@workos-inc/node', () => ({ WorkOS: class {...} }))` so every constructor call
   returns shared mock methods. Env vars primed in vi.hoisted so AUTH_ENABLED resolves true before
   module load. Re-established listOrganizationMemberships.mockImplementation in beforeEach because
   vi.clearAllMocks() wipes all implementations.

2. 404→403 assertion (self-service-delete): Handler checks WorkOS membership before org existence —
   correct security behaviour that prevents org-ID enumeration. Updated test to assert 403 + 'Access denied'.

3. DB subscription seed instead of stripe-client mock (self-service-delete, admin-endpoints):
   OrganizationDatabase.getSubscriptionInfo reads subscription_status from the DB row; mocking the
   stripe-client import had no effect. Seeding subscription_status='active' directly exercises the
   real code path without requiring a Stripe customer ID.

https://claude.ai/code/session_016BZcwrfqhmnHT3mSWZ5cBN
personal-workspace-restrictions.test.ts:
- Comment said "Re-establish after clearAllMocks" but no clearAllMocks() exists in this file; corrected to "Reset per-test"
- Add DELETE from invitation_seat_types in afterEach: the invitation test (newly un-skipped) inserts a row there and the table has no FK to organizations, so org cleanup did not cascade; stale rows would cause future invitation tests to fail the seat-limit check

https://claude.ai/code/session_016BZcwrfqhmnHT3mSWZ5cBN
@bokelley bokelley marked this pull request as ready for review April 27, 2026 11:09
@bokelley bokelley merged commit 041410c into main Apr 27, 2026
13 checks passed
@bokelley bokelley deleted the claude/issue-3321-fix-skipped-integration-tests branch April 27, 2026 11:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

claude-triaged Issue has been triaged by the Claude Code triage routine. Remove to re-triage.

Projects

None yet

2 participants