1
0
mirror of https://github.com/bitwarden/server.git synced 2025-06-30 15:42:48 -05:00

[PM-12491] Create Organization disable command (#5348)

* Add command interface and implementation for disabling organizations

* Register organization disable command for dependency injection

* Add unit tests for OrganizationDisableCommand

* Refactor subscription handlers to use IOrganizationDisableCommand for disabling organizations

* Remove DisableAsync method from IOrganizationService and its implementation in OrganizationService

* Remove IOrganizationService dependency from SubscriptionDeletedHandler

* Remove commented TODO for sending email to owners in OrganizationDisableCommand
This commit is contained in:
Rui Tomé
2025-02-25 14:57:30 +00:00
committed by GitHub
parent 0f10ca52b4
commit d15c1faa74
8 changed files with 141 additions and 22 deletions

View File

@ -0,0 +1,79 @@
using Bit.Core.AdminConsole.Entities;
using Bit.Core.AdminConsole.OrganizationFeatures.Organizations;
using Bit.Core.Repositories;
using Bit.Core.Services;
using Bit.Test.Common.AutoFixture;
using Bit.Test.Common.AutoFixture.Attributes;
using NSubstitute;
using Xunit;
namespace Bit.Core.Test.AdminConsole.OrganizationFeatures.Organizations;
[SutProviderCustomize]
public class OrganizationDisableCommandTests
{
[Theory, BitAutoData]
public async Task DisableAsync_WhenOrganizationEnabled_DisablesSuccessfully(
Organization organization,
DateTime expirationDate,
SutProvider<OrganizationDisableCommand> sutProvider)
{
organization.Enabled = true;
sutProvider.GetDependency<IOrganizationRepository>()
.GetByIdAsync(organization.Id)
.Returns(organization);
await sutProvider.Sut.DisableAsync(organization.Id, expirationDate);
Assert.False(organization.Enabled);
Assert.Equal(expirationDate, organization.ExpirationDate);
await sutProvider.GetDependency<IOrganizationRepository>()
.Received(1)
.ReplaceAsync(organization);
await sutProvider.GetDependency<IApplicationCacheService>()
.Received(1)
.UpsertOrganizationAbilityAsync(organization);
}
[Theory, BitAutoData]
public async Task DisableAsync_WhenOrganizationNotFound_DoesNothing(
Guid organizationId,
DateTime expirationDate,
SutProvider<OrganizationDisableCommand> sutProvider)
{
sutProvider.GetDependency<IOrganizationRepository>()
.GetByIdAsync(organizationId)
.Returns((Organization)null);
await sutProvider.Sut.DisableAsync(organizationId, expirationDate);
await sutProvider.GetDependency<IOrganizationRepository>()
.DidNotReceive()
.ReplaceAsync(Arg.Any<Organization>());
await sutProvider.GetDependency<IApplicationCacheService>()
.DidNotReceive()
.UpsertOrganizationAbilityAsync(Arg.Any<Organization>());
}
[Theory, BitAutoData]
public async Task DisableAsync_WhenOrganizationAlreadyDisabled_DoesNothing(
Organization organization,
DateTime expirationDate,
SutProvider<OrganizationDisableCommand> sutProvider)
{
organization.Enabled = false;
sutProvider.GetDependency<IOrganizationRepository>()
.GetByIdAsync(organization.Id)
.Returns(organization);
await sutProvider.Sut.DisableAsync(organization.Id, expirationDate);
await sutProvider.GetDependency<IOrganizationRepository>()
.DidNotReceive()
.ReplaceAsync(Arg.Any<Organization>());
await sutProvider.GetDependency<IApplicationCacheService>()
.DidNotReceive()
.UpsertOrganizationAbilityAsync(Arg.Any<Organization>());
}
}