Normalize invoice provision periods in PDF generation, switch admin labels between single-date and range modes, add end-to-end tests, update package and frontend bundle versions, and note the invoice lifecycle docs update.
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using Fuchs.intranet;
|
||||
using Fuchs.Notifications;
|
||||
using Fuchs.Services;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
using MigraDoc.DocumentObjectModel;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
|
||||
namespace Fuchs.Tests;
|
||||
|
||||
/// <summary>
|
||||
/// The stored Leistungsdatum / -zeitraum must reach the invoice PDF's admin block (it was never
|
||||
/// passed to the text blocks, so every invoice printed "Leistungszeitraum: -").
|
||||
/// </summary>
|
||||
public class InvoicePdfProvisionPeriodTests
|
||||
{
|
||||
private sealed class NoHttp : IHttpClientFactory
|
||||
{
|
||||
public HttpClient CreateClient(string name) => throw new InvalidOperationException("no HTTP expected");
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("2026-06-18", "18.06.2026")]
|
||||
[InlineData("2026-06-01 - 2026-06-30", "01.06.2026 - 30.06.2026")]
|
||||
[InlineData("18.06.2026", "18.06.2026")]
|
||||
[InlineData("01.06.2026 - 30.06.2026", "01.06.2026 - 30.06.2026")]
|
||||
[InlineData("R2026-0258", "R2026-0258")]
|
||||
[InlineData("", "")]
|
||||
[InlineData(null, "")]
|
||||
[InlineData("nach Absprache", "nach Absprache")]
|
||||
public void ProvisionPeriodForDisplay_MixedFormats_ShowsGermanDates(string? input, string expected)
|
||||
{
|
||||
Assert.Equal(expected, InvoiceService.ProvisionPeriodForDisplay(input));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("18.06.2026", "18.06.2026", "Leistungsdatum")]
|
||||
[InlineData("01.06.2026 - 30.06.2026", "01.06.2026 - 30.06.2026", "Leistungszeitraum")]
|
||||
[InlineData("2026-06-18", "18.06.2026", "Leistungsdatum")]
|
||||
[InlineData("2026-06-01 - 2026-06-30", "01.06.2026 - 30.06.2026", "Leistungszeitraum")]
|
||||
[InlineData(" 18.06.2026 ", "18.06.2026", "Leistungsdatum")]
|
||||
[InlineData("", "", "Leistungszeitraum")]
|
||||
[InlineData(null, "", "Leistungszeitraum")]
|
||||
public void ApplyProvisionPeriod_StoredValue_SetsGermanValueAndMatchingLabel(string? stored, string expectedValue, string expectedLabel)
|
||||
{
|
||||
var tb = new FuchsPdf.FdsTextBlocks();
|
||||
|
||||
InvoiceService.ApplyProvisionPeriod(tb, stored);
|
||||
|
||||
Assert.Equal(expectedValue, tb.ProvisionPeriod);
|
||||
Assert.Equal(expectedLabel, tb.AdminProvLabel);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("18.06.2026", "18.06.2026", "Leistungsdatum")]
|
||||
[InlineData("2026-06-01 - 2026-06-30", "01.06.2026 - 30.06.2026", "Leistungszeitraum")]
|
||||
[InlineData(null, "", "Leistungszeitraum")]
|
||||
public async Task GenerateInvoicePdfAsync_StoredProvisionPeriod_ReachesAdminBlock(string? stored, string expectedValue, string expectedLabel)
|
||||
{
|
||||
FuchsPdf.FdsTextBlocks? captured = null;
|
||||
var pdf = new Mock<IPdfService>();
|
||||
pdf.Setup(p => p.WriteLetterAsync(It.IsAny<FuchsPdf.FdsTextBlocks>(), It.IsAny<bool>()))
|
||||
.Callback<FuchsPdf.FdsTextBlocks, bool>((tb, _) => captured = tb)
|
||||
.ReturnsAsync(new Document());
|
||||
var erechnung = new Mock<IERechnungService>();
|
||||
erechnung.SetupGet(e => e.Enabled).Returns(false);
|
||||
var config = new ConfigurationBuilder().Build();
|
||||
var svc = new InvoiceService(new Fuchs_intranet(config), pdf.Object, new Mock<IBlobStorageService>().Object,
|
||||
new Mock<IEventService>().Object, erechnung.Object, new NoHttp(), config, NullLogger<InvoiceService>.Instance);
|
||||
var reg = new Dictionary<string, object?> { ["Id"] = "W7VAL", ["InvoiceId"] = "R2026-0258" };
|
||||
if (stored != null) reg["ProvisionPeriod"] = stored;
|
||||
var invoice = new FdsInvoiceData { InvoiceRegistration = new OCORE.OCORE_dictionaries.GenericObjectDictionary(reg) };
|
||||
|
||||
await svc.GenerateInvoicePdfAsync(invoice, draft: true);
|
||||
|
||||
Assert.NotNull(captured);
|
||||
Assert.Equal(expectedValue, captured!.ProvisionPeriod);
|
||||
Assert.Equal(expectedLabel, captured.AdminProvLabel);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user