mirror of
https://github.com/bitwarden/server.git
synced 2025-06-13 14:30:50 -05:00

* implement the seat decrease error message * Resolve the comment regarding abstraction * Resolved the database failure Signed-off-by: Cy Okeke <cokeke@bitwarden.com> * Resolve the failing test Signed-off-by: Cy Okeke <cokeke@bitwarden.com> * Resolve the failing test Signed-off-by: Cy Okeke <cokeke@bitwarden.com> * Resolve the failing upgrade test Signed-off-by: Cy Okeke <cokeke@bitwarden.com> * Resolve the failing test Signed-off-by: Cy Okeke <cokeke@bitwarden.com> * Resolve the failing test Signed-off-by: Cy Okeke <cokeke@bitwarden.com> * Removed the unused method * Remove the total calculation from the stored procedure * Refactoring base on pr feedback * Refactoring base on pr feedback * Resolve the fauiling database * Resolve the failing database test * Resolve the database test * Remove duplicate migrations * resolve the failing test * Removed the unneeded change * remove this file * Reverted Deleted migration * revert the added space * resolve the stored procedure name * Rename the migration name * Updated the stored procedure name * Revert the changes on the sproc * Revert unrelated changes * Remove the unused method * improved the xmldoc * Add an integration testing * Add the use of helper test class Signed-off-by: Cy Okeke <cokeke@bitwarden.com> * Resolve the failing test Signed-off-by: Cy Okeke <cokeke@bitwarden.com> * Resolve the failing test Signed-off-by: Cy Okeke <cokeke@bitwarden.com> * remove object look up * Resolve message rollback Signed-off-by: Cy Okeke <cokeke@bitwarden.com> --------- Signed-off-by: Cy Okeke <cokeke@bitwarden.com>
124 lines
4.4 KiB
C#
124 lines
4.4 KiB
C#
using Bit.Core.AdminConsole.Entities;
|
|
using Bit.Core.Billing.Constants;
|
|
using Bit.Core.Billing.Pricing;
|
|
using Bit.Core.Billing.Services;
|
|
using Bit.Core.Billing.Services.Implementations;
|
|
using Bit.Core.Models.Data.Organizations.OrganizationUsers;
|
|
using Bit.Core.Repositories;
|
|
using Bit.Core.Utilities;
|
|
using Bit.Test.Common.AutoFixture;
|
|
using Bit.Test.Common.AutoFixture.Attributes;
|
|
using NSubstitute;
|
|
using Stripe;
|
|
using Xunit;
|
|
|
|
namespace Bit.Core.Test.Billing.Services;
|
|
|
|
[SutProviderCustomize]
|
|
public class OrganizationBillingServiceTests
|
|
{
|
|
#region GetMetadata
|
|
|
|
[Theory, BitAutoData]
|
|
public async Task GetMetadata_Succeeds(
|
|
Guid organizationId,
|
|
Organization organization,
|
|
SutProvider<OrganizationBillingService> sutProvider)
|
|
{
|
|
sutProvider.GetDependency<IOrganizationRepository>().GetByIdAsync(organizationId).Returns(organization);
|
|
sutProvider.GetDependency<IPricingClient>().ListPlans().Returns(StaticStore.Plans.ToList());
|
|
|
|
sutProvider.GetDependency<IPricingClient>().GetPlanOrThrow(organization.PlanType)
|
|
.Returns(StaticStore.GetPlan(organization.PlanType));
|
|
|
|
var subscriberService = sutProvider.GetDependency<ISubscriberService>();
|
|
var organizationSeatCount = new OrganizationSeatCounts { Users = 1, Sponsored = 0 };
|
|
var customer = new Customer
|
|
{
|
|
Discount = new Discount
|
|
{
|
|
Coupon = new Coupon
|
|
{
|
|
Id = StripeConstants.CouponIDs.SecretsManagerStandalone,
|
|
AppliesTo = new CouponAppliesTo
|
|
{
|
|
Products = ["product_id"]
|
|
}
|
|
}
|
|
}
|
|
};
|
|
|
|
subscriberService
|
|
.GetCustomer(organization, Arg.Is<CustomerGetOptions>(options =>
|
|
options.Expand.Contains("discount.coupon.applies_to")))
|
|
.Returns(customer);
|
|
|
|
subscriberService.GetSubscription(organization).Returns(new Subscription
|
|
{
|
|
Items = new StripeList<SubscriptionItem>
|
|
{
|
|
Data =
|
|
[
|
|
new SubscriptionItem
|
|
{
|
|
Plan = new Plan
|
|
{
|
|
ProductId = "product_id"
|
|
}
|
|
}
|
|
]
|
|
}
|
|
});
|
|
|
|
sutProvider.GetDependency<IOrganizationRepository>()
|
|
.GetOccupiedSeatCountByOrganizationIdAsync(organization.Id)
|
|
.Returns(new OrganizationSeatCounts { Users = 1, Sponsored = 0 });
|
|
|
|
var metadata = await sutProvider.Sut.GetMetadata(organizationId);
|
|
|
|
Assert.True(metadata!.IsOnSecretsManagerStandalone);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region GetMetadata - Null Customer or Subscription
|
|
|
|
[Theory, BitAutoData]
|
|
public async Task GetMetadata_WhenCustomerOrSubscriptionIsNull_ReturnsDefaultMetadata(
|
|
Guid organizationId,
|
|
Organization organization,
|
|
SutProvider<OrganizationBillingService> sutProvider)
|
|
{
|
|
sutProvider.GetDependency<IOrganizationRepository>().GetByIdAsync(organizationId).Returns(organization);
|
|
|
|
sutProvider.GetDependency<IPricingClient>().ListPlans().Returns(StaticStore.Plans.ToList());
|
|
|
|
sutProvider.GetDependency<IPricingClient>().GetPlanOrThrow(organization.PlanType)
|
|
.Returns(StaticStore.GetPlan(organization.PlanType));
|
|
|
|
var subscriberService = sutProvider.GetDependency<ISubscriberService>();
|
|
|
|
// Set up subscriber service to return null for customer
|
|
subscriberService
|
|
.GetCustomer(organization, Arg.Is<CustomerGetOptions>(options => options.Expand.FirstOrDefault() == "discount.coupon.applies_to"))
|
|
.Returns((Customer)null);
|
|
|
|
// Set up subscriber service to return null for subscription
|
|
subscriberService.GetSubscription(organization).Returns((Subscription)null);
|
|
|
|
var metadata = await sutProvider.Sut.GetMetadata(organizationId);
|
|
|
|
Assert.NotNull(metadata);
|
|
Assert.False(metadata!.IsOnSecretsManagerStandalone);
|
|
Assert.False(metadata.HasSubscription);
|
|
Assert.False(metadata.IsSubscriptionUnpaid);
|
|
Assert.False(metadata.HasOpenInvoice);
|
|
Assert.False(metadata.IsSubscriptionCanceled);
|
|
Assert.Null(metadata.InvoiceDueDate);
|
|
Assert.Null(metadata.InvoiceCreatedDate);
|
|
Assert.Null(metadata.SubPeriodEndDate);
|
|
}
|
|
|
|
#endregion
|
|
}
|