Files
Artemy 2d99c57a3b Expand server tests and enforce coverage
Consolidate server tests under tests/, upgrade them to .NET 10, and add CI coverage thresholds and reports. Expand API and application boundary coverage while fixing related issues in media handling, friend blocking, session crypto, presence, username validation, and local storage.
2026-10-24 15:30:32 +07:00

42 lines
1.7 KiB
C#

using Govor.Application.Authentication;
using Govor.Application.Infrastructure.Common;
using Microsoft.EntityFrameworkCore;
using Moq;
namespace Govor.Server.Tests;
[TestFixture]
public class InvitationClockTests
{
[TestCase(-1, false)]
[TestCase(0, false)]
[TestCase(1, true)]
public async Task ExpirationUsesInjectedClockIncludingExactBoundary(int offsetMinutes, bool expectedSuccess)
{
using var db = new TestDatabase();
var now = new DateTime(2026, 11, 1, 12, 0, 0, DateTimeKind.Utc);
var invitation = await db.Context.Invitations.SingleAsync(i => i.Code == "test");
invitation.EndDate = now.AddMinutes(offsetMinutes);
await db.Context.SaveChangesAsync();
var clock = new Mock<INowDateTimeProvider>();
clock.SetupGet(c => c.Now).Returns(now);
var service = new InvitesService(db.Context, clock.Object);
Assert.That((await service.ValidateAsync("test")).IsSuccess, Is.EqualTo(expectedSuccess));
clock.VerifyGet(c => c.Now, Times.Once);
}
[Test]
public async Task InactiveInvitationIsRejectedEvenWhenItExpiresInTheFuture()
{
using var db = new TestDatabase();
var now = new DateTime(2026, 11, 1, 12, 0, 0, DateTimeKind.Utc);
var invitation = await db.Context.Invitations.SingleAsync(i => i.Code == "test");
invitation.IsActive = false;
invitation.EndDate = now.AddDays(1);
await db.Context.SaveChangesAsync();
var clock = new Mock<INowDateTimeProvider>();
clock.SetupGet(c => c.Now).Returns(now);
Assert.That((await new InvitesService(db.Context, clock.Object).ValidateAsync("test")).IsFailure, Is.True);
}
}