fix: Typ-Generic in checkSuppression, SMTP_PASS Fallback, Logging-Test prüft console.error, tenantId-Fehler-Test
This commit is contained in:
@@ -62,7 +62,8 @@ describe('sendEmail', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('loggt keine E-Mail-Adresse im Klartext', async () => {
|
it('loggt keine E-Mail-Adresse im Klartext', async () => {
|
||||||
const consoleSpy = vi.spyOn(console, 'log')
|
const logSpy = vi.spyOn(console, 'log')
|
||||||
|
const errorSpy = vi.spyOn(console, 'error')
|
||||||
await sendEmail({
|
await sendEmail({
|
||||||
to: 'geheim@example.com',
|
to: 'geheim@example.com',
|
||||||
subject: 'Test',
|
subject: 'Test',
|
||||||
@@ -70,7 +71,7 @@ describe('sendEmail', () => {
|
|||||||
text: 'Hi',
|
text: 'Hi',
|
||||||
listUnsubscribeHeader: '<https://example.com/unsub>',
|
listUnsubscribeHeader: '<https://example.com/unsub>',
|
||||||
})
|
})
|
||||||
const loggedOutput = consoleSpy.mock.calls.flat().join(' ')
|
const output = [...logSpy.mock.calls, ...errorSpy.mock.calls].flat().join(' ')
|
||||||
expect(loggedOutput).not.toContain('geheim@example.com')
|
expect(output).not.toContain('geheim@example.com')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ const transport = nodemailer.createTransport({
|
|||||||
port: Number(process.env.SMTP_PORT ?? 1025),
|
port: Number(process.env.SMTP_PORT ?? 1025),
|
||||||
secure: false,
|
secure: false,
|
||||||
auth: process.env.SMTP_USER
|
auth: process.env.SMTP_USER
|
||||||
? { user: process.env.SMTP_USER, pass: process.env.SMTP_PASS }
|
? { user: process.env.SMTP_USER, pass: process.env.SMTP_PASS ?? '' }
|
||||||
: undefined,
|
: undefined,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -42,4 +42,10 @@ describe('checkSuppression', () => {
|
|||||||
expect(call[0]).toContain('$1')
|
expect(call[0]).toContain('$1')
|
||||||
expect(call[1]).toEqual(['x@x.com'])
|
expect(call[1]).toEqual(['x@x.com'])
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('propagiert Fehler bei ungültiger tenantId nach oben', async () => {
|
||||||
|
const { withTenant } = await import('../db/tenant')
|
||||||
|
vi.mocked(withTenant).mockRejectedValueOnce(new Error('Ungültige tenantId'))
|
||||||
|
await expect(checkSuppression('invalid!', 'x@x.com')).rejects.toThrow('Ungültige tenantId')
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -3,7 +3,10 @@ import { withTenant } from '../db/tenant'
|
|||||||
export async function checkSuppression(tenantId: string, email: string): Promise<boolean> {
|
export async function checkSuppression(tenantId: string, email: string): Promise<boolean> {
|
||||||
const normalized = email.toLowerCase().trim()
|
const normalized = email.toLowerCase().trim()
|
||||||
const rows = await withTenant(tenantId, (client) =>
|
const rows = await withTenant(tenantId, (client) =>
|
||||||
client.query('SELECT 1 FROM suppression_list WHERE email = $1 LIMIT 1', [normalized])
|
client.query<{ '?column?': number }>(
|
||||||
|
'SELECT 1 FROM suppression_list WHERE email = $1 LIMIT 1',
|
||||||
|
[normalized]
|
||||||
|
)
|
||||||
)
|
)
|
||||||
return rows.length > 0
|
return rows.length > 0
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user