1
0
mirror of https://github.com/bitwarden/server.git synced 2024-11-28 13:15:12 +01:00

Fix flaky OrganizationService tests (#3246)

Set up test data more explicitly instead of relying on AutoData
This commit is contained in:
Thomas Rittson 2023-09-05 06:32:47 +10:00 committed by GitHub
parent 9eed199500
commit 4d0630081a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -642,11 +642,10 @@ public class OrganizationServiceTests
await sutProvider.GetDependency<IEventService>().Received(1).LogOrganizationUserEventsAsync(Arg.Any<IEnumerable<(OrganizationUser, EventType, EventSystemUser, DateTime?)>>()); await sutProvider.GetDependency<IEventService>().Received(1).LogOrganizationUserEventsAsync(Arg.Any<IEnumerable<(OrganizationUser, EventType, EventSystemUser, DateTime?)>>());
} }
[Theory, BitAutoData] [Theory, BitAutoData, OrganizationInviteCustomize]
public async Task InviteUser_WithSecretsManager_Passes(Organization organization, public async Task InviteUser_WithSecretsManager_Passes(Organization organization,
IEnumerable<(OrganizationUserInvite invite, string externalId)> invites, IEnumerable<(OrganizationUserInvite invite, string externalId)> invites,
[OrganizationUser(type: OrganizationUserType.Owner, status: OrganizationUserStatusType.Confirmed)] OrganizationUser savingUser, OrganizationUser savingUser, SutProvider<OrganizationService> sutProvider)
SutProvider<OrganizationService> sutProvider)
{ {
organization.PlanType = PlanType.EnterpriseAnnually; organization.PlanType = PlanType.EnterpriseAnnually;
InviteUserHelper_ArrangeValidPermissions(organization, savingUser, sutProvider); InviteUserHelper_ArrangeValidPermissions(organization, savingUser, sutProvider);
@ -654,6 +653,10 @@ public class OrganizationServiceTests
// Set up some invites to grant access to SM // Set up some invites to grant access to SM
invites.First().invite.AccessSecretsManager = true; invites.First().invite.AccessSecretsManager = true;
var invitedSmUsers = invites.First().invite.Emails.Count(); var invitedSmUsers = invites.First().invite.Emails.Count();
foreach (var (invite, externalId) in invites.Skip(1))
{
invite.AccessSecretsManager = false;
}
// Assume we need to add seats for all invited SM users // Assume we need to add seats for all invited SM users
sutProvider.GetDependency<ICountNewSmSeatsRequiredQuery>() sutProvider.GetDependency<ICountNewSmSeatsRequiredQuery>()
@ -669,11 +672,10 @@ public class OrganizationServiceTests
!update.MaxAutoscaleSmSeatsChanged)); !update.MaxAutoscaleSmSeatsChanged));
} }
[Theory, BitAutoData] [Theory, BitAutoData, OrganizationInviteCustomize]
public async Task InviteUser_WithSecretsManager_WhenErrorIsThrown_RevertsAutoscaling(Organization organization, public async Task InviteUser_WithSecretsManager_WhenErrorIsThrown_RevertsAutoscaling(Organization organization,
IEnumerable<(OrganizationUserInvite invite, string externalId)> invites, IEnumerable<(OrganizationUserInvite invite, string externalId)> invites,
[OrganizationUser(type: OrganizationUserType.Owner, status: OrganizationUserStatusType.Confirmed)] OrganizationUser savingUser, OrganizationUser savingUser, SutProvider<OrganizationService> sutProvider)
SutProvider<OrganizationService> sutProvider)
{ {
var initialSmSeats = organization.SmSeats; var initialSmSeats = organization.SmSeats;
InviteUserHelper_ArrangeValidPermissions(organization, savingUser, sutProvider); InviteUserHelper_ArrangeValidPermissions(organization, savingUser, sutProvider);
@ -681,6 +683,10 @@ public class OrganizationServiceTests
// Set up some invites to grant access to SM // Set up some invites to grant access to SM
invites.First().invite.AccessSecretsManager = true; invites.First().invite.AccessSecretsManager = true;
var invitedSmUsers = invites.First().invite.Emails.Count(); var invitedSmUsers = invites.First().invite.Emails.Count();
foreach (var (invite, externalId) in invites.Skip(1))
{
invite.AccessSecretsManager = false;
}
// Assume we need to add seats for all invited SM users // Assume we need to add seats for all invited SM users
sutProvider.GetDependency<ICountNewSmSeatsRequiredQuery>() sutProvider.GetDependency<ICountNewSmSeatsRequiredQuery>()
@ -725,13 +731,9 @@ public class OrganizationServiceTests
private void InviteUserHelper_ArrangeValidPermissions(Organization organization, OrganizationUser savingUser, private void InviteUserHelper_ArrangeValidPermissions(Organization organization, OrganizationUser savingUser,
SutProvider<OrganizationService> sutProvider) SutProvider<OrganizationService> sutProvider)
{ {
savingUser.OrganizationId = organization.Id;
organization.UseCustomPermissions = true;
sutProvider.GetDependency<IOrganizationRepository>().GetByIdAsync(organization.Id).Returns(organization); sutProvider.GetDependency<IOrganizationRepository>().GetByIdAsync(organization.Id).Returns(organization);
sutProvider.GetDependency<ICurrentContext>().OrganizationOwner(organization.Id).Returns(true); sutProvider.GetDependency<ICurrentContext>().OrganizationOwner(organization.Id).Returns(true);
sutProvider.GetDependency<ICurrentContext>().ManageUsers(organization.Id).Returns(true); sutProvider.GetDependency<ICurrentContext>().ManageUsers(organization.Id).Returns(true);
sutProvider.GetDependency<IOrganizationUserRepository>().GetManyByOrganizationAsync(savingUser.OrganizationId, OrganizationUserType.Owner)
.Returns(new List<OrganizationUser> { savingUser });
} }
[Theory, BitAutoData] [Theory, BitAutoData]