// test-webhook.js - Simple test script for webhook endpoint const fetch = require('node-fetch'); const WEBHOOK_URL = 'http://localhost:8012/api/github/webhook'; // Test webhook with a sample GitHub push event const testPayload = { ref: 'refs/heads/main', before: 'abc123', after: 'def456', repository: { id: 123456, name: 'test-repo', full_name: 'testuser/test-repo', owner: { login: 'testuser', id: 789 } }, pusher: { name: 'testuser', email: 'test@example.com' }, commits: [ { id: 'def456', message: 'Test commit', author: { name: 'Test User', email: 'test@example.com' } } ] }; async function testWebhook() { try { console.log('๐Ÿงช Testing webhook endpoint...'); console.log(`๐Ÿ“ก Sending POST request to: ${WEBHOOK_URL}`); const response = await fetch(WEBHOOK_URL, { method: 'POST', headers: { 'Content-Type': 'application/json', 'X-GitHub-Event': 'push', 'X-GitHub-Delivery': 'test-delivery-123' }, body: JSON.stringify(testPayload) }); const result = await response.json(); console.log('๐Ÿ“Š Response Status:', response.status); console.log('๐Ÿ“‹ Response Body:', JSON.stringify(result, null, 2)); if (response.ok) { console.log('โœ… Webhook test successful!'); } else { console.log('โŒ Webhook test failed!'); } } catch (error) { console.error('โŒ Error testing webhook:', error.message); } } // Run the test testWebhook();