munch-ease-frontend/tests/router.multitenant.test.ts

38 lines
1.5 KiB
TypeScript
Raw Normal View History

2025-11-01 02:44:58 +00:00
import { describe, it, expect, vi, beforeEach } from 'vitest'
describe('router multitenant routing', () => {
beforeEach(() => {
vi.resetModules()
const env: Record<string, unknown> = process.env as unknown as Record<string, unknown>
delete env.VUE_APP_MULTITENANT_ENABLED
2025-11-01 02:44:58 +00:00
})
it('includes public routes and legacy flat routes when flag disabled', async () => {
const { createAppRouter } = await import('@/router/index')
const router = createAppRouter(() => null)
const paths = router.getRoutes().map((r) => r.path)
expect(paths).toContain('/login')
expect(paths).toContain('/create-account')
expect(paths).toContain('/welcome')
expect(paths).toContain('/invitations/accept')
// legacy flat routes
expect(paths).toContain('/recipes')
expect(paths).toContain('/shopping')
})
it('nests routes under /:householdSlug when flag enabled', async () => {
(process.env as unknown as Record<string, unknown>).VUE_APP_MULTITENANT_ENABLED = 'true'
2025-11-01 02:44:58 +00:00
const { createAppRouter } = await import('@/router/index')
const router = createAppRouter(() => null)
const paths = router.getRoutes().map((r) => r.path)
// Public routes still exist
expect(paths).toContain('/login')
expect(paths).toContain('/create-account')
// Nested route example
const hasNestedRecipes = paths.some((p) => p === '/:householdSlug/recipes')
expect(hasNestedRecipes).toBe(true)
// Legacy route should not be present when nested is enabled
expect(paths).not.toContain('/recipes')
})
})