1
0
mirror of https://github.com/bitwarden/server.git synced 2025-04-05 05:00:19 -05:00

Removed test only constructor from InviteOrganization

This commit is contained in:
jrmccannon 2025-03-24 08:45:19 -05:00
parent 3f81e15169
commit 7be2e2bd07
No known key found for this signature in database
GPG Key ID: CF03F3DB01CE96A6
6 changed files with 30 additions and 32 deletions

View File

@ -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))
{
}
}

View File

@ -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,

View File

@ -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<Valid<InviteOrganization>>(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<Invalid<InviteOrganization>>(result);
Assert.Equal(OrganizationNoPaymentMethodFoundError.Code, (result as Invalid<InviteOrganization>).ErrorMessageString);
Assert.Equal(OrganizationNoPaymentMethodFoundError.Code, (result as Invalid<InviteOrganization>)!.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<Invalid<InviteOrganization>>(result);
Assert.Equal(OrganizationNoSubscriptionFoundError.Code, (result as Invalid<InviteOrganization>).ErrorMessageString);
Assert.Equal(OrganizationNoSubscriptionFoundError.Code, (result as Invalid<InviteOrganization>)!.ErrorMessageString);
}
}

View File

@ -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<Valid<PaymentsSubscription>>(result);
@ -38,7 +39,7 @@ public class InviteUserPaymentValidationTests
});
Assert.IsType<Invalid<PaymentsSubscription>>(result);
Assert.Equal(PaymentCancelledSubscriptionError.Code, (result as Invalid<PaymentsSubscription>).ErrorMessageString);
Assert.Equal(PaymentCancelledSubscriptionError.Code, (result as Invalid<PaymentsSubscription>)!.ErrorMessageString);
}
[Fact]

View File

@ -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);

View File

@ -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<Invalid<SecretsManagerSubscriptionUpdate>>(result);
Assert.Equal(OrganizationNoSecretsManagerError.Code, (result as Invalid<SecretsManagerSubscriptionUpdate>).ErrorMessageString);
Assert.Equal(OrganizationNoSecretsManagerError.Code, (result as Invalid<SecretsManagerSubscriptionUpdate>)!.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<Invalid<SecretsManagerSubscriptionUpdate>>(result);
Assert.Equal(SecretsManagerSeatLimitReachedError.Code, (result as Invalid<SecretsManagerSubscriptionUpdate>).ErrorMessageString);
Assert.Equal(SecretsManagerSeatLimitReachedError.Code, (result as Invalid<SecretsManagerSubscriptionUpdate>)!.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<Invalid<SecretsManagerSubscriptionUpdate>>(result);
Assert.Equal(SecretsManagerCannotExceedPasswordManagerError.Code, (result as Invalid<SecretsManagerSubscriptionUpdate>).ErrorMessageString);
Assert.Equal(SecretsManagerCannotExceedPasswordManagerError.Code, (result as Invalid<SecretsManagerSubscriptionUpdate>)!.ErrorMessageString);
}
}