Å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.
133 lines
4.6 KiB
TypeScript
133 lines
4.6 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
import {
|
|
exceedsInvoiceEmailRecipientLimit,
|
|
findAdditionalInvoiceRecipientCollisions,
|
|
invoiceEmailRecipientCount,
|
|
parseInvoiceRecipientText,
|
|
resolveInvoiceEmailRecipients,
|
|
} from '@/lib/invoices/email-recipients'
|
|
|
|
describe('resolveInvoiceEmailRecipients', () => {
|
|
it('uses the legacy copy only while the company list is unconfigured', () => {
|
|
expect(resolveInvoiceEmailRecipients({
|
|
to: '[email protected]',
|
|
configuredCc: null,
|
|
legacyCc: '[email protected]',
|
|
}).cc).toEqual(['[email protected]'])
|
|
|
|
expect(resolveInvoiceEmailRecipients({
|
|
to: '[email protected]',
|
|
configuredCc: [],
|
|
legacyCc: '[email protected]',
|
|
}).cc).toEqual([])
|
|
})
|
|
|
|
it('merges fixed and per-send recipients with deterministic precedence', () => {
|
|
expect(resolveInvoiceEmailRecipients({
|
|
to: '[email protected]',
|
|
configuredCc: ['[email protected]', '[email protected]'],
|
|
configuredBcc: ['[email protected]', '[email protected]'],
|
|
additionalCc: ['[email protected]', '[email protected]'],
|
|
additionalBcc: ['[email protected]', '[email protected]'],
|
|
})).toEqual({
|
|
to: ['[email protected]'],
|
|
cc: ['[email protected]', '[email protected]'],
|
|
bcc: ['[email protected]', '[email protected]'],
|
|
})
|
|
})
|
|
|
|
it('merges customer-specific recipients between company settings and per-send additions', () => {
|
|
expect(resolveInvoiceEmailRecipients({
|
|
to: '[email protected]',
|
|
configuredCc: ['[email protected]'],
|
|
configuredBcc: ['[email protected]'],
|
|
customerCc: ['[email protected]', '[email protected]'],
|
|
customerBcc: ['[email protected]', '[email protected]'],
|
|
additionalCc: ['[email protected]'],
|
|
additionalBcc: ['[email protected]'],
|
|
})).toEqual({
|
|
to: ['[email protected]'],
|
|
cc: [
|
|
'[email protected]',
|
|
'[email protected]',
|
|
'[email protected]',
|
|
],
|
|
bcc: [
|
|
'[email protected]',
|
|
'[email protected]',
|
|
'[email protected]',
|
|
],
|
|
})
|
|
})
|
|
|
|
it('counts the final de-duplicated To, CC, and BCC recipients', () => {
|
|
const atLimit = resolveInvoiceEmailRecipients({
|
|
to: '[email protected]',
|
|
configuredCc: Array.from({ length: 19 }, (_, index) => `copy-${index}@example.test`),
|
|
})
|
|
expect(invoiceEmailRecipientCount(atLimit)).toBe(20)
|
|
expect(exceedsInvoiceEmailRecipientLimit(atLimit)).toBe(false)
|
|
|
|
const overLimit = resolveInvoiceEmailRecipients({
|
|
to: '[email protected]',
|
|
configuredCc: atLimit.cc,
|
|
additionalBcc: ['[email protected]'],
|
|
})
|
|
expect(invoiceEmailRecipientCount(overLimit)).toBe(21)
|
|
expect(exceedsInvoiceEmailRecipientLimit(overLimit)).toBe(true)
|
|
})
|
|
|
|
it('trims and de-duplicates address text', () => {
|
|
expect(parseInvoiceRecipientText(
|
|
' [email protected],\[email protected]; [email protected] ',
|
|
)).toEqual(['[email protected]', '[email protected]'])
|
|
})
|
|
|
|
it('reports per-send collisions instead of silently changing recipient precedence', () => {
|
|
expect(findAdditionalInvoiceRecipientCollisions({
|
|
to: '[email protected]',
|
|
configuredCc: ['[email protected]'],
|
|
configuredBcc: ['[email protected]'],
|
|
additionalCc: ['[email protected]', '[email protected]'],
|
|
additionalBcc: ['[email protected]', '[email protected]'],
|
|
})).toEqual([
|
|
{
|
|
address: '[email protected]',
|
|
field: 'additional_cc',
|
|
conflicts_with: 'to',
|
|
},
|
|
{
|
|
address: '[email protected]',
|
|
field: 'additional_bcc',
|
|
conflicts_with: 'configured_cc',
|
|
},
|
|
{
|
|
address: '[email protected]',
|
|
field: 'additional_bcc',
|
|
conflicts_with: 'additional_cc',
|
|
},
|
|
])
|
|
})
|
|
|
|
it('reports collisions with customer-specific recipients', () => {
|
|
expect(findAdditionalInvoiceRecipientCollisions({
|
|
to: '[email protected]',
|
|
customerCc: ['[email protected]'],
|
|
customerBcc: ['[email protected]'],
|
|
additionalCc: ['[email protected]'],
|
|
additionalBcc: ['[email protected]'],
|
|
})).toEqual([
|
|
{
|
|
address: '[email protected]',
|
|
field: 'additional_cc',
|
|
conflicts_with: 'customer_bcc',
|
|
},
|
|
{
|
|
address: '[email protected]',
|
|
field: 'additional_bcc',
|
|
conflicts_with: 'customer_cc',
|
|
},
|
|
])
|
|
})
|
|
})
|