Bug/gh issues fiz (#1103)

* refactor: optimize page loading and data fetching

* fix: resolve recurring production runtime errors

* feat: add MCP company and customer updates

* fix: handle year-end tax adjustments

* feat: harden annual report compliance

* fix: expand invoice logo and font support

* fix: sanitize API route error responses

* fix: sanitize user-facing error messages

* feat: persist onboarding and tax assessment notices

* fix: reduce cloud backup audit churn

* feat: refine invoice editor layout

* fix: show saved tax adjustments in INK2

* fix: complete annual report API mappings

* docs: record operational safeguards and decisions

* fix: harden annual report review findings

* fix: adjust column span for description based on VAT registration

* New css class name
This commit is contained in:
Mattsson
2026-07-21 23:00:15 +02:00
committed by GitHub
parent 702512437a
commit e11f70b347
467 changed files with 17569 additions and 2221 deletions
+39 -2
View File
@@ -34,9 +34,13 @@ vi.mock('@/lib/supabase/server', () => ({
import { POST } from '../route'
function makeFormRequest(): Request {
function makeFormRequest(
size = 3,
type = 'image/png',
name = 'logo.png',
): Request {
const fd = new FormData()
fd.append('file', new File([new Uint8Array([1, 2, 3])], 'logo.png', { type: 'image/png' }))
fd.append('file', new File([new Uint8Array(size)], name, { type }))
return new Request('http://localhost/api/settings/logo', { method: 'POST', body: fd })
}
@@ -73,6 +77,39 @@ describe('POST /api/settings/logo', () => {
expect(status).toBe(403)
})
it('returns 400 for an unsupported file type', async () => {
const response = await POST(
makeFormRequest(3, 'application/pdf', 'logo.pdf'),
{ params: Promise.resolve({}) },
)
const { status } = await parseJsonResponse(response)
expect(status).toBe(400)
})
it('returns 400 when the logo exceeds 10 MB', async () => {
const response = await POST(
makeFormRequest(10 * 1024 * 1024 + 1),
{ params: Promise.resolve({}) },
)
const { status, body } = await parseJsonResponse<{ error: string }>(response)
expect(status).toBe(400)
expect(body.error).toContain('10 MB')
})
it('accepts a logo larger than the previous 2 MB limit', async () => {
enqueue({ error: null }) // company_settings update
const response = await POST(
makeFormRequest(2 * 1024 * 1024 + 1),
{ params: Promise.resolve({}) },
)
const { status } = await parseJsonResponse(response)
expect(status).toBe(200)
})
it('uploads the logo and returns its public url on the happy path', async () => {
enqueue({ error: null }) // company_settings update
+5 -4
View File
@@ -1,8 +1,9 @@
import { NextResponse } from 'next/server'
import { createServiceClient } from '@/lib/supabase/server'
import { withRouteContext } from '@/lib/api/with-route-context'
import { getErrorMessage as getUserErrorMessage } from '@/lib/errors/get-error-message'
import { LOGO_UPLOAD_MAX_BYTES, LOGO_UPLOAD_MAX_MB } from '@/lib/invoices/branding-constants'
const MAX_SIZE = 2 * 1024 * 1024 // 2MB
const ALLOWED_TYPES = ['image/png', 'image/jpeg', 'image/svg+xml', 'image/webp']
export const POST = withRouteContext(
@@ -19,8 +20,8 @@ export const POST = withRouteContext(
return NextResponse.json({ error: 'Otillåten filtyp. Tillåtna: PNG, JPG, SVG, WebP.' }, { status: 400 })
}
if (file.size > MAX_SIZE) {
return NextResponse.json({ error: 'Filen är för stor (max 2 MB).' }, { status: 400 })
if (file.size > LOGO_UPLOAD_MAX_BYTES) {
return NextResponse.json({ error: `Filen är för stor (max ${LOGO_UPLOAD_MAX_MB} MB).` }, { status: 400 })
}
const buffer = Buffer.from(await file.arrayBuffer())
@@ -53,7 +54,7 @@ export const POST = withRouteContext(
})
if (uploadError) {
return NextResponse.json({ error: `Uppladdning misslyckades: ${uploadError.message}` }, { status: 500 })
return NextResponse.json({ error: `Uppladdning misslyckades: ${getUserErrorMessage(uploadError)}` }, { status: 500 })
}
const { data: urlData } = serviceClient.storage