import { describe, expect, it } from 'vitest'; import { GENERIC_SERVER_ERROR_MESSAGE, sanitizeApiErrorMessage } from '$lib/services/api'; describe('sanitizeApiErrorMessage', () => { it('replaces HTML payloads with the generic server error message', () => { const htmlMessage = 'SQL error'; expect(sanitizeApiErrorMessage(htmlMessage)).toBe(GENERIC_SERVER_ERROR_MESSAGE); }); it('replaces SQLSTATE content with the generic server error message', () => { const sqlMessage = 'SQLSTATE[HY000]: General error: 1 Unknown column'; expect(sanitizeApiErrorMessage(sqlMessage)).toBe(GENERIC_SERVER_ERROR_MESSAGE); }); it('returns short API messages unchanged', () => { const userMessage = 'User not found'; expect(sanitizeApiErrorMessage(userMessage)).toBe(userMessage); }); });