littleshop/NOTIFICATION_TESTING_PLAN.md
SysAdmin 8b0e3e0611 Implement comprehensive notification system for LittleShop
- Add admin PWA push notifications for order management
- Integrate TeleBot customer messaging service
- Add push notification endpoints and VAPID key support
- Implement order status notifications throughout workflow
- Add notification UI components in admin panel
- Create TeleBotMessagingService for customer updates
- Add WebPush configuration to appsettings
- Fix compilation issues (BotStatus, BotContacts DbSet)
- Add comprehensive testing documentation

Features:
- Real-time admin notifications for new orders and status changes
- Customer order progress updates via TeleBot
- Graceful failure handling for notification services
- Test endpoints for notification system validation

🤖 Generated with Claude Code
Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-19 16:17:24 +01:00

12 KiB

🧪 Notification System Testing Plan

Prerequisites Checklist

Environment Setup

  • LittleShop application running locally (port 8080)
  • TeleBot service running (if testing TeleBot integration)
  • Admin user account created (admin/admin)
  • Web browser with push notification support (Chrome/Edge/Firefox)
  • BTCPay Server test instance configured

Configuration Verification

  • Check VAPID keys are configured in appsettings.json
  • Verify TeleBot API URL and API key are set
  • Ensure database has been migrated/created
  • Confirm admin user has Admin role in database

📱 Test Scenario 1: Admin PWA Push Notification Setup

1.1 Initial Setup Test

Steps:

  1. Open admin panel at http://localhost:8080/admin
  2. Login with admin credentials
  3. Check for notification prompt in navbar
  4. Click "Enable Notifications" button

Expected Results:

  • Browser permission prompt appears
  • After accepting, success message shows
  • Notification icon changes to active state
  • Test notification is received

Verification Commands:

# Check if subscription was saved
curl http://localhost:8080/api/push/subscriptions \
  -H "Cookie: [admin-cookie]"

1.2 Test Notification Endpoint

Steps:

  1. Navigate to admin panel
  2. Click notification test button
  3. Send test notification

API Test:

curl -X POST http://localhost:8080/api/push/test \
  -H "Content-Type: application/json" \
  -H "Cookie: [admin-cookie]" \
  -d '{"title":"Test Alert","body":"This is a test notification"}'

Expected Results:

  • Push notification appears on device
  • Notification contains correct title and body
  • Clicking notification opens admin panel

📱 Test Scenario 2: Order Lifecycle Notifications

2.1 New Order Creation

Steps:

  1. Create a new order via API or TeleBot
  2. Monitor admin notifications

API Test:

curl -X POST http://localhost:8080/api/orders \
  -H "Content-Type: application/json" \
  -d '{
    "customerIdentity": "test-customer-001",
    "items": [
      {
        "productId": "[product-guid]",
        "quantity": 1,
        "priceAtPurchase": 10.00
      }
    ],
    "shippingAddress": "123 Test St",
    "shippingMethod": "standard",
    "totalAmount": 15.00
  }'

Expected Admin Notifications:

  • "New Order Received - Order #abc12345 created for £15.00"

2.2 Payment Confirmation

Steps:

  1. Simulate BTCPay webhook for payment confirmation
  2. Monitor notifications

Webhook Simulation:

curl -X POST http://localhost:8080/api/orders/payments/webhook \
  -H "Content-Type: application/json" \
  -H "BTCPay-Sig: [webhook-signature]" \
  -d '{
    "invoiceId": "[invoice-id]",
    "status": "Settled",
    "orderId": "[order-id]"
  }'

Expected Notifications:

  • Admin: "Payment Confirmed - Order #abc12345 payment confirmed. Ready for acceptance."
  • TeleBot: Customer receives payment confirmation message

2.3 Order Status Progression

Test Each Status Change:

Status Change Admin Notification Customer Message
Accept Order "Order Accepted - Order #abc12345 has been accepted" "Great news! Your order has been accepted..."
Start Packing "Being Packed - Order #abc12345 is being packed" "Your order is currently being packed..."
Dispatch "Order Dispatched - Order #abc12345 dispatched with tracking: ABC123" "Your order is on its way! Tracking: ABC123..."
Deliver "Order Delivered - Order #abc12345 has been delivered" "Your order has been delivered successfully..."

