# Newsletter Testing Guide ## πŸ§ͺ Complete Test Suite for All Newsletter Types This guide shows how to test every newsletter function from the admin panel. ## πŸ“¬ Available Test Types ### **API Endpoint** ``` POST /api/v1/admin/newsletter/test Authorization: Bearer {admin_token} Content-Type: application/json ``` ### **Request Body** ```json { "email": "your-test@email.com", // or use "emails": ["email1@test.com", "email2@test.com"] "type": "test_type_here" } ``` --- ## βœ… Test Cases (All Newsletter Functions) ### 1. **Subscription Flow Tests** #### A. Setup Email (Initial Token Email) ```bash curl -X POST http://localhost:8080/api/v1/admin/newsletter/test \ -H "Authorization: Bearer YOUR_ADMIN_TOKEN" \ -H "Content-Type: application/json" \ -d '{ "email": "test@example.com", "type": "setup" }' ``` **Tests**: - βœ… Initial subscription email with token - βœ… Link to preference setup page - βœ… Token generation and URL formatting #### B. Welcome Email ```bash curl -X POST http://localhost:8080/api/v1/admin/newsletter/test \ -H "Authorization: Bearer YOUR_ADMIN_TOKEN" \ -H "Content-Type: application/json" \ -d '{ "email": "test@example.com", "type": "welcome" }' ``` **Tests**: - βœ… Welcome introduction email - βœ… Unsubscribe/manage links - βœ… Club branding #### C. Welcome Back Email (Resubscribe) ```bash curl -X POST http://localhost:8080/api/v1/admin/newsletter/test \ -H "Authorization: Bearer YOUR_ADMIN_TOKEN" \ -H "Content-Type: application/json" \ -d '{ "email": "test@example.com", "type": "welcome_back" }' ``` **Tests**: - βœ… Resubscription email - βœ… Preference restoration --- ### 2. **TΓ½dennΓ­ PΕ™ehled (Weekly Overview)** ```bash curl -X POST http://localhost:8080/api/v1/admin/newsletter/test \ -H "Authorization: Bearer YOUR_ADMIN_TOKEN" \ -H "Content-Type: application/json" \ -d '{ "email": "test@example.com", "type": "weekly" }' ``` **Tests**: - βœ… Weekly digest with all content - βœ… Blogs section - βœ… Events section - βœ… Upcoming matches section - βœ… Recent scores section - βœ… Preference-based filtering - βœ… Category filtering **Individual Sections**: ```bash # Test only blogs "type": "blogs" # Test only events "type": "events" # Test only matches "type": "matches" # Test only scores "type": "scores" ``` --- ### 3. **NadchΓ‘zejΓ­cΓ­ ZΓ‘pasy (Match Reminders)** #### A. 48-Hour Reminder ```bash curl -X POST http://localhost:8080/api/v1/admin/newsletter/test \ -H "Authorization: Bearer YOUR_ADMIN_TOKEN" \ -H "Content-Type: application/json" \ -d '{ "email": "test@example.com", "type": "match_reminder_48h" }' ``` **Tests**: - βœ… 48h before match alert - βœ… Match category display - βœ… Teams display - βœ… Date and time - βœ… Place/venue - βœ… Proper formatting #### B. Day-of Reminder ```bash curl -X POST http://localhost:8080/api/v1/admin/newsletter/test \ -H "Authorization: Bearer YOUR_ADMIN_TOKEN" \ -H "Content-Type: application/json" \ -d '{ "email": "test@example.com", "type": "match_reminder_today" }' ``` **Tests**: - βœ… Same-day match alert - βœ… All match details - βœ… Urgency messaging --- ### 4. **Blog Notifications** ```bash curl -X POST http://localhost:8080/api/v1/admin/newsletter/test \ -H "Authorization: Bearer YOUR_ADMIN_TOKEN" \ -H "Content-Type: application/json" \ -d '{ "email": "test@example.com", "type": "blog_notification" }' ``` **Tests**: - βœ… New blog release notification - βœ… Article title and excerpt - βœ… Link to full article - βœ… Call-to-action button - βœ… Proper styling --- ### 5. **VΓ½sledky ZΓ‘pasu (Match Results)** ```bash curl -X POST http://localhost:8080/api/v1/admin/newsletter/test \ -H "Authorization: Bearer YOUR_ADMIN_TOKEN" \ -H "Content-Type: application/json" \ -d '{ "email": "test@example.com", "type": "match_result" }' ``` **Tests**: - βœ… Match result notification - βœ… Final score display - βœ… Date and competition - βœ… Result formatting - βœ… Victory/defeat messaging --- ### 6. **Basic SMTP Test** ```bash curl -X POST http://localhost:8080/api/v1/admin/newsletter/test \ -H "Authorization: Bearer YOUR_ADMIN_TOKEN" \ -H "Content-Type: application/json" \ -d '{ "email": "test@example.com", "type": "newsletter" }' ``` **Tests**: - βœ… SMTP configuration - βœ… Email delivery - βœ… Basic template rendering --- ## 🎯 Complete Test Checklist Use this checklist to verify all newsletter functions: ### Subscription & Onboarding - [ ] **setup** - Initial setup email with token βœ‰οΈ - [ ] **welcome** - Welcome email with manage/unsubscribe βœ‰οΈ - [ ] **welcome_back** - Resubscribe email βœ‰οΈ ### Content Newsletters - [ ] **weekly** - Full weekly digest (all sections) πŸ“… - [ ] **blogs** - Blog-only digest πŸ“° - [ ] **events** - Events-only digest πŸŽ‰ - [ ] **matches** - Matches-only digest ⚽ - [ ] **scores** - Scores-only digest πŸ† ### Match Notifications - [ ] **match_reminder_48h** - 48h before match ⏰ - [ ] **match_reminder_today** - Day-of match ⏰ ### Special Notifications - [ ] **blog_notification** - New blog release πŸ“ - [ ] **match_result** - Post-match result 🎯 ### System Test - [ ] **newsletter** - Basic SMTP test πŸ”§ --- ## πŸ–₯️ Admin UI Test Buttons (Implementation Guide) To add test buttons to your admin panel, create a test page with these buttons: ```typescript // Example React/TypeScript implementation const newsletterTests = [ { type: 'setup', label: 'Setup Email', icon: 'βš™οΈ', category: 'Subscription' }, { type: 'welcome', label: 'Welcome Email', icon: 'πŸ‘‹', category: 'Subscription' }, { type: 'welcome_back', label: 'Welcome Back', icon: 'πŸ”„', category: 'Subscription' }, { type: 'weekly', label: 'Weekly Digest', icon: 'πŸ“…', category: 'Digests' }, { type: 'blogs', label: 'Blogs Only', icon: 'πŸ“°', category: 'Digests' }, { type: 'events', label: 'Events Only', icon: 'πŸŽ‰', category: 'Digests' }, { type: 'matches', label: 'Matches Only', icon: '⚽', category: 'Digests' }, { type: 'scores', label: 'Scores Only', icon: 'πŸ†', category: 'Digests' }, { type: 'match_reminder_48h', label: '48h Match Alert', icon: '⏰', category: 'Alerts' }, { type: 'match_reminder_today', label: 'Today Match Alert', icon: 'πŸ””', category: 'Alerts' }, { type: 'blog_notification', label: 'Blog Release', icon: 'πŸ“', category: 'Alerts' }, { type: 'match_result', label: 'Match Result', icon: '🎯', category: 'Alerts' }, { type: 'newsletter', label: 'SMTP Test', icon: 'πŸ”§', category: 'System' }, ]; async function sendTest(type: string, email: string) { const response = await fetch('/api/v1/admin/newsletter/test', { method: 'POST', headers: { 'Authorization': `Bearer ${adminToken}`, 'Content-Type': 'application/json', }, body: JSON.stringify({ type, email }), }); if (response.ok) { alert(`Test email "${type}" sent to ${email}`); } else { alert('Failed to send test email'); } } ``` ### UI Layout Suggestion ``` β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Newsletter Testing Panel β”‚ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ β”‚ β”‚ β”‚ Test Email: [________________] πŸ“§ β”‚ β”‚ β”‚ β”‚ β”Œβ”€β”€β”€ Subscription Flow ───────────┐ β”‚ β”‚ β”‚ [βš™οΈ Setup Email] β”‚ β”‚ β”‚ β”‚ [πŸ‘‹ Welcome Email] β”‚ β”‚ β”‚ β”‚ [πŸ”„ Welcome Back] β”‚ β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”‚ β”‚ β”‚ β”Œβ”€β”€β”€ Content Digests ─────────────┐ β”‚ β”‚ β”‚ [πŸ“… Weekly Digest] β”‚ β”‚ β”‚ β”‚ [πŸ“° Blogs] [πŸŽ‰ Events] β”‚ β”‚ β”‚ β”‚ [⚽ Matches] [πŸ† Scores] β”‚ β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”‚ β”‚ β”‚ β”Œβ”€β”€β”€ Match Alerts ────────────────┐ β”‚ β”‚ β”‚ [⏰ 48h Reminder] β”‚ β”‚ β”‚ β”‚ [πŸ”” Today Reminder] β”‚ β”‚ β”‚ β”‚ [🎯 Match Result] β”‚ β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”‚ β”‚ β”‚ β”Œβ”€β”€β”€ Special Notifications ───────┐ β”‚ β”‚ β”‚ [πŸ“ Blog Release] β”‚ β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”‚ β”‚ β”‚ β”Œβ”€β”€β”€ System ──────────────────────┐ β”‚ β”‚ β”‚ [πŸ”§ SMTP Test] β”‚ β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` --- ## πŸ” Verification Steps ### After Sending Each Test: 1. **Check Email Inbox** - Verify email received - Check sender name and address - Verify subject line 2. **Verify Content** - Check all text renders correctly - Verify images load (if any) - Test all links work - Check responsive design (mobile/desktop) 3. **Test Interactive Elements** - Click article links (should track) - Click unsubscribe (should work with token) - Click manage preferences (should load page) 4. **Verify Analytics** - Check `email_log` table for entry - Open email and verify `email_event` logs "open" - Click link and verify `email_event` logs "click" ```sql -- Check email logs SELECT * FROM email_log ORDER BY created_at DESC LIMIT 10; -- Check events SELECT * FROM email_event ORDER BY created_at DESC LIMIT 10; ``` --- ## πŸ› Troubleshooting ### Email Not Received? 1. **Check SMTP Configuration** ```sql SELECT smtp_host, smtp_port, smtp_from FROM settings LIMIT 1; ``` 2. **Check Spam Folder** - Test emails might be flagged as spam - Add sender to whitelist 3. **Check Server Logs** ```bash # Look for SMTP errors grep -i "smtp" logs/app.log grep -i "newsletter" logs/app.log ``` 4. **Verify Email Address** - Ensure email format is valid - Try different email provider ### Wrong Content? 1. **Check Cache Files** ```bash ls -la cache/prefetch/ # Should have: articles.json, events_upcoming.json, facr_club_info.json ``` 2. **Refresh Cache** - Wait for prefetcher cycle (30 minutes) - Or manually trigger: `POST /api/v1/admin/prefetch/trigger` ### Links Not Working? 1. **Check Frontend URL** ```bash echo $FRONTEND_BASE_URL # Should be: http://localhost:3000 (dev) or https://your-domain.com (prod) ``` 2. **Verify Token Generation** ```bash echo $JWT_SECRET # Should NOT be: "default-secret-key-change-in-production" ``` --- ## πŸ“Š Test Results Log Template Use this to track your testing: ```markdown ## Newsletter Test Results - [Date] ### Subscription Flow - [ ] Setup Email - βœ…/❌ - Notes: _______ - [ ] Welcome Email - βœ…/❌ - Notes: _______ - [ ] Welcome Back - βœ…/❌ - Notes: _______ ### Content Digests - [ ] Weekly Digest - βœ…/❌ - Notes: _______ - [ ] Blogs Only - βœ…/❌ - Notes: _______ - [ ] Events Only - βœ…/❌ - Notes: _______ - [ ] Matches Only - βœ…/❌ - Notes: _______ - [ ] Scores Only - βœ…/❌ - Notes: _______ ### Match Alerts - [ ] 48h Reminder - βœ…/❌ - Notes: _______ - [ ] Today Reminder - βœ…/❌ - Notes: _______ - [ ] Match Result - βœ…/❌ - Notes: _______ ### Special Notifications - [ ] Blog Release - βœ…/❌ - Notes: _______ ### System - [ ] SMTP Test - βœ…/❌ - Notes: _______ ### Analytics Verification - [ ] Open tracking works - βœ…/❌ - [ ] Click tracking works - βœ…/❌ - [ ] Blog link tracking works - βœ…/❌ - [ ] Unsubscribe works - βœ…/❌ ### Issues Found: 1. _______________________ 2. _______________________ 3. _______________________ ``` --- ## πŸš€ Quick Test All (Bash Script) Save this as `test-newsletters.sh`: ```bash #!/bin/bash TOKEN="YOUR_ADMIN_TOKEN" EMAIL="your-test@email.com" API="http://localhost:8080/api/v1/admin/newsletter/test" test_types=( "setup" "welcome" "welcome_back" "weekly" "blogs" "events" "matches" "scores" "match_reminder_48h" "match_reminder_today" "blog_notification" "match_result" "newsletter" ) for type in "${test_types[@]}"; do echo "Testing: $type" curl -X POST "$API" \ -H "Authorization: Bearer $TOKEN" \ -H "Content-Type: application/json" \ -d "{\"email\":\"$EMAIL\",\"type\":\"$type\"}" echo "" sleep 2 # Delay between requests done echo "All tests sent to $EMAIL" ``` **Usage**: ```bash chmod +x test-newsletters.sh ./test-newsletters.sh ``` --- ## βœ… Summary **Total Test Types Available**: 13 | Category | Test Types | Count | |----------|-----------|-------| | Subscription | setup, welcome, welcome_back | 3 | | Digests | weekly, blogs, events, matches, scores | 5 | | Alerts | match_reminder_48h, match_reminder_today, blog_notification, match_result | 4 | | System | newsletter | 1 | **All newsletter functions can be tested individually from the admin panel!** πŸŽ‰