mirror of
https://github.com/bitwarden/server.git
synced 2026-01-31 14:13:18 +08:00
[PM-29246] Simplify Usage of Organization Policies (#6837)
* Initial implementation of new policy query * Remove unused using * Adjusts method name to better match repository method * Correct namespace * Initial refactor of policy loading * Add xml doc, incorporate shim data model * Updates usages to reflect new shim model * Prune extranneous data from policy detail response model, format code * Fix broken test, delete inapplicable test * Adds test cases covering query * Adjust codebase to use new PolicyQueryçˆ * Format code * Fix incorrect mock on test * Fix formatting * Adjust method name * More naming adjustments * Add PolicyData constructor, update test usages * Rename PolicyData -> PolicyStatus * Remove unused using
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
using Bit.Core.AdminConsole.Entities;
|
||||
using Bit.Core.AdminConsole.Enums;
|
||||
using Bit.Core.AdminConsole.OrganizationFeatures.Policies.Implementations;
|
||||
using Bit.Core.AdminConsole.Repositories;
|
||||
using Bit.Test.Common.AutoFixture;
|
||||
using Bit.Test.Common.AutoFixture.Attributes;
|
||||
using NSubstitute;
|
||||
using NSubstitute.ReturnsExtensions;
|
||||
using Xunit;
|
||||
|
||||
namespace Bit.Core.Test.OrganizationFeatures.Policies;
|
||||
|
||||
[SutProviderCustomize]
|
||||
public class PolicyQueryTests
|
||||
{
|
||||
[Theory, BitAutoData]
|
||||
public async Task RunAsync_WithExistingPolicy_ReturnsPolicy(SutProvider<PolicyQuery> sutProvider,
|
||||
Policy policy)
|
||||
{
|
||||
// Arrange
|
||||
sutProvider.GetDependency<IPolicyRepository>()
|
||||
.GetByOrganizationIdTypeAsync(policy.OrganizationId, policy.Type)
|
||||
.Returns(policy);
|
||||
|
||||
// Act
|
||||
var policyData = await sutProvider.Sut.RunAsync(policy.OrganizationId, policy.Type);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(policy.Data, policyData.Data);
|
||||
Assert.Equal(policy.Type, policyData.Type);
|
||||
Assert.Equal(policy.Enabled, policyData.Enabled);
|
||||
Assert.Equal(policy.OrganizationId, policyData.OrganizationId);
|
||||
}
|
||||
|
||||
[Theory, BitAutoData]
|
||||
public async Task RunAsync_WithNonExistentPolicy_ReturnsDefaultDisabledPolicy(
|
||||
SutProvider<PolicyQuery> sutProvider,
|
||||
Guid organizationId,
|
||||
PolicyType policyType)
|
||||
{
|
||||
// Arrange
|
||||
sutProvider.GetDependency<IPolicyRepository>()
|
||||
.GetByOrganizationIdTypeAsync(organizationId, policyType)
|
||||
.ReturnsNull();
|
||||
|
||||
// Act
|
||||
var policyData = await sutProvider.Sut.RunAsync(organizationId, policyType);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(organizationId, policyData.OrganizationId);
|
||||
Assert.Equal(policyType, policyData.Type);
|
||||
Assert.False(policyData.Enabled);
|
||||
Assert.Null(policyData.Data);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user