Status Update Command:

# Accept order
curl -X PUT http://localhost:8080/api/admin/orders/[order-id]/status \
  -H "Content-Type: application/json" \
  -H "Cookie: [admin-cookie]" \
  -d '{"status": "Accepted"}'

🤖 Test Scenario 3: TeleBot Customer Messaging

3.1 TeleBot Service Availability

Check Service Status:

curl http://localhost:8080/api/push/telebot/status \
  -H "Cookie: [admin-cookie]"

Expected Response:

{
  "available": true,
  "message": "TeleBot service is available"
}

3.2 Test Message to Customer

Send Test Message:

curl -X POST http://localhost:8080/api/push/telebot/test \
  -H "Content-Type: application/json" \
  -H "Cookie: [admin-cookie]" \
  -d '{
    "customerId": "[customer-guid]",
    "message": "Test message from LittleShop admin"
  }'

Expected Results:

  • Customer receives message in Telegram
  • API returns success response
  • Message delivery logged in system

3.3 Order Progress Messages

Monitor TeleBot messages during order lifecycle:

  1. Payment Received:

    • Message: "💰 Your order #abc12345 has been paid successfully..."
  2. Order Accepted:

    • Message: " Great news! Your order #abc12345 has been accepted..."
  3. Packing Started:

    • Message: "📦 Your order #abc12345 is currently being packed..."
  4. Order Dispatched:

    • Message: "🚚 Your order #abc12345 is on its way! Tracking: ABC123..."
  5. Order Delivered:

    • Message: "🎉 Your order #abc12345 has been delivered successfully..."

🔧 Test Scenario 4: Error Handling

4.1 TeleBot Service Unavailable

Steps:

  1. Stop TeleBot service
  2. Process an order status change
  3. Verify system continues without errors

Expected Behavior:

  • Order processing continues normally
  • Error logged but not shown to user
  • Admin notifications still work

4.2 Push Notification Failure

Steps:

  1. Invalidate push subscription in database
  2. Process order status change
  3. Verify graceful failure

Expected Behavior:

  • Order processing continues
  • Invalid subscription removed from database
  • Error logged for debugging

4.3 Network Interruption

Steps:

  1. Simulate network failure to TeleBot API
  2. Process multiple orders
  3. Verify queue/retry mechanism

Expected Behavior:

  • Messages queued for retry
  • System remains responsive
  • Notifications sent when connection restored

📊 Test Scenario 5: Performance Testing

5.1 Concurrent Orders

Test Load:

# Create 10 orders simultaneously
for i in {1..10}; do
  curl -X POST http://localhost:8080/api/orders \
    -H "Content-Type: application/json" \
    -d "{\"customerIdentity\":\"customer-$i\",\"items\":[{\"productId\":\"[guid]\",\"quantity\":1}]}" &
done

Expected Results:

  • All orders created successfully
  • Notifications sent for each order
  • No message loss or duplication

5.2 Notification Delivery Time

Measure:

  • Time from order creation to admin notification
  • Time from status change to customer message
  • Expected: < 2 seconds for both

🔍 Test Scenario 6: Integration Testing

6.1 Full Order Flow Test

Complete Workflow:

  1. Customer creates order via TeleBot
  2. Admin receives new order notification
  3. Payment processed via BTCPay
  4. Both admin and customer notified
  5. Admin accepts order (notification sent)
  6. Admin marks as packing (notification sent)
  7. Admin dispatches with tracking (notification sent)
  8. Admin marks as delivered (notification sent)

Verification Points:

  • 8 admin notifications received
  • 5 customer messages sent
  • All messages have correct content
  • Order status correctly updated
  • Audit trail complete

6.2 Multi-Admin Testing

Setup:

  1. Create 3 admin users
  2. Enable push notifications for all
  3. Process an order

Expected Results:

  • All 3 admins receive notifications
  • Notifications are identical
  • No performance degradation

📝 Manual Testing Checklist

Admin Panel UI

  • Notification icon shows correct status
  • Test button works
  • Permission prompt handled correctly
  • Subscription list shows active subscriptions
  • Cleanup removes old subscriptions

