1
0
mirror of https://github.com/bitwarden/server.git synced 2025-06-30 23:52:50 -05:00

[AC-1943] Implement provider client invoice report (#4178)

* Update ProviderInvoiceItem SQL configuration

* Implement provider client invoice export

* Add tests

* Run dotnet format

* Fixed SPROC backwards compatibility issue
This commit is contained in:
Alex Morask
2024-06-14 12:26:49 -04:00
committed by GitHub
parent b392cc962d
commit 83604cceb1
28 changed files with 1247 additions and 32 deletions

View File

@ -26,7 +26,7 @@ namespace Bit.Api.Test.Billing.Controllers;
[SutProviderCustomize]
public class ProviderBillingControllerTests
{
#region GetInvoices
#region GetInvoicesAsync
[Theory, BitAutoData]
public async Task GetInvoices_Ok(
@ -39,6 +39,7 @@ public class ProviderBillingControllerTests
{
new ()
{
Id = "3",
Created = new DateTime(2024, 7, 1),
Status = "draft",
Total = 100000,
@ -47,8 +48,9 @@ public class ProviderBillingControllerTests
},
new ()
{
Id = "2",
Created = new DateTime(2024, 6, 1),
Number = "2",
Number = "B",
Status = "open",
Total = 100000,
HostedInvoiceUrl = "https://example.com/invoice/2",
@ -56,8 +58,9 @@ public class ProviderBillingControllerTests
},
new ()
{
Id = "1",
Created = new DateTime(2024, 5, 1),
Number = "1",
Number = "A",
Status = "paid",
Total = 100000,
HostedInvoiceUrl = "https://example.com/invoice/1",
@ -78,16 +81,19 @@ public class ProviderBillingControllerTests
var openInvoice = response.Invoices.FirstOrDefault(i => i.Status == "open");
Assert.NotNull(openInvoice);
Assert.Equal("2", openInvoice.Id);
Assert.Equal(new DateTime(2024, 6, 1), openInvoice.Date);
Assert.Equal("2", openInvoice.Number);
Assert.Equal("B", openInvoice.Number);
Assert.Equal(1000, openInvoice.Total);
Assert.Equal("https://example.com/invoice/2", openInvoice.Url);
Assert.Equal("https://example.com/invoice/2/pdf", openInvoice.PdfUrl);
var paidInvoice = response.Invoices.FirstOrDefault(i => i.Status == "paid");
Assert.NotNull(paidInvoice);
Assert.Equal("1", paidInvoice.Id);
Assert.Equal(new DateTime(2024, 5, 1), paidInvoice.Date);
Assert.Equal("1", paidInvoice.Number);
Assert.Equal("A", paidInvoice.Number);
Assert.Equal(1000, paidInvoice.Total);
Assert.Equal("https://example.com/invoice/1", paidInvoice.Url);
Assert.Equal("https://example.com/invoice/1/pdf", paidInvoice.PdfUrl);
@ -95,6 +101,33 @@ public class ProviderBillingControllerTests
#endregion
#region GenerateClientInvoiceReportAsync
[Theory, BitAutoData]
public async Task GenerateClientInvoiceReportAsync_Ok(
Provider provider,
string invoiceId,
SutProvider<ProviderBillingController> sutProvider)
{
ConfigureStableInputs(provider, sutProvider);
var reportContent = "Report"u8.ToArray();
sutProvider.GetDependency<IProviderBillingService>().GenerateClientInvoiceReport(invoiceId)
.Returns(reportContent);
var result = await sutProvider.Sut.GenerateClientInvoiceReportAsync(provider.Id, invoiceId);
Assert.IsType<FileContentHttpResult>(result);
var response = (FileContentHttpResult)result;
Assert.Equal("text/csv", response.ContentType);
Assert.Equal(reportContent, response.FileContents);
}
#endregion
#region GetPaymentInformationAsync
[Theory, BitAutoData]