From 4d0630081a179c78afdb20fe1d8ef5160cca87b2 Mon Sep 17 00:00:00 2001 From: Thomas Rittson <31796059+eliykat@users.noreply.github.com> Date: Tue, 5 Sep 2023 06:32:47 +1000 Subject: [PATCH] Fix flaky OrganizationService tests (#3246) Set up test data more explicitly instead of relying on AutoData --- .../Services/OrganizationServiceTests.cs | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/test/Core.Test/Services/OrganizationServiceTests.cs b/test/Core.Test/Services/OrganizationServiceTests.cs index 0389407da..6b4ed692d 100644 --- a/test/Core.Test/Services/OrganizationServiceTests.cs +++ b/test/Core.Test/Services/OrganizationServiceTests.cs @@ -642,11 +642,10 @@ public class OrganizationServiceTests await sutProvider.GetDependency().Received(1).LogOrganizationUserEventsAsync(Arg.Any>()); } - [Theory, BitAutoData] + [Theory, BitAutoData, OrganizationInviteCustomize] public async Task InviteUser_WithSecretsManager_Passes(Organization organization, IEnumerable<(OrganizationUserInvite invite, string externalId)> invites, - [OrganizationUser(type: OrganizationUserType.Owner, status: OrganizationUserStatusType.Confirmed)] OrganizationUser savingUser, - SutProvider sutProvider) + OrganizationUser savingUser, SutProvider sutProvider) { organization.PlanType = PlanType.EnterpriseAnnually; InviteUserHelper_ArrangeValidPermissions(organization, savingUser, sutProvider); @@ -654,6 +653,10 @@ public class OrganizationServiceTests // Set up some invites to grant access to SM invites.First().invite.AccessSecretsManager = true; 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 sutProvider.GetDependency() @@ -669,11 +672,10 @@ public class OrganizationServiceTests !update.MaxAutoscaleSmSeatsChanged)); } - [Theory, BitAutoData] + [Theory, BitAutoData, OrganizationInviteCustomize] public async Task InviteUser_WithSecretsManager_WhenErrorIsThrown_RevertsAutoscaling(Organization organization, IEnumerable<(OrganizationUserInvite invite, string externalId)> invites, - [OrganizationUser(type: OrganizationUserType.Owner, status: OrganizationUserStatusType.Confirmed)] OrganizationUser savingUser, - SutProvider sutProvider) + OrganizationUser savingUser, SutProvider sutProvider) { var initialSmSeats = organization.SmSeats; InviteUserHelper_ArrangeValidPermissions(organization, savingUser, sutProvider); @@ -681,6 +683,10 @@ public class OrganizationServiceTests // Set up some invites to grant access to SM invites.First().invite.AccessSecretsManager = true; 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 sutProvider.GetDependency() @@ -725,13 +731,9 @@ public class OrganizationServiceTests private void InviteUserHelper_ArrangeValidPermissions(Organization organization, OrganizationUser savingUser, SutProvider sutProvider) { - savingUser.OrganizationId = organization.Id; - organization.UseCustomPermissions = true; sutProvider.GetDependency().GetByIdAsync(organization.Id).Returns(organization); sutProvider.GetDependency().OrganizationOwner(organization.Id).Returns(true); sutProvider.GetDependency().ManageUsers(organization.Id).Returns(true); - sutProvider.GetDependency().GetManyByOrganizationAsync(savingUser.OrganizationId, OrganizationUserType.Owner) - .Returns(new List { savingUser }); } [Theory, BitAutoData]