mirror of
https://github.com/bitwarden/server.git
synced 2024-12-04 14:13:28 +01:00
de294b8299
* [AC-2154] Logging organization data before migrating for flexible collections * [AC-2154] Refactored logging command to perform the data migration * [AC-2154] Moved validation inside the command * [AC-2154] PR feedback * [AC-2154] Changed logging level to warning * [AC-2154] Fixed unit test * [AC-2154] Removed logging unnecessary data * [AC-2154] Removed primary constructor * [AC-2154] Added comments
47 lines
1.8 KiB
C#
47 lines
1.8 KiB
C#
using Bit.Core.AdminConsole.Entities;
|
|
using Bit.Core.AdminConsole.OrganizationFeatures.OrganizationCollectionEnhancements;
|
|
using Bit.Core.Exceptions;
|
|
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.OrganizationCollectionEnhancements;
|
|
|
|
[SutProviderCustomize]
|
|
public class OrganizationEnableCollectionEnhancementsCommandTests
|
|
{
|
|
[Theory]
|
|
[BitAutoData]
|
|
public async Task EnableCollectionEnhancements_Success(
|
|
SutProvider<OrganizationEnableCollectionEnhancementsCommand> sutProvider,
|
|
Organization organization)
|
|
{
|
|
organization.FlexibleCollections = false;
|
|
|
|
await sutProvider.Sut.EnableCollectionEnhancements(organization);
|
|
|
|
await sutProvider.GetDependency<IOrganizationRepository>().Received(1).EnableCollectionEnhancements(organization.Id);
|
|
await sutProvider.GetDependency<IOrganizationService>().Received(1).ReplaceAndUpdateCacheAsync(
|
|
Arg.Is<Organization>(o =>
|
|
o.Id == organization.Id &&
|
|
o.FlexibleCollections));
|
|
}
|
|
|
|
[Theory]
|
|
[BitAutoData]
|
|
public async Task EnableCollectionEnhancements_WhenAlreadyMigrated_Throws(
|
|
SutProvider<OrganizationEnableCollectionEnhancementsCommand> sutProvider,
|
|
Organization organization)
|
|
{
|
|
organization.FlexibleCollections = true;
|
|
|
|
var exception = await Assert.ThrowsAsync<BadRequestException>(async () => await sutProvider.Sut.EnableCollectionEnhancements(organization));
|
|
Assert.Contains("has already been migrated", exception.Message);
|
|
|
|
await sutProvider.GetDependency<IOrganizationRepository>().DidNotReceiveWithAnyArgs().EnableCollectionEnhancements(Arg.Any<Guid>());
|
|
}
|
|
}
|