mirror of
https://github.com/bitwarden/server.git
synced 2025-06-30 15:42:48 -05:00
Handle case where Stripe IDs do not relate to Stripe entities (#4021)
This commit is contained in:
@ -4,6 +4,7 @@ using Bit.Core.Services;
|
||||
using Bit.Test.Common.AutoFixture;
|
||||
using Bit.Test.Common.AutoFixture.Attributes;
|
||||
using NSubstitute;
|
||||
using NSubstitute.ExceptionExtensions;
|
||||
using NSubstitute.ReturnsExtensions;
|
||||
using Stripe;
|
||||
using Xunit;
|
||||
@ -48,6 +49,20 @@ public class SubscriberQueriesTests
|
||||
Assert.Null(customer);
|
||||
}
|
||||
|
||||
[Theory, BitAutoData]
|
||||
public async Task GetCustomer_StripeException_ReturnsNull(
|
||||
Organization organization,
|
||||
SutProvider<SubscriberQueries> sutProvider)
|
||||
{
|
||||
sutProvider.GetDependency<IStripeAdapter>()
|
||||
.CustomerGetAsync(organization.GatewayCustomerId)
|
||||
.ThrowsAsync<StripeException>();
|
||||
|
||||
var customer = await sutProvider.Sut.GetCustomer(organization);
|
||||
|
||||
Assert.Null(customer);
|
||||
}
|
||||
|
||||
[Theory, BitAutoData]
|
||||
public async Task GetCustomer_Succeeds(
|
||||
Organization organization,
|
||||
@ -98,6 +113,20 @@ public class SubscriberQueriesTests
|
||||
Assert.Null(subscription);
|
||||
}
|
||||
|
||||
[Theory, BitAutoData]
|
||||
public async Task GetSubscription_StripeException_ReturnsNull(
|
||||
Organization organization,
|
||||
SutProvider<SubscriberQueries> sutProvider)
|
||||
{
|
||||
sutProvider.GetDependency<IStripeAdapter>()
|
||||
.SubscriptionGetAsync(organization.GatewaySubscriptionId)
|
||||
.ThrowsAsync<StripeException>();
|
||||
|
||||
var subscription = await sutProvider.Sut.GetSubscription(organization);
|
||||
|
||||
Assert.Null(subscription);
|
||||
}
|
||||
|
||||
[Theory, BitAutoData]
|
||||
public async Task GetSubscription_Succeeds(
|
||||
Organization organization,
|
||||
@ -123,7 +152,7 @@ public class SubscriberQueriesTests
|
||||
async () => await sutProvider.Sut.GetCustomerOrThrow(null));
|
||||
|
||||
[Theory, BitAutoData]
|
||||
public async Task GetCustomerOrThrow_NoGatewaySubscriptionId_ThrowsGatewayException(
|
||||
public async Task GetCustomerOrThrow_NoGatewayCustomerId_ContactSupport(
|
||||
Organization organization,
|
||||
SutProvider<SubscriberQueries> sutProvider)
|
||||
{
|
||||
@ -133,7 +162,7 @@ public class SubscriberQueriesTests
|
||||
}
|
||||
|
||||
[Theory, BitAutoData]
|
||||
public async Task GetSubscriptionOrThrow_NoCustomer_ThrowsGatewayException(
|
||||
public async Task GetCustomerOrThrow_NoCustomer_ContactSupport(
|
||||
Organization organization,
|
||||
SutProvider<SubscriberQueries> sutProvider)
|
||||
{
|
||||
@ -144,6 +173,23 @@ public class SubscriberQueriesTests
|
||||
await ThrowsContactSupportAsync(async () => await sutProvider.Sut.GetCustomerOrThrow(organization));
|
||||
}
|
||||
|
||||
[Theory, BitAutoData]
|
||||
public async Task GetCustomerOrThrow_StripeException_ContactSupport(
|
||||
Organization organization,
|
||||
SutProvider<SubscriberQueries> sutProvider)
|
||||
{
|
||||
var stripeException = new StripeException();
|
||||
|
||||
sutProvider.GetDependency<IStripeAdapter>()
|
||||
.CustomerGetAsync(organization.GatewayCustomerId)
|
||||
.ThrowsAsync(stripeException);
|
||||
|
||||
await ThrowsContactSupportAsync(
|
||||
async () => await sutProvider.Sut.GetCustomerOrThrow(organization),
|
||||
"An error occurred while trying to retrieve a Stripe Customer",
|
||||
stripeException);
|
||||
}
|
||||
|
||||
[Theory, BitAutoData]
|
||||
public async Task GetCustomerOrThrow_Succeeds(
|
||||
Organization organization,
|
||||
@ -169,7 +215,7 @@ public class SubscriberQueriesTests
|
||||
async () => await sutProvider.Sut.GetSubscriptionOrThrow(null));
|
||||
|
||||
[Theory, BitAutoData]
|
||||
public async Task GetSubscriptionOrThrow_NoGatewaySubscriptionId_ThrowsGatewayException(
|
||||
public async Task GetSubscriptionOrThrow_NoGatewaySubscriptionId_ContactSupport(
|
||||
Organization organization,
|
||||
SutProvider<SubscriberQueries> sutProvider)
|
||||
{
|
||||
@ -179,7 +225,7 @@ public class SubscriberQueriesTests
|
||||
}
|
||||
|
||||
[Theory, BitAutoData]
|
||||
public async Task GetSubscriptionOrThrow_NoSubscription_ThrowsGatewayException(
|
||||
public async Task GetSubscriptionOrThrow_NoSubscription_ContactSupport(
|
||||
Organization organization,
|
||||
SutProvider<SubscriberQueries> sutProvider)
|
||||
{
|
||||
@ -190,6 +236,23 @@ public class SubscriberQueriesTests
|
||||
await ThrowsContactSupportAsync(async () => await sutProvider.Sut.GetSubscriptionOrThrow(organization));
|
||||
}
|
||||
|
||||
[Theory, BitAutoData]
|
||||
public async Task GetSubscriptionOrThrow_StripeException_ContactSupport(
|
||||
Organization organization,
|
||||
SutProvider<SubscriberQueries> sutProvider)
|
||||
{
|
||||
var stripeException = new StripeException();
|
||||
|
||||
sutProvider.GetDependency<IStripeAdapter>()
|
||||
.SubscriptionGetAsync(organization.GatewaySubscriptionId)
|
||||
.ThrowsAsync(stripeException);
|
||||
|
||||
await ThrowsContactSupportAsync(
|
||||
async () => await sutProvider.Sut.GetSubscriptionOrThrow(organization),
|
||||
"An error occurred while trying to retrieve a Stripe Subscription",
|
||||
stripeException);
|
||||
}
|
||||
|
||||
[Theory, BitAutoData]
|
||||
public async Task GetSubscriptionOrThrow_Succeeds(
|
||||
Organization organization,
|
||||
|
@ -7,12 +7,17 @@ namespace Bit.Core.Test.Billing;
|
||||
|
||||
public static class Utilities
|
||||
{
|
||||
public static async Task ThrowsContactSupportAsync(Func<Task> function)
|
||||
public static async Task ThrowsContactSupportAsync(
|
||||
Func<Task> function,
|
||||
string internalMessage = null,
|
||||
Exception innerException = null)
|
||||
{
|
||||
var contactSupport = ContactSupport();
|
||||
var contactSupport = ContactSupport(internalMessage, innerException);
|
||||
|
||||
var exception = await Assert.ThrowsAsync<BillingException>(function);
|
||||
|
||||
Assert.Equal(contactSupport.ClientFriendlyMessage, exception.ClientFriendlyMessage);
|
||||
Assert.Equal(contactSupport.Message, exception.Message);
|
||||
Assert.Equal(contactSupport.InnerException, exception.InnerException);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user