File tree Expand file tree Collapse file tree
tests/Smtp2Go.NET.IntegrationTests/Webhooks Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -290,7 +290,11 @@ private async Task<int> SetupWebhookPipelineAsync(
290290 } ;
291291 var webhookUrl = webhookUri . Uri . AbsoluteUri ;
292292
293- // Step 3: Register the webhook with SMTP2GO.
293+ // Step 3: Delete any stale webhooks from previous runs.
294+ // SMTP2GO free tier allows only 1 webhook — a stale webhook from a failed run blocks creation.
295+ await DeleteAllExistingWebhooksAsync ( ct ) ;
296+
297+ // Step 4: Register the webhook with SMTP2GO.
294298 var createRequest = new WebhookCreateRequest
295299 {
296300 WebhookUrl = webhookUrl ,
@@ -308,6 +312,35 @@ private async Task<int> SetupWebhookPipelineAsync(
308312 }
309313
310314
315+ /// <summary>
316+ /// Deletes all existing webhooks on the SMTP2GO account.
317+ /// SMTP2GO free tier limits accounts to 1 webhook — stale webhooks from
318+ /// previous failed runs block creation of new ones.
319+ /// </summary>
320+ private async Task DeleteAllExistingWebhooksAsync ( CancellationToken ct )
321+ {
322+ var listResponse = await _fixture . Client . Webhooks . ListAsync ( ct ) ;
323+
324+ if ( listResponse . Data is not { Length : > 0 } )
325+ return ;
326+
327+ foreach ( var webhook in listResponse . Data )
328+ {
329+ if ( webhook . WebhookId is { } id )
330+ {
331+ try
332+ {
333+ await _fixture . Client . Webhooks . DeleteAsync ( id , ct ) ;
334+ }
335+ catch
336+ {
337+ // Best-effort cleanup — continue with remaining webhooks.
338+ }
339+ }
340+ }
341+ }
342+
343+
311344 /// <summary>
312345 /// Best-effort webhook cleanup. Silently ignores errors to prevent masking test failures.
313346 /// </summary>
You can’t perform that action at this time.
0 commit comments