62 lines
1.4 KiB
C#
62 lines
1.4 KiB
C#
using Heimdall.Domain.Entities;
|
|||
|
|
using Shouldly;
|
||
|
|
|
||
|
|
namespace Heimdall.Domain.Tests.Entities;
|
||
|
|
|
||
|
|
public class ApiKeyTests
|
||
|
|
{
|
||
|
|
[Fact]
|
||
|
|
public void Create_apikey_should_set_properties()
|
||
|
|
{
|
||
|
|
var siteId = Guid.NewGuid();
|
||
|
|
var userId = Guid.NewGuid();
|
||
|
|
var key = new ApiKey("hash123", "abc12345", siteId, userId);
|
||
|
|
|
||
|
|
key.KeyHash.ShouldBe("hash123");
|
||
|
|
key.KeyPrefix.ShouldBe("abc12345");
|
||
|
|
key.SiteId.ShouldBe(siteId);
|
||
|
|
key.CreatedByUserId.ShouldBe(userId);
|
||
|
|
key.Enabled.ShouldBeTrue();
|
||
|
|
}
|
||
|
|
|
||
|
|
[Fact]
|
||
|
|
public void Create_apikey_without_optional_params()
|
||
|
|
{
|
||
|
|
var key = new ApiKey("hash456", "def56789");
|
||
|
|
|
||
|
|
key.SiteId.ShouldBeNull();
|
||
|
|
key.CreatedByUserId.ShouldBeNull();
|
||
|
|
}
|
||
|
|
|
||
|
|
[Fact]
|
||
|
|
public void MarkUsed_should_set_last_used_at()
|
||
|
|
{
|
||
|
|
var key = new ApiKey("hash", "prefix");
|
||
|
|
key.LastUsedAt.ShouldBeNull();
|
||
|
|
|
||
|
|
key.MarkUsed();
|
||
|
|
|
||
|
|
key.LastUsedAt.ShouldNotBeNull();
|
||
|
|
}
|
||
|
|
|
||
|
|
[Fact]
|
||
|
|
public void Disable_should_set_enabled_false()
|
||
|
|
{
|
||
|
|
var key = new ApiKey("hash", "prefix");
|
||
|
|
|
||
|
|
key.Disable();
|
||
|
|
|
||
|
|
key.Enabled.ShouldBeFalse();
|
||
|
|
}
|
||
|
|
|
||
|
|
[Fact]
|
||
|
|
public void SetExpiry_should_update_expiry()
|
||
|
|
{
|
||
|
|
var key = new ApiKey("hash", "prefix");
|
||
|
|
var expiresAt = DateTime.UtcNow.AddDays(30);
|
||
|
|
|
||
|
|
key.SetExpiry(expiresAt);
|
||
|
|
|
||
|
|
key.ExpiresAt.ShouldBe(expiresAt);
|
||
|
|
}
|
||
|
|
}
|