mirror of
https://github.com/bitwarden/server.git
synced 2024-12-01 13:43:23 +01:00
c4ba0dc2a5
* Add new endpoint for creating client organizations in consolidated billing * Create empty org and then assign seats for code re-use * Fixes made from debugging client side * few more small fixes * Vincent's feedback
210 lines
6.9 KiB
C#
210 lines
6.9 KiB
C#
using Bit.Core.AdminConsole.Entities;
|
|
using Bit.Core.Billing.Queries.Implementations;
|
|
using Bit.Core.Services;
|
|
using Bit.Test.Common.AutoFixture;
|
|
using Bit.Test.Common.AutoFixture.Attributes;
|
|
using NSubstitute;
|
|
using NSubstitute.ReturnsExtensions;
|
|
using Stripe;
|
|
using Xunit;
|
|
|
|
using static Bit.Core.Test.Billing.Utilities;
|
|
|
|
namespace Bit.Core.Test.Billing.Queries;
|
|
|
|
[SutProviderCustomize]
|
|
public class SubscriberQueriesTests
|
|
{
|
|
#region GetCustomer
|
|
[Theory, BitAutoData]
|
|
public async Task GetCustomer_NullSubscriber_ThrowsArgumentNullException(
|
|
SutProvider<SubscriberQueries> sutProvider)
|
|
=> await Assert.ThrowsAsync<ArgumentNullException>(
|
|
async () => await sutProvider.Sut.GetCustomer(null));
|
|
|
|
[Theory, BitAutoData]
|
|
public async Task GetCustomer_NoGatewayCustomerId_ReturnsNull(
|
|
Organization organization,
|
|
SutProvider<SubscriberQueries> sutProvider)
|
|
{
|
|
organization.GatewayCustomerId = null;
|
|
|
|
var customer = await sutProvider.Sut.GetCustomer(organization);
|
|
|
|
Assert.Null(customer);
|
|
}
|
|
|
|
[Theory, BitAutoData]
|
|
public async Task GetCustomer_NoCustomer_ReturnsNull(
|
|
Organization organization,
|
|
SutProvider<SubscriberQueries> sutProvider)
|
|
{
|
|
sutProvider.GetDependency<IStripeAdapter>()
|
|
.CustomerGetAsync(organization.GatewayCustomerId)
|
|
.ReturnsNull();
|
|
|
|
var customer = await sutProvider.Sut.GetCustomer(organization);
|
|
|
|
Assert.Null(customer);
|
|
}
|
|
|
|
[Theory, BitAutoData]
|
|
public async Task GetCustomer_Succeeds(
|
|
Organization organization,
|
|
SutProvider<SubscriberQueries> sutProvider)
|
|
{
|
|
var customer = new Customer();
|
|
|
|
sutProvider.GetDependency<IStripeAdapter>()
|
|
.CustomerGetAsync(organization.GatewayCustomerId)
|
|
.Returns(customer);
|
|
|
|
var gotCustomer = await sutProvider.Sut.GetCustomer(organization);
|
|
|
|
Assert.Equivalent(customer, gotCustomer);
|
|
}
|
|
#endregion
|
|
|
|
#region GetSubscription
|
|
[Theory, BitAutoData]
|
|
public async Task GetSubscription_NullSubscriber_ThrowsArgumentNullException(
|
|
SutProvider<SubscriberQueries> sutProvider)
|
|
=> await Assert.ThrowsAsync<ArgumentNullException>(
|
|
async () => await sutProvider.Sut.GetSubscription(null));
|
|
|
|
[Theory, BitAutoData]
|
|
public async Task GetSubscription_NoGatewaySubscriptionId_ReturnsNull(
|
|
Organization organization,
|
|
SutProvider<SubscriberQueries> sutProvider)
|
|
{
|
|
organization.GatewaySubscriptionId = null;
|
|
|
|
var subscription = await sutProvider.Sut.GetSubscription(organization);
|
|
|
|
Assert.Null(subscription);
|
|
}
|
|
|
|
[Theory, BitAutoData]
|
|
public async Task GetSubscription_NoSubscription_ReturnsNull(
|
|
Organization organization,
|
|
SutProvider<SubscriberQueries> sutProvider)
|
|
{
|
|
sutProvider.GetDependency<IStripeAdapter>()
|
|
.SubscriptionGetAsync(organization.GatewaySubscriptionId)
|
|
.ReturnsNull();
|
|
|
|
var subscription = await sutProvider.Sut.GetSubscription(organization);
|
|
|
|
Assert.Null(subscription);
|
|
}
|
|
|
|
[Theory, BitAutoData]
|
|
public async Task GetSubscription_Succeeds(
|
|
Organization organization,
|
|
SutProvider<SubscriberQueries> sutProvider)
|
|
{
|
|
var subscription = new Subscription();
|
|
|
|
sutProvider.GetDependency<IStripeAdapter>()
|
|
.SubscriptionGetAsync(organization.GatewaySubscriptionId)
|
|
.Returns(subscription);
|
|
|
|
var gotSubscription = await sutProvider.Sut.GetSubscription(organization);
|
|
|
|
Assert.Equivalent(subscription, gotSubscription);
|
|
}
|
|
#endregion
|
|
|
|
#region GetCustomerOrThrow
|
|
[Theory, BitAutoData]
|
|
public async Task GetCustomerOrThrow_NullSubscriber_ThrowsArgumentNullException(
|
|
SutProvider<SubscriberQueries> sutProvider)
|
|
=> await Assert.ThrowsAsync<ArgumentNullException>(
|
|
async () => await sutProvider.Sut.GetCustomerOrThrow(null));
|
|
|
|
[Theory, BitAutoData]
|
|
public async Task GetCustomerOrThrow_NoGatewaySubscriptionId_ThrowsGatewayException(
|
|
Organization organization,
|
|
SutProvider<SubscriberQueries> sutProvider)
|
|
{
|
|
organization.GatewayCustomerId = null;
|
|
|
|
await ThrowsContactSupportAsync(async () => await sutProvider.Sut.GetCustomerOrThrow(organization));
|
|
}
|
|
|
|
[Theory, BitAutoData]
|
|
public async Task GetSubscriptionOrThrow_NoCustomer_ThrowsGatewayException(
|
|
Organization organization,
|
|
SutProvider<SubscriberQueries> sutProvider)
|
|
{
|
|
sutProvider.GetDependency<IStripeAdapter>()
|
|
.CustomerGetAsync(organization.GatewayCustomerId)
|
|
.ReturnsNull();
|
|
|
|
await ThrowsContactSupportAsync(async () => await sutProvider.Sut.GetCustomerOrThrow(organization));
|
|
}
|
|
|
|
[Theory, BitAutoData]
|
|
public async Task GetCustomerOrThrow_Succeeds(
|
|
Organization organization,
|
|
SutProvider<SubscriberQueries> sutProvider)
|
|
{
|
|
var customer = new Customer();
|
|
|
|
sutProvider.GetDependency<IStripeAdapter>()
|
|
.CustomerGetAsync(organization.GatewayCustomerId)
|
|
.Returns(customer);
|
|
|
|
var gotCustomer = await sutProvider.Sut.GetCustomerOrThrow(organization);
|
|
|
|
Assert.Equivalent(customer, gotCustomer);
|
|
}
|
|
#endregion
|
|
|
|
#region GetSubscriptionOrThrow
|
|
[Theory, BitAutoData]
|
|
public async Task GetSubscriptionOrThrow_NullSubscriber_ThrowsArgumentNullException(
|
|
SutProvider<SubscriberQueries> sutProvider)
|
|
=> await Assert.ThrowsAsync<ArgumentNullException>(
|
|
async () => await sutProvider.Sut.GetSubscriptionOrThrow(null));
|
|
|
|
[Theory, BitAutoData]
|
|
public async Task GetSubscriptionOrThrow_NoGatewaySubscriptionId_ThrowsGatewayException(
|
|
Organization organization,
|
|
SutProvider<SubscriberQueries> sutProvider)
|
|
{
|
|
organization.GatewaySubscriptionId = null;
|
|
|
|
await ThrowsContactSupportAsync(async () => await sutProvider.Sut.GetSubscriptionOrThrow(organization));
|
|
}
|
|
|
|
[Theory, BitAutoData]
|
|
public async Task GetSubscriptionOrThrow_NoSubscription_ThrowsGatewayException(
|
|
Organization organization,
|
|
SutProvider<SubscriberQueries> sutProvider)
|
|
{
|
|
sutProvider.GetDependency<IStripeAdapter>()
|
|
.SubscriptionGetAsync(organization.GatewaySubscriptionId)
|
|
.ReturnsNull();
|
|
|
|
await ThrowsContactSupportAsync(async () => await sutProvider.Sut.GetSubscriptionOrThrow(organization));
|
|
}
|
|
|
|
[Theory, BitAutoData]
|
|
public async Task GetSubscriptionOrThrow_Succeeds(
|
|
Organization organization,
|
|
SutProvider<SubscriberQueries> sutProvider)
|
|
{
|
|
var subscription = new Subscription();
|
|
|
|
sutProvider.GetDependency<IStripeAdapter>()
|
|
.SubscriptionGetAsync(organization.GatewaySubscriptionId)
|
|
.Returns(subscription);
|
|
|
|
var gotSubscription = await sutProvider.Sut.GetSubscriptionOrThrow(organization);
|
|
|
|
Assert.Equivalent(subscription, gotSubscription);
|
|
}
|
|
#endregion
|
|
}
|