feat(customers): carry contact person and invoice copy recipients through migration (#1392)
* feat(customers): carry contact person and invoice copy recipients through migration Extends the arcim-migration entity mapper, Fortnox provider mapper, canonical DTOs, customer APIs (web + v1) and invoice send flows so contact person and customer-level invoice CC/BCC addresses survive provider migrations. NULL means unconfigured and empty means an explicit clear, so re-syncs enrich legacy gaps without resurrecting deliberately removed values. Fortnox fixed assets are split into a dedicated follow-up issue. Fixes #1345 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * chore(db): bump customer metadata migration past pack-slug version Main already contains 20260803230000; keep new versions strictly newest so Supabase branching applies them in order. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * fix(customers): complete Customer type consumers and make enrichment payload resolvable The preview-pdf mock customer and the makeCustomer fixture now carry the three new metadata fields, fixing the type-check failure in Build (zero extensions) and Vercel. The enrichment update in the migration orchestrator now spells its payload as an object literal typed CustomerMetadataEnrichment (absent keys drop at serialization), so the phantom-column guard resolves the columns instead of counting another unresolvable dynamic payload past its ceiling. The cc/bcc guards also verify element types instead of casting. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> --------- Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5
parent
cb3ef45f14
commit
00ae3540db
@@ -100,8 +100,15 @@ export const PATCH = withRouteContext(
|
||||
if (body.customer_type !== undefined) updateData.customer_type = body.customer_type
|
||||
// Empty string clears the customer number, same as an explicit null.
|
||||
if (body.customer_number !== undefined) updateData.customer_number = body.customer_number || null
|
||||
if (body.contact_person !== undefined) updateData.contact_person = body.contact_person
|
||||
if (body.email !== undefined) updateData.email = body.email
|
||||
if (body.phone !== undefined) updateData.phone = body.phone
|
||||
if (body.invoice_email_cc_addresses !== undefined) {
|
||||
updateData.invoice_email_cc_addresses = body.invoice_email_cc_addresses
|
||||
}
|
||||
if (body.invoice_email_bcc_addresses !== undefined) {
|
||||
updateData.invoice_email_bcc_addresses = body.invoice_email_bcc_addresses
|
||||
}
|
||||
if (body.address_line1 !== undefined) updateData.address_line1 = body.address_line1
|
||||
if (body.address_line2 !== undefined) updateData.address_line2 = body.address_line2
|
||||
if (body.postal_code !== undefined) updateData.postal_code = body.postal_code
|
||||
|
||||
@@ -57,7 +57,12 @@ vi.mock('@/lib/init', () => ({ ensureInitialized: vi.fn() }))
|
||||
import { POST } from '../route'
|
||||
import { PATCH } from '../[id]/route'
|
||||
|
||||
type CustomerRow = { customer_number?: string | null }
|
||||
type CustomerRow = {
|
||||
customer_number?: string | null
|
||||
contact_person?: string | null
|
||||
invoice_email_cc_addresses?: string[] | null
|
||||
invoice_email_bcc_addresses?: string[] | null
|
||||
}
|
||||
|
||||
describe('customer_number on POST /api/customers', () => {
|
||||
beforeEach(() => {
|
||||
@@ -145,6 +150,49 @@ describe('customer_number on POST /api/customers', () => {
|
||||
expect(status).toBe(200)
|
||||
expect((captured.insert[0] as CustomerRow).customer_number).toBeNull()
|
||||
})
|
||||
|
||||
it('stores customer invoice contact metadata on create', async () => {
|
||||
queryResult = {
|
||||
data: { id: 'cust-1', name: 'Test AB', customer_type: 'swedish_business' },
|
||||
error: null,
|
||||
}
|
||||
const request = createMockRequest('/api/customers', {
|
||||
method: 'POST',
|
||||
body: {
|
||||
name: 'Test AB',
|
||||
customer_type: 'swedish_business',
|
||||
contact_person: 'Anna Andersson',
|
||||
invoice_email_cc_addresses: ['finance@example.test'],
|
||||
invoice_email_bcc_addresses: ['archive@example.test'],
|
||||
},
|
||||
})
|
||||
|
||||
const response = await POST(request, { params: Promise.resolve({}) })
|
||||
expect((await parseJsonResponse(response)).status).toBe(200)
|
||||
expect(captured.insert[0]).toMatchObject({
|
||||
contact_person: 'Anna Andersson',
|
||||
invoice_email_cc_addresses: ['finance@example.test'],
|
||||
invoice_email_bcc_addresses: ['archive@example.test'],
|
||||
})
|
||||
})
|
||||
|
||||
it('rejects more than 19 customer invoice copy recipients', async () => {
|
||||
const request = createMockRequest('/api/customers', {
|
||||
method: 'POST',
|
||||
body: {
|
||||
name: 'Test AB',
|
||||
customer_type: 'swedish_business',
|
||||
invoice_email_cc_addresses: Array.from(
|
||||
{ length: 20 },
|
||||
(_, index) => `copy-${index}@example.test`,
|
||||
),
|
||||
},
|
||||
})
|
||||
|
||||
const response = await POST(request, { params: Promise.resolve({}) })
|
||||
expect((await parseJsonResponse(response)).status).toBe(400)
|
||||
expect(captured.insert).toHaveLength(0)
|
||||
})
|
||||
})
|
||||
|
||||
describe('customer_number on PATCH /api/customers/[id]', () => {
|
||||
@@ -227,4 +275,23 @@ describe('customer_number on PATCH /api/customers/[id]', () => {
|
||||
expect(status).toBe(200)
|
||||
expect(captured.update[0]).not.toHaveProperty('customer_number')
|
||||
})
|
||||
|
||||
it('updates customer invoice contact metadata', async () => {
|
||||
const request = createMockRequest('/api/customers/cust-1', {
|
||||
method: 'PATCH',
|
||||
body: {
|
||||
contact_person: '',
|
||||
invoice_email_cc_addresses: [],
|
||||
invoice_email_bcc_addresses: ['archive@example.test'],
|
||||
},
|
||||
})
|
||||
|
||||
const response = await PATCH(request, routeParams)
|
||||
expect((await parseJsonResponse(response)).status).toBe(200)
|
||||
expect(captured.update[0]).toMatchObject({
|
||||
contact_person: '',
|
||||
invoice_email_cc_addresses: [],
|
||||
invoice_email_bcc_addresses: ['archive@example.test'],
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -65,8 +65,11 @@ export const POST = withRouteContext(
|
||||
name: body.name,
|
||||
customer_type: body.customer_type,
|
||||
customer_number: body.customer_number || null,
|
||||
contact_person: body.contact_person ?? null,
|
||||
email: body.email,
|
||||
phone: body.phone,
|
||||
invoice_email_cc_addresses: body.invoice_email_cc_addresses ?? null,
|
||||
invoice_email_bcc_addresses: body.invoice_email_bcc_addresses ?? null,
|
||||
address_line1: body.address_line1,
|
||||
address_line2: body.address_line2,
|
||||
postal_code: body.postal_code,
|
||||
|
||||
Reference in New Issue
Block a user