45 lines
1.7 KiB
JavaScript
45 lines
1.7 KiB
JavaScript
import { createClient } from '@supabase/supabase-js';
|
|
|
|
const supabaseUrl = 'https://jqklhhpyykzrktikjnmb.supabase.co';
|
|
const supabaseAnonKey = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Impxa2xoaHB5eWt6cmt0aWtqbm1iIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NjgzODQ0MDgsImV4cCI6MjA4Mzk2MDQwOH0.QsPuBnyUtRPSavlqKj3IGR9c8juT02LY_hSi-j3c6M0';
|
|
|
|
const supabase = createClient(supabaseUrl, supabaseAnonKey);
|
|
|
|
const TEST_USER_ID = '74441cc1-1d93-4ed7-9857-41499c947844';
|
|
const DUMMY_TOKEN = 'ExponentPushToken[TEST_TOKEN_1234567890]';
|
|
|
|
async function simulate() {
|
|
console.log(`1. Atribuindo token dummy ao utilizador ${TEST_USER_ID}...`);
|
|
const { error: err1 } = await supabase
|
|
.from('profiles')
|
|
.update({ fcm_token: DUMMY_TOKEN })
|
|
.eq('id', TEST_USER_ID);
|
|
|
|
if (err1) {
|
|
console.error("Erro ao atualizar token (pode ser RLS):", err1);
|
|
// Se falhar, tentamos inserir um novo perfil (caso não exista e o anon permita)
|
|
// Mas o mais provável é que já exista se houver agendamentos.
|
|
} else {
|
|
console.log("Token atualizado com sucesso.");
|
|
}
|
|
|
|
console.log(`2. Inserindo notificação para disparar Webhook...`);
|
|
const { data: notif, error: err2 } = await supabase
|
|
.from('notifications')
|
|
.insert([{
|
|
user_id: TEST_USER_ID,
|
|
message: 'Teste de Notificação Automático (Antigravity)',
|
|
read: false
|
|
}])
|
|
.select();
|
|
|
|
if (err2) {
|
|
console.error("Erro ao inserir notificação:", err2);
|
|
} else {
|
|
console.log("Notificação inserida com sucesso:", notif);
|
|
console.log("Se o Webhook estiver ativo, a Edge Function 'send-push-notification' foi disparada agora.");
|
|
}
|
|
}
|
|
|
|
simulate();
|