|
1 | 1 | using Facturapi; |
2 | 2 | using Facturapi.Wrappers; |
| 3 | +using Newtonsoft.Json.Linq; |
3 | 4 | using System; |
4 | 5 | using System.Collections.Generic; |
5 | 6 | using System.IO; |
@@ -54,6 +55,60 @@ public async Task ReceiptCancelAsync_UsesReceiptDeleteRoute() |
54 | 55 | Assert.Equal("rcp_123", result.Id); |
55 | 56 | } |
56 | 57 |
|
| 58 | + [Fact] |
| 59 | + public async Task ReceiptMultiInvoiceAsync_UsesMultiInvoiceRoute() |
| 60 | + { |
| 61 | + var handler = new RecordingHandler(async (request, cancellationToken) => |
| 62 | + { |
| 63 | + Assert.Equal(HttpMethod.Post, request.Method); |
| 64 | + Assert.NotNull(request.RequestUri); |
| 65 | + Assert.Equal("/v2/receipts/multi-invoice", request.RequestUri.PathAndQuery); |
| 66 | + Assert.NotNull(request.Content); |
| 67 | + var body = await request.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 68 | + Assert.Contains("\"keys\":[\"rcp_1\",\"rcp_2\"]", body); |
| 69 | + return JsonResponse("{\"id\":\"inv_123\"}"); |
| 70 | + }); |
| 71 | + |
| 72 | + var wrapper = new ReceiptWrapper("test_key", "v2", CreateHttpClient(handler)); |
| 73 | + var result = await wrapper.MultiInvoiceAsync(new Dictionary<string, object> |
| 74 | + { |
| 75 | + ["keys"] = new[] { "rcp_1", "rcp_2" } |
| 76 | + }); |
| 77 | + |
| 78 | + Assert.Equal(JTokenType.Object, result.Type); |
| 79 | + Assert.Equal("inv_123", result["id"]?.Value<string>()); |
| 80 | + } |
| 81 | + |
| 82 | + [Fact] |
| 83 | + public async Task ReceiptPreviewMultiInvoicePdfAsync_UsesPreviewPdfRoute() |
| 84 | + { |
| 85 | + var payload = Encoding.UTF8.GetBytes("pdf-bytes"); |
| 86 | + var handler = new RecordingHandler(async (request, cancellationToken) => |
| 87 | + { |
| 88 | + Assert.Equal(HttpMethod.Post, request.Method); |
| 89 | + Assert.NotNull(request.RequestUri); |
| 90 | + Assert.Equal("/v2/receipts/multi-invoice/preview/pdf", request.RequestUri.PathAndQuery); |
| 91 | + Assert.NotNull(request.Content); |
| 92 | + var body = await request.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 93 | + Assert.Contains("\"keys\":[\"rcp_1\"]", body); |
| 94 | + return new HttpResponseMessage(HttpStatusCode.OK) |
| 95 | + { |
| 96 | + Content = new ByteArrayContent(payload) |
| 97 | + }; |
| 98 | + }); |
| 99 | + |
| 100 | + var wrapper = new ReceiptWrapper("test_key", "v2", CreateHttpClient(handler)); |
| 101 | + using var stream = await wrapper.PreviewMultiInvoicePdfAsync(new Dictionary<string, object> |
| 102 | + { |
| 103 | + ["keys"] = new[] { "rcp_1" } |
| 104 | + }); |
| 105 | + |
| 106 | + Assert.Equal(0, stream.Position); |
| 107 | + using var reader = new StreamReader(stream, Encoding.UTF8, false, 1024, leaveOpen: true); |
| 108 | + var text = await reader.ReadToEndAsync(); |
| 109 | + Assert.Equal("pdf-bytes", text); |
| 110 | + } |
| 111 | + |
57 | 112 | [Fact] |
58 | 113 | public async Task OrganizationDeleteSeriesAsync_UsesDeleteSeriesRoute() |
59 | 114 | { |
|
0 commit comments