157 lines
5.3 KiB
JavaScript
157 lines
5.3 KiB
JavaScript
/**
|
||
* Script de teste completo para verificar se Guilherme pode acessar o sistema
|
||
*/
|
||
|
||
const SUPABASE_URL = "https://yuanqfswhberkoevtmfr.supabase.co";
|
||
const SUPABASE_ANON_KEY =
|
||
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Inl1YW5xZnN3aGJlcmtvZXZ0bWZyIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NTQ5NTQzNjksImV4cCI6MjA3MDUzMDM2OX0.g8Fm4XAvtX46zifBZnYVH4tVuQkqUH6Ia9CXQj4DztQ";
|
||
|
||
const GUILHERME_EMAIL = "guilhermesilvagomes1020@gmail.com";
|
||
const GUILHERME_PASSWORD = "guilherme123";
|
||
|
||
async function testarGuilherme() {
|
||
try {
|
||
console.log("\n🧪 === TESTANDO ACESSO DO GUILHERME ===\n");
|
||
|
||
// 1. Testar login
|
||
console.log("1️⃣ Testando login do Guilherme...");
|
||
console.log(` Email: ${GUILHERME_EMAIL}`);
|
||
console.log(` Senha: ${GUILHERME_PASSWORD}\n`);
|
||
|
||
const loginResponse = await fetch(
|
||
`${SUPABASE_URL}/auth/v1/token?grant_type=password`,
|
||
{
|
||
method: "POST",
|
||
headers: {
|
||
"Content-Type": "application/json",
|
||
apikey: SUPABASE_ANON_KEY,
|
||
},
|
||
body: JSON.stringify({
|
||
email: GUILHERME_EMAIL,
|
||
password: GUILHERME_PASSWORD,
|
||
}),
|
||
}
|
||
);
|
||
|
||
if (!loginResponse.ok) {
|
||
const error = await loginResponse.text();
|
||
console.error("❌ Erro no login:", error);
|
||
throw new Error("Login falhou");
|
||
}
|
||
|
||
const loginData = await loginResponse.json();
|
||
const token = loginData.access_token;
|
||
const userId = loginData.user.id;
|
||
|
||
console.log("✅ Login realizado com sucesso!");
|
||
console.log(` User ID: ${userId}`);
|
||
console.log(` Email verificado: ${loginData.user.email}\n`);
|
||
|
||
// 2. Verificar pacientes atribuídos
|
||
console.log("2️⃣ Verificando pacientes atribuídos...");
|
||
const assignmentsResponse = await fetch(
|
||
`${SUPABASE_URL}/rest/v1/patient_assignments?user_id=eq.${userId}`,
|
||
{
|
||
headers: {
|
||
apikey: SUPABASE_ANON_KEY,
|
||
Authorization: `Bearer ${token}`,
|
||
},
|
||
}
|
||
);
|
||
|
||
const assignments = await assignmentsResponse.json();
|
||
console.log(` ✅ ${assignments.length} paciente(s) atribuído(s)`);
|
||
|
||
if (assignments.length > 0) {
|
||
for (const assignment of assignments) {
|
||
console.log(`\n 📋 Atribuição:`);
|
||
console.log(` Patient ID: ${assignment.patient_id}`);
|
||
console.log(` Role: ${assignment.role}`);
|
||
|
||
// Buscar dados do paciente
|
||
const patientResponse = await fetch(
|
||
`${SUPABASE_URL}/rest/v1/patients?id=eq.${assignment.patient_id}`,
|
||
{
|
||
headers: {
|
||
apikey: SUPABASE_ANON_KEY,
|
||
Authorization: `Bearer ${token}`,
|
||
},
|
||
}
|
||
);
|
||
|
||
const patients = await patientResponse.json();
|
||
if (patients && patients.length > 0) {
|
||
const patient = patients[0];
|
||
console.log(` Nome: ${patient.full_name}`);
|
||
console.log(` Email: ${patient.email}`);
|
||
console.log(` Telefone: ${patient.phone_mobile}`);
|
||
}
|
||
}
|
||
}
|
||
|
||
// 3. Verificar consultas (localStorage simulation)
|
||
console.log("\n3️⃣ Verificando consultas de demonstração...");
|
||
const fs = await import("fs");
|
||
const path = await import("path");
|
||
const { fileURLToPath } = await import("url");
|
||
const { dirname } = await import("path");
|
||
|
||
const __filename = fileURLToPath(import.meta.url);
|
||
const __dirname = dirname(__filename);
|
||
|
||
const consultasPath = path.join(
|
||
__dirname,
|
||
"..",
|
||
"src",
|
||
"data",
|
||
"consultas-demo.json"
|
||
);
|
||
|
||
if (fs.existsSync(consultasPath)) {
|
||
const consultasData = fs.readFileSync(consultasPath, "utf-8");
|
||
const consultas = JSON.parse(consultasData);
|
||
|
||
console.log(` ✅ ${consultas.length} consultas encontradas\n`);
|
||
|
||
consultas.forEach((consulta, index) => {
|
||
console.log(` 📅 Consulta ${index + 1}:`);
|
||
console.log(` Data/Hora: ${consulta.dataHora}`);
|
||
console.log(` Status: ${consulta.status}`);
|
||
console.log(` Tipo: ${consulta.tipo}`);
|
||
console.log(` Médico: ${consulta.medicoNome}`);
|
||
console.log(` Observações: ${consulta.observacoes}\n`);
|
||
});
|
||
} else {
|
||
console.log(" ⚠️ Arquivo de consultas não encontrado");
|
||
}
|
||
|
||
// 4. Resumo final
|
||
console.log("\n✅ === TODOS OS TESTES PASSARAM! ===\n");
|
||
console.log("📋 RESUMO:");
|
||
console.log(` ✅ Login funcionando`);
|
||
console.log(` ✅ Paciente atribuído ao usuário`);
|
||
console.log(` ✅ Consultas de demonstração criadas`);
|
||
console.log(` ✅ Role: user (acesso ao painel paciente)\n`);
|
||
|
||
console.log("🎯 PRÓXIMA AÇÃO:");
|
||
console.log(" 1. Inicie o servidor de desenvolvimento: npm run dev");
|
||
console.log(" 2. Acesse: http://localhost:5173/paciente");
|
||
console.log(" 3. Faça login com:");
|
||
console.log(` Email: ${GUILHERME_EMAIL}`);
|
||
console.log(` Senha: ${GUILHERME_PASSWORD}`);
|
||
console.log(" 4. Você verá as 3 consultas no painel!\n");
|
||
|
||
console.log("💡 DICA:");
|
||
console.log(" As consultas são carregadas automaticamente do arquivo");
|
||
console.log(" src/data/consultas-demo.json para o localStorage\n");
|
||
} catch (error) {
|
||
console.error("\n❌ ERRO NO TESTE:", error.message);
|
||
if (error.stack) {
|
||
console.error(error.stack);
|
||
}
|
||
process.exit(1);
|
||
}
|
||
}
|
||
|
||
testarGuilherme();
|