modified: .env.example
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
This commit is contained in:
59
tests/patientRepository.test.mjs
Normal file
59
tests/patientRepository.test.mjs
Normal file
@@ -0,0 +1,59 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import test from 'node:test'
|
||||
|
||||
process.env.VITE_SUPABASE_URL = 'https://example.supabase.co'
|
||||
process.env.VITE_SUPABASE_ANON_KEY = 'anon-key'
|
||||
|
||||
globalThis.Event = class Event {
|
||||
constructor(type) {
|
||||
this.type = type
|
||||
}
|
||||
}
|
||||
|
||||
globalThis.window = {
|
||||
dispatchEvent() {},
|
||||
sessionStorage: {
|
||||
getItem() {
|
||||
return JSON.stringify({
|
||||
access_token: 'access-token',
|
||||
expires_at: Math.floor(Date.now() / 1000) + 3600,
|
||||
})
|
||||
},
|
||||
removeItem() {},
|
||||
setItem() {},
|
||||
},
|
||||
}
|
||||
|
||||
test('patientRepository.getById busca o paciente direto por id', async () => {
|
||||
const calls = []
|
||||
|
||||
globalThis.fetch = async (url) => {
|
||||
const requestUrl = String(url)
|
||||
calls.push(requestUrl)
|
||||
|
||||
if (requestUrl.includes('/patients?')) {
|
||||
return Response.json([
|
||||
{
|
||||
id: 'patient-1',
|
||||
full_name: 'Ana Souza',
|
||||
cpf: '12345678900',
|
||||
birth_date: '1990-01-01',
|
||||
},
|
||||
])
|
||||
}
|
||||
|
||||
if (requestUrl.includes('/appointments?')) {
|
||||
return Response.json([])
|
||||
}
|
||||
|
||||
throw new Error(`URL inesperada: ${requestUrl}`)
|
||||
}
|
||||
|
||||
const { patientRepository } = await import('../src/repositories/patientRepository.js')
|
||||
const patient = await patientRepository.getById('patient-1')
|
||||
|
||||
assert.equal(patient.id, 'patient-1')
|
||||
assert.equal(patient.name, 'Ana Souza')
|
||||
assert.ok(calls.some((url) => url.includes('/patients?') && url.includes('id=eq.patient-1')))
|
||||
assert.ok(calls.every((url) => !url.includes('/patients?select=*') || url.includes('id=eq.patient-1')))
|
||||
})
|
||||
Reference in New Issue
Block a user