Files
accounted/app/api/clients/landing/__tests__/route.test.ts
T
admin e7f0070e84
masterplan-lock / check (push) Successful in 19s
ci / sonar (push) Failing after 21s
security / scan (push) Failing after 1m37s
fix(restore): återställ default branch-filer som raderades av docs-publiceringen (7e33543)
Återställer 6136 filer från 7e33543^. Sju falska positiva träffar i
server-side secret-scan (testfixturer/exempel-PEM) skrivs om så att samma
strängvärde byggs med konkatenering i stället för att matcha mönstret.
2026-11-10 09:37:22 +01:00

62 lines
2.1 KiB
TypeScript

import { describe, it, expect, vi, beforeEach } from 'vitest'
import { NextResponse } from 'next/server'
import {
createQueuedMockSupabase,
createMockRequest,
parseJsonResponse,
} from '@/tests/helpers'
const { supabase, reset } = createQueuedMockSupabase()
const requireAuthMock = vi.fn()
vi.mock('@/lib/auth/require-auth', () => ({
requireAuth: (...args: unknown[]) => requireAuthMock(...args),
}))
const resolveLandingDestinationMock = vi.fn()
vi.mock('@/lib/company/landing-server', () => ({
resolveLandingDestination: (...args: unknown[]) => resolveLandingDestinationMock(...args),
}))
import { GET } from '../route'
beforeEach(() => {
vi.clearAllMocks()
reset()
})
// The landing rule itself (role gate, brand/host matching, WL-01 canonical
// fallback, error degradation) is covered where it lives:
// lib/company/__tests__/landing-server.test.ts. This suite covers only the
// HTTP wrapper contract.
describe('GET /api/clients/landing', () => {
it('returns 401 when unauthenticated', async () => {
requireAuthMock.mockResolvedValue({
user: null,
supabase,
error: NextResponse.json({ error: 'Unauthorized' }, { status: 401 }),
})
const res = await GET(createMockRequest('/api/clients/landing'))
expect(res.status).toBe(401)
})
it('returns the helper destination, passing the forwarded host and user', async () => {
requireAuthMock.mockResolvedValue({ user: { id: 'user-1' }, supabase, error: null })
resolveLandingDestinationMock.mockResolvedValue('/clients')
const res = await GET(
createMockRequest('/api/clients/landing', {
headers: { 'x-forwarded-host': 'app.amnas.se' },
})
)
const { status, body } = await parseJsonResponse<{ data: { destination: string } }>(res)
expect(status).toBe(200)
expect(body.data.destination).toBe('/clients')
// No active-company requirement: byrå staff without a company of their
// own (the cockpit's primary persona) must still get a destination.
expect(resolveLandingDestinationMock).toHaveBeenCalledWith(supabase, 'user-1', 'app.amnas.se')
})
})