Implement rock-solid automated testing infrastructure for mana-core-auth with daily execution, notifications, and comprehensive monitoring. Test Suite Improvements: - Fix all 36 failing BetterAuthService tests (missing service mocks) - Add 21 JwtAuthGuard tests achieving 100% statement coverage - Create silentError helper to suppress intentional error logs - Fix Todo backend TaskService test structure - Add jose mock for JWT testing - Configure jest collectCoverageFrom for mana-core-auth GitHub Actions Workflow: - Daily automated test execution (2 AM UTC + manual trigger) - Matrix parallelization across 6 backend services - PostgreSQL and Redis service containers - Coverage enforcement (80% threshold) - Multi-channel notifications (Discord, Slack, GitHub Issues) - Support for success notifications (opt-in) Test Infrastructure: - Coverage aggregation across multiple services - Flaky test detection with 30-run history tracking - Performance metrics tracking with regression detection - Test data seeding and cleanup scripts - Comprehensive test reporting with formatted metrics Documentation: - TESTING_GUIDE.md (4000+ words) - Complete testing documentation - AUTOMATED_TESTING_SYSTEM.md - System architecture and workflows - DISCORD_NOTIFICATIONS_SETUP.md - Discord webhook setup guide - TESTING_DEPLOYMENT_CHECKLIST.md - Pre-deployment verification - TESTING_QUICK_REFERENCE.md - Quick command reference Final Result: - 180/180 tests passing (100% pass rate) - Zero console errors in test output - Automated daily testing with rich notifications - Production-ready test infrastructure
5.9 KiB
Discord Notifications Setup
This guide shows you how to set up Discord notifications for daily test results.
Quick Setup (5 minutes)
1. Create Discord Webhook
- Open your Discord server
- Go to Server Settings → Integrations → Webhooks
- Click New Webhook
- Configure:
- Name:
ManaCore CI/CD(or whatever you prefer) - Channel: Select the channel for test notifications (e.g.,
#dev-alerts) - Avatar: Optional - upload a custom icon
- Name:
- Click Copy Webhook URL
2. Add Webhook to GitHub Secrets
- Go to your GitHub repository
- Navigate to Settings → Secrets and variables → Actions
- Click New repository secret
- Add:
- Name:
DISCORD_WEBHOOK_URL - Value: Paste the webhook URL from Discord
- Name:
- Click Add secret
3. That's It!
The workflow will now send Discord notifications automatically:
- Failure notifications: Always sent when tests fail
- Success notifications: Optional (enable via manual workflow trigger)
What You'll Receive
Failure Notification
When tests fail, you'll get a red embed:
❌ Daily Tests Failed
The daily test suite encountered failures and needs attention.
📅 Date: 2025-12-26
📊 Coverage: 87.5%
🔗 Workflow Run: [View Details](link)
Color: Red (#E74C3C)
Success Notification (Optional)
When tests pass and you enable success notifications:
✅ Daily Tests Passed
All tests completed successfully!
📅 Date: 2025-12-26
📊 Coverage: 95.3%
✅ Tests: 180 passed
🔗 Workflow Run: [View Details](link)
Color: Green (#2ECC71)
Advanced Configuration
Enable Success Notifications
By default, only failures send Discord notifications. To get success notifications:
- Go to Actions → Daily Tests workflow
- Click Run workflow
- Check the box: Send Discord notification on success
- Run workflow
Customize Notification Content
Edit .github/workflows/daily-tests.yml and modify the Discord webhook payload:
- name: Send Discord notification
run: |
curl -X POST "$DISCORD_WEBHOOK_URL" \
-H 'Content-Type: application/json' \
-d '{
"username": "Your Custom Name",
"avatar_url": "https://your-custom-avatar.png",
"embeds": [{
"title": "Custom Title",
"description": "Custom description",
"color": 15158332,
...
}]
}'
Change Notification Channel
In Discord:
- Server Settings → Integrations → Webhooks
- Find ManaCore CI/CD webhook
- Change Channel dropdown
- Save
The GitHub secret stays the same - no need to update!
Add Multiple Channels
To send to multiple Discord channels:
- Create multiple webhooks in Discord (one per channel)
- Add multiple secrets to GitHub:
DISCORD_WEBHOOK_URL_ALERTSDISCORD_WEBHOOK_URL_TEAMDISCORD_WEBHOOK_URL_DEVOPS
- Duplicate the Discord notification step in the workflow for each webhook
Discord Webhook URL Format
The webhook URL should look like:
https://discord.com/api/webhooks/[WEBHOOK_ID]/[WEBHOOK_TOKEN]
Security: Never commit this URL to git! Always use GitHub Secrets.
Troubleshooting
Notifications Not Appearing
-
Check webhook is active:
- Discord → Server Settings → Integrations → Webhooks
- Verify webhook exists and is enabled
-
Check GitHub secret:
- GitHub → Settings → Secrets →
DISCORD_WEBHOOK_URL - Verify secret exists and is spelled correctly
- GitHub → Settings → Secrets →
-
Check workflow logs:
- GitHub Actions → Daily Tests → Latest run
- Look for "Send Discord notification" step
- Check for curl errors
Rate Limiting
Discord webhooks are rate-limited to:
- 30 requests per minute per webhook
- 5 requests per 2 seconds burst
Our daily workflow sends 1-2 notifications per day, well within limits.
Testing Your Webhook
Test the webhook without running the full workflow:
# Replace with your actual webhook URL
WEBHOOK_URL="https://discord.com/api/webhooks/YOUR_WEBHOOK_HERE"
curl -X POST "$WEBHOOK_URL" \
-H 'Content-Type: application/json' \
-d '{
"username": "Test Bot",
"content": "This is a test message from curl!"
}'
If you see the message in Discord, your webhook works!
Slack + Discord Together
You can use both Slack and Discord notifications simultaneously:
-
Add both secrets:
DISCORD_WEBHOOK_URLSLACK_WEBHOOK_URL
-
The workflow checks for both and sends to whichever exists
Discord Embed Colors
The workflow uses these colors:
| Status | Color | Hex |
|---|---|---|
| ❌ Failure | Red | #E74C3C (15158332) |
| ✅ Success | Green | #2ECC71 (3066993) |
To customize, change the "color" field in the workflow.
Security Best Practices
- ✅ Do: Store webhook URL in GitHub Secrets
- ✅ Do: Use a dedicated Discord channel for CI/CD
- ✅ Do: Restrict webhook permissions if possible
- ❌ Don't: Commit webhook URLs to git
- ❌ Don't: Share webhook URLs publicly
- ❌ Don't: Use webhooks with admin permissions
Example: Full Setup
# 1. Create Discord webhook
Discord → Server Settings → Integrations → Create Webhook
Channel: #dev-alerts
Copy URL: https://discord.com/api/webhooks/123456789/abcdefg
# 2. Add to GitHub
GitHub → Settings → Secrets → New secret
Name: DISCORD_WEBHOOK_URL
Value: https://discord.com/api/webhooks/123456789/abcdefg
# 3. Test (optional)
GitHub Actions → Daily Tests → Run workflow
# 4. Done!
Wait for next daily run (2 AM UTC) or trigger manually
Support
For issues with:
- Discord webhooks: Discord API Docs
- GitHub Actions: GitHub Actions Docs
- This workflow: See
docs/TESTING_GUIDE.md
🏗️ ManaCore Monorepo