|
5 | 5 | using System.Diagnostics; |
6 | 6 | using System.Text.Json; |
7 | 7 | using System.Text.Json.Nodes; |
| 8 | +using System.Threading; |
8 | 9 | using System.Threading.Tasks; |
9 | 10 | using NNostr.Client.Protocols; |
10 | 11 | using Xunit; |
@@ -88,12 +89,53 @@ public async Task CanParseUri() |
88 | 89 | PaymentHash = "dummy" |
89 | 90 | }); |
90 | 91 |
|
91 | | - |
92 | | - var x = false; |
93 | | - |
94 | | - |
95 | | - |
| 92 | + } |
| 93 | + |
| 94 | + [Fact] |
| 95 | + public void PayInvoiceRequest_SerializesCorrectly() |
| 96 | + { |
| 97 | + // Test for the bug fix - PayInvoiceRequest should include "invoice" in JSON |
| 98 | + var request = new NIP47.PayInvoiceRequest() |
| 99 | + { |
| 100 | + Invoice = "lnbc1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdpl2pkx2ctnv5sxxmmwwd5kgetjypeh2ursdae8g6twvus8g6rfwvs8qun0dfjkxaq8rkx3yf5tcsyz3d73gafnh3cax9rn449d9p5uxz9ezhhypd0elx87sjle52x86fux2ypatgddc6k63n7erqz25le42c4u4ecky03ylcqca784w", |
| 101 | + Amount = 1000 |
| 102 | + }; |
| 103 | + |
| 104 | + var nip47Request = ((NIP47.INIP47Request)request).ToNip47Request(); |
| 105 | + var json = JsonSerializer.Serialize(nip47Request); |
| 106 | + |
| 107 | + // The JSON should contain "invoice" property |
| 108 | + Assert.Contains("\"invoice\"", json); |
| 109 | + |
| 110 | + // Verify the structure is correct |
| 111 | + var jsonNode = JsonSerializer.Deserialize<JsonNode>(json); |
| 112 | + Assert.Equal("pay_invoice", jsonNode!["method"]!.GetValue<string>()); |
| 113 | + Assert.Equal(request.Invoice, jsonNode!["params"]!["invoice"]!.GetValue<string>()); |
| 114 | + Assert.Equal(1000, jsonNode!["params"]!["amount"]!.GetValue<decimal>()); |
| 115 | + } |
| 116 | + |
| 117 | + [Fact] |
| 118 | + public void PayInvoiceRequest_WithoutJsonPropertyName_WouldNotSerializeInvoice() |
| 119 | + { |
| 120 | + // This test demonstrates what would happen without the [JsonPropertyName("invoice")] attribute |
| 121 | + // We create a request object and verify that the JSON includes the invoice field |
| 122 | + var request = new NIP47.PayInvoiceRequest() |
| 123 | + { |
| 124 | + Invoice = "lnbc1test", |
| 125 | + Amount = 500 |
| 126 | + }; |
| 127 | + |
| 128 | + var nip47Request = ((NIP47.INIP47Request)request).ToNip47Request(); |
| 129 | + var json = JsonSerializer.Serialize(nip47Request); |
| 130 | + |
| 131 | + // With the fix, "invoice" should be present in the JSON |
| 132 | + Assert.Contains("\"invoice\"", json); |
96 | 133 |
|
| 134 | + // Parse and verify the invoice is properly serialized |
| 135 | + var jsonNode = JsonSerializer.Deserialize<JsonNode>(json); |
| 136 | + var invoiceValue = jsonNode!["params"]!["invoice"]; |
| 137 | + Assert.NotNull(invoiceValue); |
| 138 | + Assert.Equal("lnbc1test", invoiceValue!.GetValue<string>()); |
97 | 139 | } |
98 | 140 | } |
99 | 141 |
|
|
0 commit comments