mirror of
https://github.com/bitwarden/server.git
synced 2024-12-01 13:43:23 +01:00
eac2b9f0b8
* Return default state for billing metadata when no stripe entities * Fix tests
106 lines
3.4 KiB
C#
106 lines
3.4 KiB
C#
using Bit.Core.AdminConsole.Entities;
|
|
using Bit.Core.Billing.Constants;
|
|
using Bit.Core.Billing.Queries;
|
|
using Bit.Core.Billing.Queries.Implementations;
|
|
using Bit.Core.Repositories;
|
|
using Bit.Test.Common.AutoFixture;
|
|
using Bit.Test.Common.AutoFixture.Attributes;
|
|
using NSubstitute;
|
|
using Stripe;
|
|
using Xunit;
|
|
|
|
namespace Bit.Core.Test.Billing.Queries;
|
|
|
|
[SutProviderCustomize]
|
|
public class OrganizationBillingQueriesTests
|
|
{
|
|
#region GetMetadata
|
|
[Theory, BitAutoData]
|
|
public async Task GetMetadata_OrganizationNull_ReturnsNull(
|
|
Guid organizationId,
|
|
SutProvider<OrganizationBillingQueries> sutProvider)
|
|
{
|
|
var metadata = await sutProvider.Sut.GetMetadata(organizationId);
|
|
|
|
Assert.Null(metadata);
|
|
}
|
|
|
|
[Theory, BitAutoData]
|
|
public async Task GetMetadata_CustomerNull_ReturnsNull(
|
|
Guid organizationId,
|
|
Organization organization,
|
|
SutProvider<OrganizationBillingQueries> sutProvider)
|
|
{
|
|
sutProvider.GetDependency<IOrganizationRepository>().GetByIdAsync(organizationId).Returns(organization);
|
|
|
|
var metadata = await sutProvider.Sut.GetMetadata(organizationId);
|
|
|
|
Assert.False(metadata.IsOnSecretsManagerStandalone);
|
|
}
|
|
|
|
[Theory, BitAutoData]
|
|
public async Task GetMetadata_SubscriptionNull_ReturnsNull(
|
|
Guid organizationId,
|
|
Organization organization,
|
|
SutProvider<OrganizationBillingQueries> sutProvider)
|
|
{
|
|
sutProvider.GetDependency<IOrganizationRepository>().GetByIdAsync(organizationId).Returns(organization);
|
|
|
|
sutProvider.GetDependency<ISubscriberQueries>().GetCustomer(organization).Returns(new Customer());
|
|
|
|
var metadata = await sutProvider.Sut.GetMetadata(organizationId);
|
|
|
|
Assert.False(metadata.IsOnSecretsManagerStandalone);
|
|
}
|
|
|
|
[Theory, BitAutoData]
|
|
public async Task GetMetadata_Succeeds(
|
|
Guid organizationId,
|
|
Organization organization,
|
|
SutProvider<OrganizationBillingQueries> sutProvider)
|
|
{
|
|
sutProvider.GetDependency<IOrganizationRepository>().GetByIdAsync(organizationId).Returns(organization);
|
|
|
|
var subscriberQueries = sutProvider.GetDependency<ISubscriberQueries>();
|
|
|
|
subscriberQueries
|
|
.GetCustomer(organization, Arg.Is<CustomerGetOptions>(options => options.Expand.FirstOrDefault() == "discount.coupon.applies_to"))
|
|
.Returns(new Customer
|
|
{
|
|
Discount = new Discount
|
|
{
|
|
Coupon = new Coupon
|
|
{
|
|
Id = StripeConstants.CouponIDs.SecretsManagerStandalone,
|
|
AppliesTo = new CouponAppliesTo
|
|
{
|
|
Products = ["product_id"]
|
|
}
|
|
}
|
|
}
|
|
});
|
|
|
|
subscriberQueries.GetSubscription(organization).Returns(new Subscription
|
|
{
|
|
Items = new StripeList<SubscriptionItem>
|
|
{
|
|
Data =
|
|
[
|
|
new SubscriptionItem
|
|
{
|
|
Plan = new Plan
|
|
{
|
|
ProductId = "product_id"
|
|
}
|
|
}
|
|
]
|
|
}
|
|
});
|
|
|
|
var metadata = await sutProvider.Sut.GetMetadata(organizationId);
|
|
|
|
Assert.True(metadata.IsOnSecretsManagerStandalone);
|
|
}
|
|
#endregion
|
|
}
|