mirror of
https://github.com/bitwarden/server.git
synced 2024-12-02 13:53:23 +01:00
Refactor unit tests to separate feature flag tests
This commit is contained in:
parent
45c23c0f18
commit
97ec648a44
@ -18,11 +18,8 @@ namespace Bit.Core.Test.AdminConsole.OrganizationFeatures.OrganizationUsers;
|
|||||||
[SutProviderCustomize]
|
[SutProviderCustomize]
|
||||||
public class RemoveOrganizationUserCommandTests
|
public class RemoveOrganizationUserCommandTests
|
||||||
{
|
{
|
||||||
[Theory]
|
[Theory, BitAutoData]
|
||||||
[BitAutoData(true)]
|
|
||||||
[BitAutoData(false)]
|
|
||||||
public async Task RemoveUser_WithDeletingUserId_Success(
|
public async Task RemoveUser_WithDeletingUserId_Success(
|
||||||
bool isAccountDeprovisioningEnabled,
|
|
||||||
[OrganizationUser(type: OrganizationUserType.User)] OrganizationUser organizationUser,
|
[OrganizationUser(type: OrganizationUserType.User)] OrganizationUser organizationUser,
|
||||||
[OrganizationUser(type: OrganizationUserType.Owner)] OrganizationUser deletingUser,
|
[OrganizationUser(type: OrganizationUserType.Owner)] OrganizationUser deletingUser,
|
||||||
SutProvider<RemoveOrganizationUserCommand> sutProvider)
|
SutProvider<RemoveOrganizationUserCommand> sutProvider)
|
||||||
@ -30,9 +27,6 @@ public class RemoveOrganizationUserCommandTests
|
|||||||
// Arrange
|
// Arrange
|
||||||
organizationUser.OrganizationId = deletingUser.OrganizationId;
|
organizationUser.OrganizationId = deletingUser.OrganizationId;
|
||||||
|
|
||||||
sutProvider.GetDependency<IFeatureService>()
|
|
||||||
.IsEnabled(FeatureFlagKeys.AccountDeprovisioning)
|
|
||||||
.Returns(isAccountDeprovisioningEnabled);
|
|
||||||
sutProvider.GetDependency<IOrganizationUserRepository>()
|
sutProvider.GetDependency<IOrganizationUserRepository>()
|
||||||
.GetByIdAsync(organizationUser.Id)
|
.GetByIdAsync(organizationUser.Id)
|
||||||
.Returns(organizationUser);
|
.Returns(organizationUser);
|
||||||
@ -47,31 +41,57 @@ public class RemoveOrganizationUserCommandTests
|
|||||||
await sutProvider.Sut.RemoveUserAsync(deletingUser.OrganizationId, organizationUser.Id, deletingUser.UserId);
|
await sutProvider.Sut.RemoveUserAsync(deletingUser.OrganizationId, organizationUser.Id, deletingUser.UserId);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
|
await sutProvider.GetDependency<IGetOrganizationUsersManagementStatusQuery>()
|
||||||
|
.DidNotReceiveWithAnyArgs()
|
||||||
|
.GetUsersOrganizationManagementStatusAsync(default, default);
|
||||||
await sutProvider.GetDependency<IOrganizationUserRepository>()
|
await sutProvider.GetDependency<IOrganizationUserRepository>()
|
||||||
.Received(1)
|
.Received(1)
|
||||||
.DeleteAsync(organizationUser);
|
.DeleteAsync(organizationUser);
|
||||||
await sutProvider.GetDependency<IEventService>()
|
await sutProvider.GetDependency<IEventService>()
|
||||||
.Received(1)
|
.Received(1)
|
||||||
.LogOrganizationUserEventAsync(organizationUser, EventType.OrganizationUser_Removed);
|
.LogOrganizationUserEventAsync(organizationUser, EventType.OrganizationUser_Removed);
|
||||||
|
}
|
||||||
|
|
||||||
if (isAccountDeprovisioningEnabled)
|
[Theory, BitAutoData]
|
||||||
|
public async Task RemoveUser_WithDeletingUserId_WithAccountDeprovisioningEnabled_Success(
|
||||||
|
[OrganizationUser(type: OrganizationUserType.User)] OrganizationUser organizationUser,
|
||||||
|
[OrganizationUser(type: OrganizationUserType.Owner)] OrganizationUser deletingUser,
|
||||||
|
SutProvider<RemoveOrganizationUserCommand> sutProvider)
|
||||||
{
|
{
|
||||||
|
// Arrange
|
||||||
|
organizationUser.OrganizationId = deletingUser.OrganizationId;
|
||||||
|
|
||||||
|
sutProvider.GetDependency<IFeatureService>()
|
||||||
|
.IsEnabled(FeatureFlagKeys.AccountDeprovisioning)
|
||||||
|
.Returns(true);
|
||||||
|
sutProvider.GetDependency<IOrganizationUserRepository>()
|
||||||
|
.GetByIdAsync(organizationUser.Id)
|
||||||
|
.Returns(organizationUser);
|
||||||
|
sutProvider.GetDependency<IOrganizationUserRepository>()
|
||||||
|
.GetByIdAsync(deletingUser.Id)
|
||||||
|
.Returns(deletingUser);
|
||||||
|
sutProvider.GetDependency<ICurrentContext>()
|
||||||
|
.OrganizationOwner(deletingUser.OrganizationId)
|
||||||
|
.Returns(true);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
await sutProvider.Sut.RemoveUserAsync(deletingUser.OrganizationId, organizationUser.Id, deletingUser.UserId);
|
||||||
|
|
||||||
|
// Assert
|
||||||
await sutProvider.GetDependency<IGetOrganizationUsersManagementStatusQuery>()
|
await sutProvider.GetDependency<IGetOrganizationUsersManagementStatusQuery>()
|
||||||
.Received(1)
|
.Received(1)
|
||||||
.GetUsersOrganizationManagementStatusAsync(
|
.GetUsersOrganizationManagementStatusAsync(
|
||||||
organizationUser.OrganizationId,
|
organizationUser.OrganizationId,
|
||||||
Arg.Is<IEnumerable<Guid>>(i => i.Contains(organizationUser.Id)));
|
Arg.Is<IEnumerable<Guid>>(i => i.Contains(organizationUser.Id)));
|
||||||
}
|
await sutProvider.GetDependency<IOrganizationUserRepository>()
|
||||||
else
|
.Received(1)
|
||||||
{
|
.DeleteAsync(organizationUser);
|
||||||
await sutProvider.GetDependency<IGetOrganizationUsersManagementStatusQuery>()
|
await sutProvider.GetDependency<IEventService>()
|
||||||
.DidNotReceiveWithAnyArgs()
|
.Received(1)
|
||||||
.GetUsersOrganizationManagementStatusAsync(default, default);
|
.LogOrganizationUserEventAsync(organizationUser, EventType.OrganizationUser_Removed);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory, BitAutoData]
|
||||||
[BitAutoData]
|
|
||||||
public async Task RemoveUser_WithDeletingUserId_NotFound_ThrowsException(
|
public async Task RemoveUser_WithDeletingUserId_NotFound_ThrowsException(
|
||||||
SutProvider<RemoveOrganizationUserCommand> sutProvider,
|
SutProvider<RemoveOrganizationUserCommand> sutProvider,
|
||||||
Guid organizationId, Guid organizationUserId)
|
Guid organizationId, Guid organizationUserId)
|
||||||
@ -81,8 +101,7 @@ public class RemoveOrganizationUserCommandTests
|
|||||||
await sutProvider.Sut.RemoveUserAsync(organizationId, organizationUserId, null));
|
await sutProvider.Sut.RemoveUserAsync(organizationId, organizationUserId, null));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory, BitAutoData]
|
||||||
[BitAutoData]
|
|
||||||
public async Task RemoveUser_WithDeletingUserId_MismatchingOrganizationId_ThrowsException(
|
public async Task RemoveUser_WithDeletingUserId_MismatchingOrganizationId_ThrowsException(
|
||||||
SutProvider<RemoveOrganizationUserCommand> sutProvider, Guid organizationId, Guid organizationUserId)
|
SutProvider<RemoveOrganizationUserCommand> sutProvider, Guid organizationId, Guid organizationUserId)
|
||||||
{
|
{
|
||||||
@ -211,19 +230,12 @@ public class RemoveOrganizationUserCommandTests
|
|||||||
.GetUsersOrganizationManagementStatusAsync(orgUser.OrganizationId, Arg.Is<IEnumerable<Guid>>(i => i.Contains(orgUser.Id)));
|
.GetUsersOrganizationManagementStatusAsync(orgUser.OrganizationId, Arg.Is<IEnumerable<Guid>>(i => i.Contains(orgUser.Id)));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory, BitAutoData]
|
||||||
[BitAutoData(true)]
|
public async Task RemoveUser_WithEventSystemUser_Success(
|
||||||
[BitAutoData(false)]
|
|
||||||
public async Task RemoveUser_WithEventSystemUser_Success(bool isAccountDeprovisioningEnabled,
|
|
||||||
[OrganizationUser(type: OrganizationUserType.User)] OrganizationUser organizationUser,
|
[OrganizationUser(type: OrganizationUserType.User)] OrganizationUser organizationUser,
|
||||||
EventSystemUser eventSystemUser,
|
EventSystemUser eventSystemUser, SutProvider<RemoveOrganizationUserCommand> sutProvider)
|
||||||
SutProvider<RemoveOrganizationUserCommand> sutProvider)
|
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
sutProvider.GetDependency<IFeatureService>()
|
|
||||||
.IsEnabled(FeatureFlagKeys.AccountDeprovisioning)
|
|
||||||
.Returns(isAccountDeprovisioningEnabled);
|
|
||||||
|
|
||||||
sutProvider.GetDependency<IOrganizationUserRepository>()
|
sutProvider.GetDependency<IOrganizationUserRepository>()
|
||||||
.GetByIdAsync(organizationUser.Id)
|
.GetByIdAsync(organizationUser.Id)
|
||||||
.Returns(organizationUser);
|
.Returns(organizationUser);
|
||||||
@ -232,15 +244,43 @@ public class RemoveOrganizationUserCommandTests
|
|||||||
await sutProvider.Sut.RemoveUserAsync(organizationUser.OrganizationId, organizationUser.Id, eventSystemUser);
|
await sutProvider.Sut.RemoveUserAsync(organizationUser.OrganizationId, organizationUser.Id, eventSystemUser);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
|
await sutProvider.GetDependency<IGetOrganizationUsersManagementStatusQuery>()
|
||||||
|
.DidNotReceiveWithAnyArgs()
|
||||||
|
.GetUsersOrganizationManagementStatusAsync(default, default);
|
||||||
await sutProvider.GetDependency<IOrganizationUserRepository>()
|
await sutProvider.GetDependency<IOrganizationUserRepository>()
|
||||||
.Received(1)
|
.Received(1)
|
||||||
.DeleteAsync(organizationUser);
|
.DeleteAsync(organizationUser);
|
||||||
await sutProvider.GetDependency<IEventService>()
|
await sutProvider.GetDependency<IEventService>()
|
||||||
.Received(1)
|
.Received(1)
|
||||||
.LogOrganizationUserEventAsync(organizationUser, EventType.OrganizationUser_Removed, eventSystemUser);
|
.LogOrganizationUserEventAsync(organizationUser, EventType.OrganizationUser_Removed, eventSystemUser);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory, BitAutoData]
|
||||||
|
public async Task RemoveUser_WithEventSystemUser_WithAccountDeprovisioningEnabled_Success(
|
||||||
|
[OrganizationUser(type: OrganizationUserType.User)] OrganizationUser organizationUser,
|
||||||
|
EventSystemUser eventSystemUser, SutProvider<RemoveOrganizationUserCommand> sutProvider)
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
sutProvider.GetDependency<IFeatureService>()
|
||||||
|
.IsEnabled(FeatureFlagKeys.AccountDeprovisioning)
|
||||||
|
.Returns(true);
|
||||||
|
sutProvider.GetDependency<IOrganizationUserRepository>()
|
||||||
|
.GetByIdAsync(organizationUser.Id)
|
||||||
|
.Returns(organizationUser);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
await sutProvider.Sut.RemoveUserAsync(organizationUser.OrganizationId, organizationUser.Id, eventSystemUser);
|
||||||
|
|
||||||
|
// Assert
|
||||||
await sutProvider.GetDependency<IGetOrganizationUsersManagementStatusQuery>()
|
await sutProvider.GetDependency<IGetOrganizationUsersManagementStatusQuery>()
|
||||||
.DidNotReceiveWithAnyArgs()
|
.DidNotReceiveWithAnyArgs()
|
||||||
.GetUsersOrganizationManagementStatusAsync(default, default);
|
.GetUsersOrganizationManagementStatusAsync(default, default);
|
||||||
|
await sutProvider.GetDependency<IOrganizationUserRepository>()
|
||||||
|
.Received(1)
|
||||||
|
.DeleteAsync(organizationUser);
|
||||||
|
await sutProvider.GetDependency<IEventService>()
|
||||||
|
.Received(1)
|
||||||
|
.LogOrganizationUserEventAsync(organizationUser, EventType.OrganizationUser_Removed, eventSystemUser);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
@ -375,11 +415,8 @@ public class RemoveOrganizationUserCommandTests
|
|||||||
Arg.Any<bool>());
|
Arg.Any<bool>());
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory, BitAutoData]
|
||||||
[BitAutoData(true)]
|
|
||||||
[BitAutoData(false)]
|
|
||||||
public async Task RemoveUsers_WithDeletingUserId_Success(
|
public async Task RemoveUsers_WithDeletingUserId_Success(
|
||||||
bool isAccountDeprovisioningEnabled,
|
|
||||||
[OrganizationUser(OrganizationUserStatusType.Confirmed, OrganizationUserType.Owner)] OrganizationUser deletingUser,
|
[OrganizationUser(OrganizationUserStatusType.Confirmed, OrganizationUserType.Owner)] OrganizationUser deletingUser,
|
||||||
[OrganizationUser(type: OrganizationUserType.Owner)] OrganizationUser orgUser1, OrganizationUser orgUser2)
|
[OrganizationUser(type: OrganizationUserType.Owner)] OrganizationUser orgUser1, OrganizationUser orgUser2)
|
||||||
{
|
{
|
||||||
@ -390,9 +427,6 @@ public class RemoveOrganizationUserCommandTests
|
|||||||
var organizationUsers = new[] { orgUser1, orgUser2 };
|
var organizationUsers = new[] { orgUser1, orgUser2 };
|
||||||
var organizationUserIds = organizationUsers.Select(u => u.Id);
|
var organizationUserIds = organizationUsers.Select(u => u.Id);
|
||||||
|
|
||||||
sutProvider.GetDependency<IFeatureService>()
|
|
||||||
.IsEnabled(FeatureFlagKeys.AccountDeprovisioning)
|
|
||||||
.Returns(isAccountDeprovisioningEnabled);
|
|
||||||
sutProvider.GetDependency<IOrganizationUserRepository>()
|
sutProvider.GetDependency<IOrganizationUserRepository>()
|
||||||
.GetManyAsync(default)
|
.GetManyAsync(default)
|
||||||
.ReturnsForAnyArgs(organizationUsers);
|
.ReturnsForAnyArgs(organizationUsers);
|
||||||
@ -417,6 +451,9 @@ public class RemoveOrganizationUserCommandTests
|
|||||||
// Assert
|
// Assert
|
||||||
Assert.Equal(2, result.Count());
|
Assert.Equal(2, result.Count());
|
||||||
Assert.All(result, r => Assert.Empty(r.ErrorMessage));
|
Assert.All(result, r => Assert.Empty(r.ErrorMessage));
|
||||||
|
await sutProvider.GetDependency<IGetOrganizationUsersManagementStatusQuery>()
|
||||||
|
.DidNotReceiveWithAnyArgs()
|
||||||
|
.GetUsersOrganizationManagementStatusAsync(default, default);
|
||||||
await sutProvider.GetDependency<IOrganizationUserRepository>()
|
await sutProvider.GetDependency<IOrganizationUserRepository>()
|
||||||
.Received(1)
|
.Received(1)
|
||||||
.DeleteManyAsync(Arg.Is<IEnumerable<Guid>>(i => i.Contains(orgUser1.Id) && i.Contains(orgUser2.Id)));
|
.DeleteManyAsync(Arg.Is<IEnumerable<Guid>>(i => i.Contains(orgUser1.Id) && i.Contains(orgUser2.Id)));
|
||||||
@ -427,20 +464,62 @@ public class RemoveOrganizationUserCommandTests
|
|||||||
i.First().OrganizationUser.Id == orgUser1.Id
|
i.First().OrganizationUser.Id == orgUser1.Id
|
||||||
&& i.Last().OrganizationUser.Id == orgUser2.Id
|
&& i.Last().OrganizationUser.Id == orgUser2.Id
|
||||||
&& i.All(u => u.DateTime == eventDate)));
|
&& i.All(u => u.DateTime == eventDate)));
|
||||||
if (isAccountDeprovisioningEnabled)
|
}
|
||||||
|
|
||||||
|
[Theory, BitAutoData]
|
||||||
|
public async Task RemoveUsers_WithDeletingUserId_WithAccountDeprovisioningEnabled_Success(
|
||||||
|
[OrganizationUser(OrganizationUserStatusType.Confirmed, OrganizationUserType.Owner)] OrganizationUser deletingUser,
|
||||||
|
[OrganizationUser(type: OrganizationUserType.Owner)] OrganizationUser orgUser1, OrganizationUser orgUser2)
|
||||||
{
|
{
|
||||||
|
// Arrange
|
||||||
|
var sutProvider = SutProviderFactory();
|
||||||
|
var eventDate = sutProvider.GetDependency<FakeTimeProvider>().GetUtcNow().UtcDateTime;
|
||||||
|
orgUser1.OrganizationId = orgUser2.OrganizationId = deletingUser.OrganizationId;
|
||||||
|
var organizationUsers = new[] { orgUser1, orgUser2 };
|
||||||
|
var organizationUserIds = organizationUsers.Select(u => u.Id);
|
||||||
|
|
||||||
|
sutProvider.GetDependency<IFeatureService>()
|
||||||
|
.IsEnabled(FeatureFlagKeys.AccountDeprovisioning)
|
||||||
|
.Returns(true);
|
||||||
|
sutProvider.GetDependency<IOrganizationUserRepository>()
|
||||||
|
.GetManyAsync(default)
|
||||||
|
.ReturnsForAnyArgs(organizationUsers);
|
||||||
|
sutProvider.GetDependency<IOrganizationUserRepository>()
|
||||||
|
.GetByIdAsync(deletingUser.Id)
|
||||||
|
.Returns(deletingUser);
|
||||||
|
sutProvider.GetDependency<IHasConfirmedOwnersExceptQuery>()
|
||||||
|
.HasConfirmedOwnersExceptAsync(deletingUser.OrganizationId, Arg.Any<IEnumerable<Guid>>())
|
||||||
|
.Returns(true);
|
||||||
|
sutProvider.GetDependency<ICurrentContext>()
|
||||||
|
.OrganizationOwner(deletingUser.OrganizationId)
|
||||||
|
.Returns(true);
|
||||||
|
sutProvider.GetDependency<IGetOrganizationUsersManagementStatusQuery>()
|
||||||
|
.GetUsersOrganizationManagementStatusAsync(
|
||||||
|
deletingUser.OrganizationId,
|
||||||
|
Arg.Is<IEnumerable<Guid>>(i => i.Contains(orgUser1.Id) && i.Contains(orgUser2.Id)))
|
||||||
|
.Returns(new Dictionary<Guid, bool> { { orgUser1.Id, false }, { orgUser2.Id, false } });
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await sutProvider.Sut.RemoveUsersAsync(deletingUser.OrganizationId, organizationUserIds, deletingUser.UserId);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.Equal(2, result.Count());
|
||||||
|
Assert.All(result, r => Assert.Empty(r.ErrorMessage));
|
||||||
await sutProvider.GetDependency<IGetOrganizationUsersManagementStatusQuery>()
|
await sutProvider.GetDependency<IGetOrganizationUsersManagementStatusQuery>()
|
||||||
.Received(1)
|
.Received(1)
|
||||||
.GetUsersOrganizationManagementStatusAsync(
|
.GetUsersOrganizationManagementStatusAsync(
|
||||||
deletingUser.OrganizationId,
|
deletingUser.OrganizationId,
|
||||||
Arg.Is<IEnumerable<Guid>>(i => i.Contains(orgUser1.Id) && i.Contains(orgUser2.Id)));
|
Arg.Is<IEnumerable<Guid>>(i => i.Contains(orgUser1.Id) && i.Contains(orgUser2.Id)));
|
||||||
}
|
await sutProvider.GetDependency<IOrganizationUserRepository>()
|
||||||
else
|
.Received(1)
|
||||||
{
|
.DeleteManyAsync(Arg.Is<IEnumerable<Guid>>(i => i.Contains(orgUser1.Id) && i.Contains(orgUser2.Id)));
|
||||||
await sutProvider.GetDependency<IGetOrganizationUsersManagementStatusQuery>()
|
await sutProvider.GetDependency<IEventService>()
|
||||||
.DidNotReceiveWithAnyArgs()
|
.Received(1)
|
||||||
.GetUsersOrganizationManagementStatusAsync(default, default);
|
.LogOrganizationUserEventsAsync(
|
||||||
}
|
Arg.Is<IEnumerable<(OrganizationUser OrganizationUser, EventType EventType, DateTime? DateTime)>>(i =>
|
||||||
|
i.First().OrganizationUser.Id == orgUser1.Id
|
||||||
|
&& i.Last().OrganizationUser.Id == orgUser2.Id
|
||||||
|
&& i.All(u => u.DateTime == eventDate)));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory, BitAutoData]
|
[Theory, BitAutoData]
|
||||||
@ -567,11 +646,8 @@ public class RemoveOrganizationUserCommandTests
|
|||||||
Assert.Contains(RemoveOrganizationUserCommand.RemoveLastConfirmedOwnerErrorMessage, exception.Message);
|
Assert.Contains(RemoveOrganizationUserCommand.RemoveLastConfirmedOwnerErrorMessage, exception.Message);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory, BitAutoData]
|
||||||
[BitAutoData(true)]
|
|
||||||
[BitAutoData(false)]
|
|
||||||
public async Task RemoveUsers_WithEventSystemUser_Success(
|
public async Task RemoveUsers_WithEventSystemUser_Success(
|
||||||
bool isAccountDeprovisioningEnabled,
|
|
||||||
EventSystemUser eventSystemUser,
|
EventSystemUser eventSystemUser,
|
||||||
[OrganizationUser(type: OrganizationUserType.Owner)] OrganizationUser orgUser1,
|
[OrganizationUser(type: OrganizationUserType.Owner)] OrganizationUser orgUser1,
|
||||||
OrganizationUser orgUser2)
|
OrganizationUser orgUser2)
|
||||||
@ -583,9 +659,6 @@ public class RemoveOrganizationUserCommandTests
|
|||||||
var organizationUsers = new[] { orgUser1, orgUser2 };
|
var organizationUsers = new[] { orgUser1, orgUser2 };
|
||||||
var organizationUserIds = organizationUsers.Select(u => u.Id);
|
var organizationUserIds = organizationUsers.Select(u => u.Id);
|
||||||
|
|
||||||
sutProvider.GetDependency<IFeatureService>()
|
|
||||||
.IsEnabled(FeatureFlagKeys.AccountDeprovisioning)
|
|
||||||
.Returns(isAccountDeprovisioningEnabled);
|
|
||||||
sutProvider.GetDependency<IOrganizationUserRepository>()
|
sutProvider.GetDependency<IOrganizationUserRepository>()
|
||||||
.GetManyAsync(default)
|
.GetManyAsync(default)
|
||||||
.ReturnsForAnyArgs(organizationUsers);
|
.ReturnsForAnyArgs(organizationUsers);
|
||||||
@ -599,6 +672,9 @@ public class RemoveOrganizationUserCommandTests
|
|||||||
// Assert
|
// Assert
|
||||||
Assert.Equal(2, result.Count());
|
Assert.Equal(2, result.Count());
|
||||||
Assert.All(result, r => Assert.Empty(r.ErrorMessage));
|
Assert.All(result, r => Assert.Empty(r.ErrorMessage));
|
||||||
|
await sutProvider.GetDependency<IGetOrganizationUsersManagementStatusQuery>()
|
||||||
|
.DidNotReceiveWithAnyArgs()
|
||||||
|
.GetUsersOrganizationManagementStatusAsync(default, default);
|
||||||
await sutProvider.GetDependency<IOrganizationUserRepository>()
|
await sutProvider.GetDependency<IOrganizationUserRepository>()
|
||||||
.Received(1)
|
.Received(1)
|
||||||
.DeleteManyAsync(Arg.Is<IEnumerable<Guid>>(i => i.Contains(orgUser1.Id) && i.Contains(orgUser2.Id)));
|
.DeleteManyAsync(Arg.Is<IEnumerable<Guid>>(i => i.Contains(orgUser1.Id) && i.Contains(orgUser2.Id)));
|
||||||
@ -606,15 +682,55 @@ public class RemoveOrganizationUserCommandTests
|
|||||||
.Received(1)
|
.Received(1)
|
||||||
.LogOrganizationUserEventsAsync(
|
.LogOrganizationUserEventsAsync(
|
||||||
Arg.Is<IEnumerable<(OrganizationUser OrganizationUser, EventType EventType, EventSystemUser EventSystemUser, DateTime? DateTime)>>(
|
Arg.Is<IEnumerable<(OrganizationUser OrganizationUser, EventType EventType, EventSystemUser EventSystemUser, DateTime? DateTime)>>(
|
||||||
i =>
|
i => i.First().OrganizationUser.Id == orgUser1.Id
|
||||||
i.First().OrganizationUser.Id == orgUser1.Id
|
|
||||||
&& i.Last().OrganizationUser.Id == orgUser2.Id
|
&& i.Last().OrganizationUser.Id == orgUser2.Id
|
||||||
&& i.All(u =>
|
&& i.All(u => u.EventSystemUser == eventSystemUser
|
||||||
u.EventSystemUser == eventSystemUser
|
|
||||||
&& u.DateTime == eventDate)));
|
&& u.DateTime == eventDate)));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory, BitAutoData]
|
||||||
|
public async Task RemoveUsers_WithEventSystemUser_WithAccountDeprovisioningEnabled_Success(
|
||||||
|
EventSystemUser eventSystemUser,
|
||||||
|
[OrganizationUser(type: OrganizationUserType.Owner)] OrganizationUser orgUser1,
|
||||||
|
OrganizationUser orgUser2)
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var sutProvider = SutProviderFactory();
|
||||||
|
var eventDate = sutProvider.GetDependency<FakeTimeProvider>().GetUtcNow().UtcDateTime;
|
||||||
|
orgUser1.OrganizationId = orgUser2.OrganizationId;
|
||||||
|
var organizationUsers = new[] { orgUser1, orgUser2 };
|
||||||
|
var organizationUserIds = organizationUsers.Select(u => u.Id);
|
||||||
|
|
||||||
|
sutProvider.GetDependency<IFeatureService>()
|
||||||
|
.IsEnabled(FeatureFlagKeys.AccountDeprovisioning)
|
||||||
|
.Returns(true);
|
||||||
|
sutProvider.GetDependency<IOrganizationUserRepository>()
|
||||||
|
.GetManyAsync(default)
|
||||||
|
.ReturnsForAnyArgs(organizationUsers);
|
||||||
|
sutProvider.GetDependency<IHasConfirmedOwnersExceptQuery>()
|
||||||
|
.HasConfirmedOwnersExceptAsync(orgUser1.OrganizationId, Arg.Any<IEnumerable<Guid>>())
|
||||||
|
.Returns(true);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await sutProvider.Sut.RemoveUsersAsync(orgUser1.OrganizationId, organizationUserIds, eventSystemUser);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.Equal(2, result.Count());
|
||||||
|
Assert.All(result, r => Assert.Empty(r.ErrorMessage));
|
||||||
await sutProvider.GetDependency<IGetOrganizationUsersManagementStatusQuery>()
|
await sutProvider.GetDependency<IGetOrganizationUsersManagementStatusQuery>()
|
||||||
.DidNotReceiveWithAnyArgs()
|
.DidNotReceiveWithAnyArgs()
|
||||||
.GetUsersOrganizationManagementStatusAsync(default, default);
|
.GetUsersOrganizationManagementStatusAsync(default, default);
|
||||||
|
await sutProvider.GetDependency<IOrganizationUserRepository>()
|
||||||
|
.Received(1)
|
||||||
|
.DeleteManyAsync(Arg.Is<IEnumerable<Guid>>(i => i.Contains(orgUser1.Id) && i.Contains(orgUser2.Id)));
|
||||||
|
await sutProvider.GetDependency<IEventService>()
|
||||||
|
.Received(1)
|
||||||
|
.LogOrganizationUserEventsAsync(
|
||||||
|
Arg.Is<IEnumerable<(OrganizationUser OrganizationUser, EventType EventType, EventSystemUser EventSystemUser, DateTime? DateTime)>>(
|
||||||
|
i => i.First().OrganizationUser.Id == orgUser1.Id
|
||||||
|
&& i.Last().OrganizationUser.Id == orgUser2.Id
|
||||||
|
&& i.All(u => u.EventSystemUser == eventSystemUser
|
||||||
|
&& u.DateTime == eventDate)));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory, BitAutoData]
|
[Theory, BitAutoData]
|
||||||
|
Loading…
Reference in New Issue
Block a user