diff --git a/test/Api.Test/Controllers/PoliciesControllerTests.cs b/test/Api.Test/Controllers/PoliciesControllerTests.cs index 1b96ace5d..8236074ee 100644 --- a/test/Api.Test/Controllers/PoliciesControllerTests.cs +++ b/test/Api.Test/Controllers/PoliciesControllerTests.cs @@ -201,4 +201,85 @@ public class PoliciesControllerTests await Assert.ThrowsAsync(() => sutProvider.Sut.Get(orgId, type)); } + [Theory] + [BitAutoData] + public async Task GetPolicyStatusAsync_UserUnauthorized_ThrowsUnauthorizedAccessException( + SutProvider sutProvider, Guid orgId, PolicyType type) + { + // Arrange + sutProvider.GetDependency() + .GetUserByPrincipalAsync(Arg.Any()) + .Returns(Task.FromResult(null)); + + // Act & Assert + await Assert.ThrowsAsync(() => sutProvider.Sut.GetPolicyStatusAsync(orgId, type)); + } + + [Theory] + [BitAutoData] + public async Task GetPolicyStatusAsync_PolicyNotFound_ReturnsFalse( + SutProvider sutProvider, Guid orgId, PolicyType type, User user) + { + // Arrange + sutProvider.GetDependency() + .GetUserByPrincipalAsync(Arg.Any()) + .Returns(user); + + sutProvider.GetDependency() + .GetByOrganizationIdTypeAsync(orgId, type) + .Returns(Task.FromResult(null)); + + // Act + var result = await sutProvider.Sut.GetPolicyStatusAsync(orgId, type); + + // Assert + Assert.False(result); + } + + [Theory] + [BitAutoData] + public async Task GetPolicyStatusAsync_PolicyDisabled_ReturnsFalse( + SutProvider sutProvider, Guid orgId, PolicyType type, User user, Policy policy) + { + // Arrange + policy.Enabled = false; + + sutProvider.GetDependency() + .GetUserByPrincipalAsync(Arg.Any()) + .Returns(user); + + sutProvider.GetDependency() + .GetByOrganizationIdTypeAsync(orgId, type) + .Returns(policy); + + // Act + var result = await sutProvider.Sut.GetPolicyStatusAsync(orgId, type); + + // Assert + Assert.False(result); + } + + [Theory] + [BitAutoData] + public async Task GetPolicyStatusAsync_PolicyEnabled_ReturnsTrue( + SutProvider sutProvider, Guid orgId, PolicyType type, User user, Policy policy) + { + // Arrange + policy.Enabled = true; + + sutProvider.GetDependency() + .GetUserByPrincipalAsync(Arg.Any()) + .Returns(user); + + sutProvider.GetDependency() + .GetByOrganizationIdTypeAsync(orgId, type) + .Returns(policy); + + // Act + var result = await sutProvider.Sut.GetPolicyStatusAsync(orgId, type); + + // Assert + Assert.True(result); + } + }