From 7be2e2bd0711aa0a9a103db74b1205ecc9042a50 Mon Sep 17 00:00:00 2001 From: jrmccannon Date: Mon, 24 Mar 2025 08:45:19 -0500 Subject: [PATCH] Removed test only constructor from InviteOrganization --- .../Models/Business/InviteOrganization.cs | 6 ------ .../InviteOrganizationUserCommandTests.cs | 13 +++++++------ .../InviteUserOrganizationValidationTests.cs | 12 ++++++------ .../InviteUserPaymentValidationTests.cs | 5 +++-- .../PasswordManagerInviteUserValidationTests.cs | 9 +++++---- .../SecretsManagerInviteUserValidationTests.cs | 17 +++++++++-------- 6 files changed, 30 insertions(+), 32 deletions(-) diff --git a/src/Core/AdminConsole/Models/Business/InviteOrganization.cs b/src/Core/AdminConsole/Models/Business/InviteOrganization.cs index f292b8c063..175ee07a9f 100644 --- a/src/Core/AdminConsole/Models/Business/InviteOrganization.cs +++ b/src/Core/AdminConsole/Models/Business/InviteOrganization.cs @@ -1,6 +1,5 @@ using Bit.Core.AdminConsole.Entities; using Bit.Core.Models.StaticStore; -using Bit.Core.Utilities; namespace Bit.Core.AdminConsole.Models.Business; @@ -21,7 +20,6 @@ public record InviteOrganization } - public InviteOrganization(Organization organization, Plan plan) { OrganizationId = organization.Id; @@ -34,8 +32,4 @@ public record InviteOrganization GatewaySubscriptionId = organization.GatewaySubscriptionId; UseSecretsManager = organization.UseSecretsManager; } - - public InviteOrganization(Organization organization) : this(organization, StaticStore.GetPlan(organization.PlanType)) - { - } } diff --git a/test/Core.Test/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/InviteOrganizationUserCommandTests.cs b/test/Core.Test/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/InviteOrganizationUserCommandTests.cs index d040e64a9b..8e4d9c93e7 100644 --- a/test/Core.Test/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/InviteOrganizationUserCommandTests.cs +++ b/test/Core.Test/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/InviteOrganizationUserCommandTests.cs @@ -8,6 +8,7 @@ using Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers.InviteUsers.V using Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers.InviteUsers.Validation.PasswordManager; using Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers.InviteUsers.Validation.SecretsManager; using Bit.Core.AdminConsole.Shared.Validation; +using Bit.Core.Billing.Models.StaticStore.Plans; using Bit.Core.Entities; using Bit.Core.Enums; using Bit.Core.Models.Commands; @@ -41,7 +42,7 @@ public class InviteOrganizationUserCommandTests // Arrange user.Email = address.Address; - var organizationDto = new InviteOrganization(organization); + var organizationDto = new InviteOrganization(organization, new FreePlan()); var request = new OrganizationUserSingleEmailInvite(user.Email, organizationDto, @@ -89,7 +90,7 @@ public class InviteOrganizationUserCommandTests // Arrange orgUser.Email = address.Address; - var organizationDto = new InviteOrganization(organization); + var organizationDto = new InviteOrganization(organization, new FreePlan()); var request = new OrganizationUserSingleEmailInvite(orgUser.Email, organizationDto, @@ -141,7 +142,7 @@ public class InviteOrganizationUserCommandTests user.Email = address.Address; - var organizationDto = new InviteOrganization(organization); + var organizationDto = new InviteOrganization(organization, new FreePlan()); var request = new OrganizationUserSingleEmailInvite(user.Email, organizationDto, @@ -195,7 +196,7 @@ public class InviteOrganizationUserCommandTests organization.MaxAutoscaleSeats = 2; ownerDetails.Type = OrganizationUserType.Owner; - var organizationDto = new InviteOrganization(organization); + var organizationDto = new InviteOrganization(organization, new FreePlan()); var request = new OrganizationUserSingleEmailInvite(user.Email, organizationDto, @@ -252,7 +253,7 @@ public class InviteOrganizationUserCommandTests organization.MaxAutoscaleSeats = 2; ownerDetails.Type = OrganizationUserType.Owner; - var organizationDto = new InviteOrganization(organization); + var organizationDto = new InviteOrganization(organization, new FreePlan()); var request = new OrganizationUserSingleEmailInvite(user.Email, organizationDto, @@ -314,7 +315,7 @@ public class InviteOrganizationUserCommandTests organization.MaxAutoscaleSeats = 2; ownerDetails.Type = OrganizationUserType.Owner; - var organizationDto = new InviteOrganization(organization); + var organizationDto = new InviteOrganization(organization, new FreePlan()); var request = new OrganizationUserSingleEmailInvite(user.Email, organizationDto, diff --git a/test/Core.Test/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/InviteUserOrganizationValidationTests.cs b/test/Core.Test/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/InviteUserOrganizationValidationTests.cs index 4c95f31557..ac67cb2a5b 100644 --- a/test/Core.Test/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/InviteUserOrganizationValidationTests.cs +++ b/test/Core.Test/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/InviteUserOrganizationValidationTests.cs @@ -2,6 +2,7 @@ using Bit.Core.AdminConsole.Models.Business; using Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers.InviteUsers.Validation.Organization; using Bit.Core.AdminConsole.Shared.Validation; +using Bit.Core.Billing.Models.StaticStore.Plans; using Bit.Test.Common.AutoFixture.Attributes; using Xunit; @@ -13,7 +14,7 @@ public class InviteUserOrganizationValidationTests [BitAutoData] public void Validate_WhenOrganizationIsFreeTier_ShouldReturnValidResponse(Organization organization) { - var result = InvitingUserOrganizationValidation.Validate(new InviteOrganization(organization)); + var result = InvitingUserOrganizationValidation.Validate(new InviteOrganization(organization, new FreePlan())); Assert.IsType>(result); } @@ -25,11 +26,10 @@ public class InviteUserOrganizationValidationTests { organization.GatewayCustomerId = string.Empty; - var result = InvitingUserOrganizationValidation.Validate(new InviteOrganization(organization)); + var result = InvitingUserOrganizationValidation.Validate(new InviteOrganization(organization, new FreePlan())); Assert.IsType>(result); - - Assert.Equal(OrganizationNoPaymentMethodFoundError.Code, (result as Invalid).ErrorMessageString); + Assert.Equal(OrganizationNoPaymentMethodFoundError.Code, (result as Invalid)!.ErrorMessageString); } [Theory] @@ -39,9 +39,9 @@ public class InviteUserOrganizationValidationTests { organization.GatewaySubscriptionId = string.Empty; - var result = InvitingUserOrganizationValidation.Validate(new InviteOrganization(organization)); + var result = InvitingUserOrganizationValidation.Validate(new InviteOrganization(organization, new FreePlan())); Assert.IsType>(result); - Assert.Equal(OrganizationNoSubscriptionFoundError.Code, (result as Invalid).ErrorMessageString); + Assert.Equal(OrganizationNoSubscriptionFoundError.Code, (result as Invalid)!.ErrorMessageString); } } diff --git a/test/Core.Test/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/InviteUserPaymentValidationTests.cs b/test/Core.Test/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/InviteUserPaymentValidationTests.cs index a26fbaaaea..bcca89e1d2 100644 --- a/test/Core.Test/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/InviteUserPaymentValidationTests.cs +++ b/test/Core.Test/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/InviteUserPaymentValidationTests.cs @@ -6,6 +6,7 @@ using Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers.InviteUsers.V using Bit.Core.AdminConsole.Shared.Validation; using Bit.Core.Billing.Constants; using Bit.Core.Billing.Enums; +using Bit.Core.Billing.Models.StaticStore.Plans; using Bit.Test.Common.AutoFixture.Attributes; using Xunit; @@ -22,7 +23,7 @@ public class InviteUserPaymentValidationTests var result = InviteUserPaymentValidation.Validate(new PaymentsSubscription { SubscriptionStatus = StripeConstants.SubscriptionStatus.Active, - ProductTierType = new InviteOrganization(organization).Plan.ProductTier + ProductTierType = new InviteOrganization(organization, new FreePlan()).Plan.ProductTier }); Assert.IsType>(result); @@ -38,7 +39,7 @@ public class InviteUserPaymentValidationTests }); Assert.IsType>(result); - Assert.Equal(PaymentCancelledSubscriptionError.Code, (result as Invalid).ErrorMessageString); + Assert.Equal(PaymentCancelledSubscriptionError.Code, (result as Invalid)!.ErrorMessageString); } [Fact] diff --git a/test/Core.Test/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/PasswordManagerInviteUserValidationTests.cs b/test/Core.Test/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/PasswordManagerInviteUserValidationTests.cs index 6a8d2898af..c9d5e72967 100644 --- a/test/Core.Test/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/PasswordManagerInviteUserValidationTests.cs +++ b/test/Core.Test/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/PasswordManagerInviteUserValidationTests.cs @@ -3,6 +3,7 @@ using Bit.Core.AdminConsole.Models.Business; using Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers.InviteUsers.Validation.PasswordManager; using Bit.Core.AdminConsole.Shared.Validation; using Bit.Core.Billing.Enums; +using Bit.Core.Billing.Models.StaticStore.Plans; using Bit.Test.Common.AutoFixture.Attributes; using Xunit; @@ -17,7 +18,7 @@ public class PasswordManagerInviteUserValidationTests { organization.Seats = null; - var organizationDto = new InviteOrganization(organization); + var organizationDto = new InviteOrganization(organization, new FreePlan()); var subscriptionUpdate = new PasswordManagerSubscriptionUpdate(organizationDto, 0, 0); @@ -35,7 +36,7 @@ public class PasswordManagerInviteUserValidationTests var seatsOccupiedByUsers = 4; var additionalSeats = 4; - var organizationDto = new InviteOrganization(organization); + var organizationDto = new InviteOrganization(organization, new Enterprise2023Plan(isAnnual: true)); var subscriptionUpdate = new PasswordManagerSubscriptionUpdate(organizationDto, seatsOccupiedByUsers, additionalSeats); @@ -54,7 +55,7 @@ public class PasswordManagerInviteUserValidationTests var seatsOccupiedByUsers = 4; var additionalSeats = 1; - var organizationDto = new InviteOrganization(organization); + var organizationDto = new InviteOrganization(organization, new Enterprise2023Plan(isAnnual: true)); var subscriptionUpdate = new PasswordManagerSubscriptionUpdate(organizationDto, seatsOccupiedByUsers, additionalSeats); @@ -74,7 +75,7 @@ public class PasswordManagerInviteUserValidationTests var additionalSeats = 4; organization.PlanType = PlanType.Free; - var organizationDto = new InviteOrganization(organization); + var organizationDto = new InviteOrganization(organization, new FreePlan()); var subscriptionUpdate = new PasswordManagerSubscriptionUpdate(organizationDto, seatsOccupiedByUsers, additionalSeats); diff --git a/test/Core.Test/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/SecretsManagerInviteUserValidationTests.cs b/test/Core.Test/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/SecretsManagerInviteUserValidationTests.cs index 8f49e4a514..370b6e75f7 100644 --- a/test/Core.Test/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/SecretsManagerInviteUserValidationTests.cs +++ b/test/Core.Test/AdminConsole/OrganizationFeatures/OrganizationUsers/InviteUsers/Validation/SecretsManagerInviteUserValidationTests.cs @@ -5,6 +5,7 @@ using Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers.InviteUsers.V using Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers.InviteUsers.Validation.SecretsManager; using Bit.Core.AdminConsole.Shared.Validation; using Bit.Core.Billing.Enums; +using Bit.Core.Billing.Models.StaticStore.Plans; using Bit.Core.Enums; using Bit.Core.Models.Data; using Bit.Test.Common.AutoFixture.Attributes; @@ -22,7 +23,7 @@ public class SecretsManagerInviteUserValidationTests { organization.UseSecretsManager = false; - var organizationDto = new InviteOrganization(organization); + var organizationDto = new InviteOrganization(organization, new FreePlan()); var subscriptionUpdate = new PasswordManagerSubscriptionUpdate(organizationDto, 0, 0); var request = new InviteUserOrganizationValidationRequest @@ -49,7 +50,7 @@ public class SecretsManagerInviteUserValidationTests { organization.UseSecretsManager = false; - var organizationDto = new InviteOrganization(organization); + var organizationDto = new InviteOrganization(organization, new FreePlan()); var subscriptionUpdate = new PasswordManagerSubscriptionUpdate(organizationDto, 0, 0); var invite = OrganizationUserInvite.Create(["email@test.com"], [], OrganizationUserType.User, new Permissions(), string.Empty, true); @@ -69,7 +70,7 @@ public class SecretsManagerInviteUserValidationTests var result = SecretsManagerInviteUserValidation.Validate(update); Assert.IsType>(result); - Assert.Equal(OrganizationNoSecretsManagerError.Code, (result as Invalid).ErrorMessageString); + Assert.Equal(OrganizationNoSecretsManagerError.Code, (result as Invalid)!.ErrorMessageString); } [Theory] @@ -80,7 +81,7 @@ public class SecretsManagerInviteUserValidationTests organization.SmSeats = null; organization.UseSecretsManager = true; - var organizationDto = new InviteOrganization(organization); + var organizationDto = new InviteOrganization(organization, new FreePlan()); var subscriptionUpdate = new PasswordManagerSubscriptionUpdate(organizationDto, 0, 0); var request = new InviteUserOrganizationValidationRequest @@ -110,7 +111,7 @@ public class SecretsManagerInviteUserValidationTests organization.UseSecretsManager = true; organization.PlanType = PlanType.EnterpriseAnnually; - var organizationDto = new InviteOrganization(organization); + var organizationDto = new InviteOrganization(organization, new Enterprise2023Plan(isAnnual: true)); var subscriptionUpdate = new PasswordManagerSubscriptionUpdate(organizationDto, 0, 0); var request = new InviteUserOrganizationValidationRequest @@ -128,7 +129,7 @@ public class SecretsManagerInviteUserValidationTests var result = SecretsManagerInviteUserValidation.Validate(update); Assert.IsType>(result); - Assert.Equal(SecretsManagerSeatLimitReachedError.Code, (result as Invalid).ErrorMessageString); + Assert.Equal(SecretsManagerSeatLimitReachedError.Code, (result as Invalid)!.ErrorMessageString); } [Theory] @@ -141,7 +142,7 @@ public class SecretsManagerInviteUserValidationTests organization.UseSecretsManager = true; organization.PlanType = PlanType.EnterpriseAnnually; - var organizationDto = new InviteOrganization(organization); + var organizationDto = new InviteOrganization(organization, new Enterprise2023Plan(isAnnual: true)); var subscriptionUpdate = new PasswordManagerSubscriptionUpdate(organizationDto, 0, 0); var request = new InviteUserOrganizationValidationRequest @@ -159,6 +160,6 @@ public class SecretsManagerInviteUserValidationTests var result = SecretsManagerInviteUserValidation.Validate(update); Assert.IsType>(result); - Assert.Equal(SecretsManagerCannotExceedPasswordManagerError.Code, (result as Invalid).ErrorMessageString); + Assert.Equal(SecretsManagerCannotExceedPasswordManagerError.Code, (result as Invalid)!.ErrorMessageString); } }