new file: .env.local modified: .gitignore new file: docs/mock-audit.md modified: eslint.config.js modified: package-lock.json modified: package.json deleted: src/App.css modified: src/App.jsx deleted: src/assets/react.svg deleted: src/assets/vite.svg new file: src/components/RichTextEditor.jsx modified: src/components/calendar/AgendaMonthlyView.jsx modified: src/components/calendar/AgendaWeeklyView.jsx modified: src/components/ui.jsx modified: src/config/api.js modified: src/data/mockData.js new file: src/data/reportTemplates.js modified: src/hooks/useAgenda.js modified: src/mappers/appointmentMapper.js modified: src/pages/AgendaPage.jsx modified: src/pages/MedicalRecordsPage.jsx modified: src/pages/MessagesPage.jsx modified: src/pages/PatientsPage.jsx modified: src/pages/ProfilePage.jsx modified: src/pages/ReportsPage.jsx modified: src/pages/UsersPage.jsx modified: src/pages/VisitsPage.jsx modified: src/repositories/patientRepository.js modified: src/repositories/profileRepository.js modified: src/repositories/userRepository.js deleted: test.mjs deleted: test2.mjs deleted: test3.mjs deleted: test4.mjs deleted: test5.mjs new file: tests/mappers.test.mjs new file: tests/patientRepository.test.mjs new file: tests/permissions.test.mjs new file: tests/repositoryUtils.test.mjs
41 lines
1.4 KiB
JavaScript
41 lines
1.4 KiB
JavaScript
import assert from 'node:assert/strict'
|
|
import test from 'node:test'
|
|
|
|
import { getResponseError, translateErrorMessage } from '../src/repositories/repositoryUtils.js'
|
|
|
|
test('traduz erros crus comuns do Supabase para pt-BR', () => {
|
|
assert.equal(translateErrorMessage('Invalid login credentials'), 'E-mail ou senha inválidos.')
|
|
assert.equal(
|
|
translateErrorMessage('new row violates row-level security policy for table "patients"'),
|
|
'Você não tem permissão para realizar esta ação.',
|
|
)
|
|
assert.equal(
|
|
translateErrorMessage('invalid input value for enum appointment_type: "teleconsulta"'),
|
|
'Valor inválido para uma opção do sistema.',
|
|
)
|
|
})
|
|
|
|
test('getResponseError preserva erros estruturados em portugues da API', async () => {
|
|
const response = new Response(
|
|
JSON.stringify({
|
|
title: 'Erro de Validacao',
|
|
errors: {
|
|
cpf: ['Campo obrigatorio'],
|
|
},
|
|
}),
|
|
{ status: 400 },
|
|
)
|
|
|
|
const message = await getResponseError(response, 'Erro ao criar usuario.')
|
|
|
|
assert.match(message, /Erro ao criar usuario\. \(400\):/)
|
|
assert.match(message, /cpf: Campo obrigatorio/)
|
|
})
|
|
|
|
test('getResponseError usa fallback em ingles desconhecido', async () => {
|
|
const response = new Response('Something went wrong in backend', { status: 500 })
|
|
const message = await getResponseError(response, 'Falha ao salvar registro.')
|
|
|
|
assert.equal(message, 'Falha ao salvar registro. (500): Falha ao salvar registro.')
|
|
})
|