Skip to content

Commit 9173a48

Browse files
committed
Fixed integration test issue
1 parent d04cacf commit 9173a48

1 file changed

Lines changed: 34 additions & 1 deletion

File tree

tests/Smtp2Go.NET.IntegrationTests/Webhooks/WebhookDeliveryIntegrationTests.cs

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff 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>

0 commit comments

Comments
 (0)