| 1 | # Discord End-to-End Tests |
| 2 | |
| 3 | This directory contains end-to-end (e2e) tests for the Discord service in Shoutrrr. |
| 4 | |
| 5 | ## Overview |
| 6 | |
| 7 | The end-to-end tests validate the complete Discord webhook functionality by making actual HTTP requests to Discord's API. |
| 8 | |
| 9 | ## Test Coverage |
| 10 | |
| 11 | ### Basic Message Functionality |
| 12 | |
| 13 | - Plain text messages with various content types |
| 14 | - Special characters and Unicode handling |
| 15 | - Long message content (chunking behavior) |
| 16 | |
| 17 | ### Rich Embed Features |
| 18 | |
| 19 | - Author information (name, URL, icon URL) |
| 20 | - Color customization and level-based coloring |
| 21 | - Custom fields with key-value pairs |
| 22 | - Image and thumbnail URLs |
| 23 | - Timestamps |
| 24 | - Multiple embeds in single messages |
| 25 | |
| 26 | ### File Attachments |
| 27 | |
| 28 | - Single file attachments |
| 29 | - Multiple file attachments |
| 30 | - Different file types and sizes |
| 31 | - Special characters in filenames |
| 32 | |
| 33 | ### Thread Support |
| 34 | |
| 35 | - Posting to existing threads using `thread_id` |
| 36 | - Thread permission and state handling |
| 37 | |
| 38 | ### Configuration Options |
| 39 | |
| 40 | - Custom username and avatar overrides |
| 41 | - JSON mode for raw payload delivery |
| 42 | - Complex parameter combinations |
| 43 | |
| 44 | ### Advanced Scenarios |
| 45 | |
| 46 | - Complex embeds with all features combined |
| 47 | - Edge cases and error conditions |
| 48 | - Rate limit handling with delays between tests |
| 49 | |
| 50 | ## Setup Requirements |
| 51 | |
| 52 | ### Discord Webhook Configuration |
| 53 | |
| 54 | 1. Create a Discord webhook in your server/channel: |
| 55 | - Go to Server Settings → Integrations → Webhooks |
| 56 | - Create a new webhook or use an existing one |
| 57 | - Copy the webhook URL |
| 58 | |
| 59 | 2. (Optional) Create a thread for thread testing: |
| 60 | - Post a message in your channel |
| 61 | - Right-click the message → "Create Thread" |
| 62 | - Copy the thread ID from the URL (the number after `/threads/`) |
| 63 | |
| 64 | ### Environment Variables |
| 65 | |
| 66 | Create a `.env` file in this directory with the following variables: |
| 67 | |
| 68 | ```bash |
| 69 | # Required: Discord webhook URL |
| 70 | SHOUTRRR_DISCORD_URL=discord://YOUR_WEBHOOK_TOKEN@YOUR_WEBHOOK_ID |
| 71 | |
| 72 | # Optional: Thread ID for thread testing |
| 73 | SHOUTRRR_DISCORD_THREAD_ID=YOUR_THREAD_ID |
| 74 | ``` |
| 75 | |
| 76 | **Security Note**: Never commit real webhook URLs to version control. The `.env` file is already in `.gitignore`. |
| 77 | |
| 78 | ### Example .env Configuration |
| 79 | |
| 80 | ```bash |
| 81 | SHOUTRRR_DISCORD_URL=discord://<TOKEN>@<WEBHOOK_ID> |
| 82 | SHOUTRRR_DISCORD_THREAD_ID=<THREAD_ID> |
| 83 | ``` |
| 84 | |
| 85 | ## Running the Tests |
| 86 | |
| 87 | ### Prerequisites |
| 88 | |
| 89 | - Go 1.25+ |
| 90 | - Valid Discord webhook URL |
| 91 | - `.env` file with required environment variables |
| 92 | |
| 93 | ### Execute E2E Tests |
| 94 | |
| 95 | Run all e2e tests: |
| 96 | |
| 97 | ```bash |
| 98 | go test ./testing/e2e/discord/ -v |
| 99 | ``` |
| 100 | |
| 101 | Run specific test files: |
| 102 | |
| 103 | ```bash |
| 104 | # Test basic functionality |
| 105 | go test ./testing/e2e/discord/ -v -args -ginkgo.focus="basic" |
| 106 | |
| 107 | # Test embed features |
| 108 | go test ./testing/e2e/discord/ -v -args -ginkgo.focus="embed" |
| 109 | |
| 110 | # Test file attachments |
| 111 | go test ./testing/e2e/discord/ -v -args -ginkgo.focus="file" |
| 112 | ``` |
| 113 | |
| 114 | ### Test Behavior |
| 115 | |
| 116 | - Tests will skip if required environment variables are missing |
| 117 | - Tests include delays between executions to respect Discord's rate limits |
| 118 | - Thread tests may skip if thread permissions prevent posting |
| 119 | - All tests send actual messages to your Discord channel - monitor your channel during test runs |
| 120 | |
| 121 | ### Expected Output |
| 122 | |
| 123 | Successful test run will show messages appearing in your Discord channel. Each test includes an "E2E Test:" prefix to identify test messages. |
| 124 | |
| 125 | ## Test Structure |
| 126 | |
| 127 | ```bash |
| 128 | testing/e2e/discord/ |
| 129 | ├── .env # Environment variables (not committed) |
| 130 | ├── suite_test.go # Test suite setup and configuration |
| 131 | ├── basic_test.go # Basic text message functionality |
| 132 | ├── complex_combination_test.go # Complex embeds with all features |
| 133 | ├── embed_author_test.go # Embed author information |
| 134 | ├── embed_colors_test.go # Color customization |
| 135 | ├── embed_fields_test.go # Custom fields |
| 136 | ├── embed_images_test.go # Images and thumbnails |
| 137 | ├── embed_timestamp_test.go # Timestamp handling |
| 138 | ├── file_attachment_test.go # Single file attachments |
| 139 | ├── json_mode_test.go # JSON mode functionality |
| 140 | ├── long_message_test.go # Long message handling |
| 141 | ├── multiple_embeds_test.go # Multiple embeds |
| 142 | ├── multiple_files_test.go # Multiple file attachments |
| 143 | ├── special_characters_test.go # Special character handling |
| 144 | ├── thread_test.go # Thread functionality |
| 145 | └── username_avatar_test.go # Username/avatar customization |
| 146 | ``` |
| 147 | |
| 148 | ### Test Organization |
| 149 | |
| 150 | Each test file focuses on a specific feature category: |
| 151 | |
| 152 | - **Basic Tests** (`basic_test.go`): Core message sending functionality |
| 153 | - **Embed Tests** (`embed_*_test.go`): Rich embed features and formatting |
| 154 | - **File Tests** (`file_*_test.go`): File attachment handling |
| 155 | - **Thread Tests** (`thread_test.go`): Posting messages to existing threads |
| 156 | - **Configuration Tests** (`username_avatar_test.go`, `json_mode_test.go`): Service configuration options |
| 157 | - **Edge Case Tests** (`long_message_test.go`, `special_characters_test.go`): Boundary conditions |