feat(payments): integrate cancellation token in payment intent creation and update related tests
This commit is contained in:
@@ -1,7 +1,40 @@
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Mvc.Testing;
|
||||
using GroundsForSupport.Server.Data;
|
||||
using GroundsForSupport.Server.Payments.Stripe;
|
||||
|
||||
namespace GroundsForSupport.API.Tests.Integration.Infra;
|
||||
using System.Text.Json;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using System.Text;
|
||||
|
||||
namespace GroundsForSupport.Server.Tests.Integration.Infra;
|
||||
|
||||
public sealed class TestApi : WebApplicationFactory<Program>
|
||||
{
|
||||
protected override void ConfigureWebHost(IWebHostBuilder builder)
|
||||
{
|
||||
var contextOptions = new ContextOptions()
|
||||
{
|
||||
DatabaseFilePath = "GroundsForSupport.Test.db",
|
||||
};
|
||||
|
||||
var stripeOptions = new StripeOptions()
|
||||
{
|
||||
ApiKey = "sk_test_12345",
|
||||
};
|
||||
|
||||
var contextOptionsJson = JsonSerializer.Serialize(contextOptions);
|
||||
var stripeOptionsJson = JsonSerializer.Serialize(stripeOptions);
|
||||
|
||||
var configJson = $@"{{
|
||||
""{nameof(ContextOptions)}"": {contextOptionsJson},
|
||||
""{nameof(StripeOptions)}"": {stripeOptionsJson}
|
||||
}}";
|
||||
|
||||
var config = new ConfigurationBuilder()
|
||||
.AddJsonStream(new MemoryStream(Encoding.UTF8.GetBytes(configJson)))
|
||||
.Build();
|
||||
|
||||
builder.UseConfiguration(config);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,14 @@
|
||||
using System.Net;
|
||||
using System.Net.Http.Json;
|
||||
|
||||
using GroundsForSupport.API.Tests.Integration.Infra;
|
||||
using GroundsForSupport.Server.Payments;
|
||||
using GroundsForSupport.Server.Payments.Stripe;
|
||||
using GroundsForSupport.Server.Tests.Integration.Infra;
|
||||
|
||||
using Microsoft.AspNetCore.TestHost;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
using Moq;
|
||||
|
||||
[assembly: CaptureConsole]
|
||||
|
||||
@@ -50,7 +57,26 @@ public sealed class PaymentTests(TestApi api) : IClassFixture<TestApi>
|
||||
[Fact]
|
||||
public async Task CreatePaymentIntent_WhenGivenValidRequest_ItShouldReturnCreated()
|
||||
{
|
||||
var client = _api.CreateClient();
|
||||
var mockStripeService = new Mock<IStripeService>();
|
||||
|
||||
mockStripeService
|
||||
.Setup(s => s.CreatePaymentIntentAsync(
|
||||
It.IsAny<string>(),
|
||||
It.IsAny<decimal>(),
|
||||
It.IsAny<string?>(),
|
||||
It.IsAny<string?>(),
|
||||
It.IsAny<CancellationToken>()
|
||||
)
|
||||
)
|
||||
.ReturnsAsync((true, new Intent("pi_12345_secret_67890")));
|
||||
|
||||
var api = _api.WithWebHostBuilder(
|
||||
b => b.ConfigureTestServices(
|
||||
s => s.AddSingleton(mockStripeService.Object)
|
||||
)
|
||||
);
|
||||
|
||||
var client = api.CreateClient();
|
||||
|
||||
var request = new
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user