Files
moyosapp_beta.0.0.3.3_beta1/scripts/test-resend-webhook-simple.ts
2026-01-16 19:04:48 +02:00

78 lines
2.5 KiB
TypeScript
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env tsx
/**
* Simple Resend Webhook Test
*
* Tests the webhook endpoint directly without needing database records.
*
* Usage:
* npx tsx scripts/test-resend-webhook-simple.ts
*/
const BASE_URL = process.env.APP_URL || 'http://localhost:3001';
async function testWebhook() {
console.log('🔍 Testing Resend Webhook Endpoint\n');
console.log(` URL: ${BASE_URL}/api/webhooks/resend\n`);
// Test 1: GET request (should return webhook info)
console.log('1⃣ Testing GET request (webhook info)...');
try {
const getResponse = await fetch(`${BASE_URL}/api/webhooks/resend`);
const getData = await getResponse.json();
console.log(` Status: ${getResponse.status}`);
console.log(` Response:`, JSON.stringify(getData, null, 2));
console.log('');
} catch (error) {
console.log(` ❌ Error:`, error);
}
// Test 2: POST request with fake webhook payload
console.log('2⃣ Testing POST request (simulated webhook)...');
const fakeEmailId = 'test-email-' + Date.now();
const payload = {
type: 'email.delivered',
created_at: new Date().toISOString(),
data: {
email_id: fakeEmailId,
from: 'noreply@themoyos.co.za',
to: ['test@example.com'],
subject: 'Test Email',
created_at: new Date().toISOString(),
},
};
try {
const postResponse = await fetch(`${BASE_URL}/api/webhooks/resend`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(payload),
});
const postData = await postResponse.json();
console.log(` Status: ${postResponse.status}`);
console.log(` Response:`, JSON.stringify(postData, null, 2));
if (postResponse.ok) {
console.log('\n✅ Webhook endpoint is working!');
console.log(' (Email not found in DB is expected for this test)');
} else {
console.log('\n⚠ Webhook returned an error');
}
} catch (error) {
console.log(` ❌ Error:`, error);
}
console.log('\n📋 Summary:');
console.log(' - If you see "Email not found in logs" - webhook is working correctly');
console.log(' - The webhook only updates emails that exist in your database');
console.log(' - To test with real data:');
console.log(' 1. Send an email via the admin dashboard');
console.log(' 2. Deploy to production OR use ngrok for local testing');
console.log(' 3. Resend will send webhooks to your production URL');
}
testWebhook().catch(console.error);