466e55a015
* fix: reconcile annual reports with final closing entries * test: cover annual report depreciation and VAT balances * Merge remote-tracking branch 'origin/main' into fix/usr-fdbck-ch * fix: show exact invoice delivery details * fix: use currency account in invoice emails * fix: address invoice delivery review feedback * fix: harden invoice delivery and payment accounts * test: assert RLS-denied zero-row updates * fix: close remaining invoice compliance gaps * fix: harden invoice archive authorization * fix: close invoice delivery review findings * fix: verify delivery finalization results * fix: cap combined invoice email recipients * fix: close final invoice compliance findings * fix: prevent stale payment account saves * test: prove invoice delivery isolation * fix: close invoice privacy review findings * test: normalize delivery retention dates
48 lines
1.5 KiB
TypeScript
48 lines
1.5 KiB
TypeScript
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
|
|
|
const { createServerClientMock, cookiesMock } = vi.hoisted(() => ({
|
|
createServerClientMock: vi.fn(),
|
|
cookiesMock: vi.fn(),
|
|
}))
|
|
|
|
vi.mock('@supabase/ssr', () => ({
|
|
createServerClient: createServerClientMock,
|
|
}))
|
|
|
|
vi.mock('next/headers', () => ({
|
|
cookies: cookiesMock,
|
|
}))
|
|
|
|
describe('createServiceClient', () => {
|
|
beforeEach(() => {
|
|
vi.resetModules()
|
|
vi.clearAllMocks()
|
|
vi.stubEnv('NEXT_PUBLIC_SUPABASE_URL', 'https://project.supabase.co')
|
|
vi.stubEnv('NEXT_PUBLIC_SUPABASE_ANON_KEY', 'anon-key')
|
|
vi.stubEnv('SUPABASE_SERVICE_ROLE_KEY', 'service-role-key')
|
|
})
|
|
|
|
afterEach(() => {
|
|
vi.unstubAllEnvs()
|
|
})
|
|
|
|
it('uses the service-role key with a cookie-free client', async () => {
|
|
const serviceClient = { kind: 'service' }
|
|
createServerClientMock.mockReturnValue(serviceClient)
|
|
const { createServiceClient } = await import('../server')
|
|
|
|
expect(createServiceClient()).toBe(serviceClient)
|
|
expect(createServerClientMock).toHaveBeenCalledWith(
|
|
'https://project.supabase.co',
|
|
'service-role-key',
|
|
expect.objectContaining({ cookies: expect.any(Object) }),
|
|
)
|
|
const options = createServerClientMock.mock.calls[0][2] as {
|
|
cookies: { getAll: () => unknown[]; setAll: () => void }
|
|
}
|
|
expect(options.cookies.getAll()).toEqual([])
|
|
expect(() => options.cookies.setAll()).not.toThrow()
|
|
expect(cookiesMock).not.toHaveBeenCalled()
|
|
})
|
|
})
|