* fix(bokslut): remove uppskjuten skatt on obeskattade reserver in juridisk person (K3 29.37) and confirm K3 to K2 reversion In juridisk person K3 29.37 keeps obeskattade reserver at gross; the 79.4/20.6 split belongs to koncernredovisning. The old disposition double-counted the tax portion (result charged twice, 2240 overstated on top of gross 21xx). Removes the proposal step, POST kind, UI case, K2-to-K3 account seeding and the interim framework gate; keeps LATENT_TAX_DEFAULT_RATE for analytical soliditet presentation. Also adds the K3-to-K2 consequence confirmation dialog in settings. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * docs(decisions): scope the batch log to shipped code and record the 29.37 election nuance Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * fix(settings): stop promising deferred-tax accounting the engine no longer does The framework help text and the K2-to-K3 confirmation both told the user that switching to K3 means uppskjuten skatt is recognised separately on 2240/8940 with a 79.4/20.6 split. This PR removes exactly that behaviour, so the copy would have promised something the product does not do, which is the defect class this batch exists to remove. Both now describe what actually happens: kassaflodesanalys, komponentavskrivning and a wider note set, with obeskattade reserver carried gross per K3 29.37. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> --------- Co-authored-by: Jakob Wennberg <311770904+jakobwennberg-oss@users.noreply.github.com> Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
89 lines
3.0 KiB
TypeScript
89 lines
3.0 KiB
TypeScript
/**
|
|
* Tests for /api/company/current — GET (cross-tab sync) and PATCH (K2/K3).
|
|
*/
|
|
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
|
import { NextResponse } from 'next/server'
|
|
import { createQueuedMockSupabase, createMockRequest, parseJsonResponse } from '@/tests/helpers'
|
|
|
|
const { supabase, enqueue, reset } = createQueuedMockSupabase()
|
|
|
|
const requireAuthMock = vi.fn()
|
|
vi.mock('@/lib/auth/require-auth', () => ({
|
|
requireAuth: (...args: unknown[]) => requireAuthMock(...args),
|
|
}))
|
|
|
|
const getActiveCompanyIdMock = vi.fn()
|
|
vi.mock('@/lib/company/context', () => ({
|
|
getActiveCompanyId: (...args: unknown[]) => getActiveCompanyIdMock(...args),
|
|
requireCompanyId: vi.fn().mockResolvedValue('company-1'),
|
|
}))
|
|
|
|
const requireWriteMock = vi.fn()
|
|
vi.mock('@/lib/auth/require-write', () => ({
|
|
requireWritePermission: (...args: unknown[]) => requireWriteMock(...args),
|
|
}))
|
|
|
|
import { GET, PATCH } from '../route'
|
|
|
|
const routeParams = { params: Promise.resolve({}) }
|
|
|
|
beforeEach(() => {
|
|
vi.clearAllMocks()
|
|
reset()
|
|
requireAuthMock.mockResolvedValue({ user: { id: 'user-1' }, supabase, error: null })
|
|
requireWriteMock.mockResolvedValue({ ok: true })
|
|
getActiveCompanyIdMock.mockResolvedValue('company-1')
|
|
})
|
|
|
|
describe('GET /api/company/current', () => {
|
|
it('returns 401 with no-store when unauthenticated', async () => {
|
|
requireAuthMock.mockResolvedValue({
|
|
user: null,
|
|
supabase,
|
|
error: NextResponse.json({ error: 'Unauthorized' }, { status: 401 }),
|
|
})
|
|
const res = await GET()
|
|
expect(res.status).toBe(401)
|
|
expect(res.headers.get('Cache-Control')).toBe('private, no-store')
|
|
})
|
|
|
|
it('returns null companyId when the user has no active company', async () => {
|
|
getActiveCompanyIdMock.mockResolvedValue(null)
|
|
const { status, body } = await parseJsonResponse<{ companyId: string | null }>(await GET())
|
|
expect(status).toBe(200)
|
|
expect(body.companyId).toBeNull()
|
|
})
|
|
})
|
|
|
|
describe('PATCH /api/company/current', () => {
|
|
it('rejects K3 for enskild firma with 400', async () => {
|
|
enqueue({ data: { entity_type: 'enskild_firma' } })
|
|
|
|
const req = createMockRequest('/api/company/current', {
|
|
method: 'PATCH',
|
|
body: { accounting_framework: 'k3' },
|
|
})
|
|
const { status, body } = await parseJsonResponse<{ error: string }>(
|
|
await PATCH(req, routeParams)
|
|
)
|
|
expect(status).toBe(400)
|
|
expect(body.error).toContain('aktiebolag')
|
|
})
|
|
|
|
it('updates the framework for an aktiebolag', async () => {
|
|
enqueue({ data: { entity_type: 'aktiebolag' } }) // entity check
|
|
enqueue({ data: { id: 'company-1', accounting_framework: 'k3', entity_type: 'aktiebolag' } }) // update
|
|
|
|
const req = createMockRequest('/api/company/current', {
|
|
method: 'PATCH',
|
|
body: { accounting_framework: 'k3' },
|
|
})
|
|
const { status, body } = await parseJsonResponse<{
|
|
data: { accounting_framework: string }
|
|
}>(await PATCH(req, routeParams))
|
|
|
|
expect(status).toBe(200)
|
|
expect(body.data.accounting_framework).toBe('k3')
|
|
})
|
|
})
|