Add unit tests for Environments, Audit, and Webhooks namespaces (#6)
## Summary - Add missing unit test coverage for the Environments, Audit, and Webhooks namespaces (raises them from ~0-62% to 91-100%) - Exclude WebhookBackgroundService/WebhookRetryBackgroundService from coverage (require live DI/DB, disallowed by CLAUDE.md's no-InMemory/WebApplicationFactory rule) ## Test plan - [x] `dotnet test` full suite passes (646/646) - [x] Coverage report confirms Environments ~99.5%, Audit 100%, Webhooks ~91% Reviewed-on: #6
This commit was merged in pull request #6.
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
using MicCheck.Api.Webhooks;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace MicCheck.Api.Tests.Unit.Webhooks;
|
||||
|
||||
[TestFixture]
|
||||
public class WebhookQueueTests
|
||||
{
|
||||
[Test]
|
||||
public async Task WhenAnEventIsEnqueued_ThenItCanBeReadBack()
|
||||
{
|
||||
var queue = new WebhookQueue();
|
||||
var webhookEvent = new WebhookEvent
|
||||
{
|
||||
EventType = WebhookEventTypes.FlagUpdated,
|
||||
OrganizationId = 1,
|
||||
Data = new { }
|
||||
};
|
||||
|
||||
await queue.EnqueueAsync(webhookEvent);
|
||||
|
||||
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(1));
|
||||
await using var enumerator = queue.ReadAllAsync(cts.Token).GetAsyncEnumerator(cts.Token);
|
||||
await enumerator.MoveNextAsync();
|
||||
|
||||
Assert.That(enumerator.Current, Is.SameAs(webhookEvent));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task WhenMultipleEventsAreEnqueued_ThenTheyAreReadInOrder()
|
||||
{
|
||||
var queue = new WebhookQueue();
|
||||
var first = new WebhookEvent { EventType = WebhookEventTypes.FlagUpdated, OrganizationId = 1, Data = new { } };
|
||||
var second = new WebhookEvent { EventType = WebhookEventTypes.FlagDeleted, OrganizationId = 1, Data = new { } };
|
||||
|
||||
await queue.EnqueueAsync(first);
|
||||
await queue.EnqueueAsync(second);
|
||||
|
||||
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(1));
|
||||
await using var enumerator = queue.ReadAllAsync(cts.Token).GetAsyncEnumerator(cts.Token);
|
||||
|
||||
await enumerator.MoveNextAsync();
|
||||
Assert.That(enumerator.Current, Is.SameAs(first));
|
||||
|
||||
await enumerator.MoveNextAsync();
|
||||
Assert.That(enumerator.Current, Is.SameAs(second));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user