-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
saas-migrationTrue multi-tenant SaaS migrationTrue multi-tenant SaaS migration
Milestone
Description
Overview
Update the entire test suite to work with the new subdomain-based routing, NEXT_PUBLIC_BASE_DOMAIN env var, and restructured portal routes. This is a follow-up to issues #88–#95 and must be done last.
Context
Multiple test files reference NEXT_PUBLIC_APP_URL, hardcoded /portal/{slug} paths, and assume path-based tenant resolution. All of these need updating.
Unit / Integration Tests (Vitest)
app/actions/portal.test.ts
- Change
process.env.NEXT_PUBLIC_APP_URL = "https://app.example.com"→process.env.NEXT_PUBLIC_BASE_DOMAIN = "example.com" - Update expected magic link URL:
- Old:
https://app.example.com/portal/test-slug/auth-callback - New:
https://test-slug.example.com/auth/callback
- Old:
- Update
finalizePortalSessionActiontests: removetenantSlugargument; mockheaders()to returnx-tenant-slug
app/auth/callback/route.test.ts
- Add
Hostheader to mock requests:request.headers.set("host", "test-slug.example.com") - Remove tests that rely on
?next=/portal/{slug}query param for tenant detection - Add test: callback on root domain (
taskflow.com) creates new tenant and redirects to{slug}.taskflow.com/dashboard - Add test: callback on tenant subdomain (
acme.taskflow.com) for portal client → redirects toacme.taskflow.com/portal - Update
NEXT_PUBLIC_BASE_DOMAINenv var mock (removeALLOW_REGISTRATION)
lib/url.test.ts (new)
Unit tests for the new lib/url.ts utility:
tenantUrl("acme", "/dashboard")→https://acme.taskflow.com/dashboardtenantUrl("acme")→https://acme.taskflow.comportalUrl("acme")→https://acme.taskflow.com/portal- In local dev (base domain =
localhost:3000):tenantUrl(...)→http://localhost:3000/...
proxy.test.ts (new or existing)
Unit tests for getTenantSlugFromHost():
"acme.taskflow.com"→"acme""taskflow.com"→null"www.taskflow.com"→null"localhost:3000"→null"acme.lvh.me"(dev testing) →"acme"whenBASE_DOMAIN=lvh.me
E2E Tests (Playwright)
playwright.config.ts
baseURLcurrently set tohttp://localhost:3000- For subdomain testing in CI/E2E: configure
/etc/hostsor uselvh.metricklvh.meand*.lvh.mealways resolve to127.0.0.1— no hosts file needed- Set
NEXT_PUBLIC_BASE_DOMAIN=lvh.mein E2E test environment baseURL→http://lvh.me:3000for the landing page; tenant URLs:http://{slug}.lvh.me:3000
tests/e2e/portal.spec.ts
- Update all portal navigation to use subdomain URLs instead of path-based
- Portal URL:
http://${tenantSlug}.lvh.me:3000/portal - Portal login:
http://${tenantSlug}.lvh.me:3000/portal/login - Remove
tenantSlugfrom path segments in assertions
tests/e2e/auth.spec.ts (or equivalent)
- Add registration flow test: visit
http://lvh.me:3000/auth/register, complete form, assert redirect tohttp://{slug}.lvh.me:3000/dashboard - Test session cookie is valid on tenant subdomain after registration
tests/e2e/fixtures/global-setup.ts
- Update
storageStatefixtures to use subdomain origins - Seed data setup: ensure test tenant slug is predictable (e.g.
test-tenant)
Key Files
app/actions/portal.test.tsapp/auth/callback/route.test.ts- New:
lib/url.test.ts - New:
proxy.test.ts playwright.config.tstests/e2e/portal.spec.tstests/e2e/fixtures/global-setup.ts
Testing Definition of Done
npm run test:unitpasses with 0 failuresnpm run test:e2epasses with subdomain-aware configurationnpm run buildpasses
Depends On
All of issues #88–#95 must be merged before this test update is complete (though tests can be written in parallel).
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
saas-migrationTrue multi-tenant SaaS migrationTrue multi-tenant SaaS migration