Order Management

  • New order triggers notification
  • Payment confirmation triggers notification
  • Each status change triggers notification
  • Bulk status updates send notifications
  • Notification content is accurate

TeleBot Integration

  • Service status endpoint works
  • Test message endpoint works
  • Customer receives all expected messages
  • Messages formatted correctly with emojis
  • Links and tracking info included

Error Scenarios

  • Handles offline TeleBot gracefully
  • Handles invalid push subscriptions
  • Continues on notification failures
  • Logs errors appropriately
  • No user-facing error messages

🚀 Automated Test Commands

Run All Tests

# 1. Start services
cd /mnt/c/Production/Source/LittleShop
dotnet run --project LittleShop/LittleShop.csproj &
dotnet run --project TeleBot/TeleBot/TeleBot.csproj &

# 2. Wait for startup
sleep 10

# 3. Run test suite
./test-notifications.sh

# 4. Check results
cat notification-test-results.log

Create Test Script

#!/bin/bash
# test-notifications.sh

echo "Testing Admin Push Notifications..."
curl -X POST http://localhost:8080/api/push/test \
  -H "Content-Type: application/json" \
  -H "Cookie: $ADMIN_COOKIE" \
  -d '{"title":"Test","body":"Testing"}' \
  -w "\nStatus: %{http_code}\n"

echo "Testing TeleBot Service..."
curl http://localhost:8080/api/push/telebot/status \
  -H "Cookie: $ADMIN_COOKIE" \
  -w "\nStatus: %{http_code}\n"

echo "Creating Test Order..."
ORDER_ID=$(curl -X POST http://localhost:8080/api/orders \
  -H "Content-Type: application/json" \
  -d '{"customerIdentity":"test-001","items":[]}' \
  -s | jq -r '.id')

echo "Order created: $ORDER_ID"

# Test status updates
for status in "Accepted" "Packing" "Dispatched" "Delivered"; do
  echo "Updating to status: $status"
  curl -X PUT "http://localhost:8080/api/admin/orders/$ORDER_ID/status" \
    -H "Content-Type: application/json" \
    -H "Cookie: $ADMIN_COOKIE" \
    -d "{\"status\":\"$status\"}" \
    -w "\nStatus: %{http_code}\n"
  sleep 2
done

echo "Tests completed!"

Success Criteria

Functional Requirements

  • Admin users receive push notifications for all order events
  • Customers receive TeleBot messages for order updates
  • Notifications sent within 2 seconds of events
  • System continues operating if notifications fail
  • All notification content is accurate and formatted correctly

Non-Functional Requirements

  • No performance impact on order processing
  • Handles 100+ concurrent orders without issues
  • Graceful degradation when services unavailable
  • Comprehensive error logging
  • No sensitive data in notifications

Documentation

  • API endpoints documented
  • Configuration requirements clear
  • Troubleshooting guide available
  • Test scenarios reproducible

🐛 Common Issues and Solutions

Issue: Push notifications not received

Solution:

  1. Check browser permissions
  2. Verify VAPID keys configured
  3. Ensure HTTPS in production
  4. Check service worker registration

Issue: TeleBot messages not sent

Solution:

  1. Verify TeleBot service running
  2. Check API URL and credentials
  3. Ensure customer has Telegram ID
  4. Review TeleBot logs

Issue: Duplicate notifications

Solution:

  1. Check for multiple subscriptions
  2. Verify single service instance
  3. Review event handling logic
  4. Check database for duplicates

📋 Test Report Template

## Notification System Test Report
**Date:** [Date]
**Tester:** [Name]
**Environment:** [Dev/Staging/Prod]

### Test Results Summary
- Admin Push Notifications: [PASS/FAIL]
- TeleBot Customer Messages: [PASS/FAIL]
- Error Handling: [PASS/FAIL]
- Performance: [PASS/FAIL]

### Issues Found
1. [Issue description and severity]
2. [Issue description and severity]

### Recommendations
- [Recommendation 1]
- [Recommendation 2]

### Sign-off
- [ ] Ready for production
- [ ] Requires fixes