|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace PhpLightningTest\Unit\Invoice\Domain\BackendInvoice; |
|
6
|
|
|
|
|
7
|
|
|
use PhpLightning\Invoice\Domain\BackendInvoice\LnbitsBackendInvoice; |
|
8
|
|
|
use PhpLightning\Invoice\Domain\Http\HttpApiInterface; |
|
9
|
|
|
use PhpLightning\Shared\Transfer\BackendInvoiceResponse; |
|
10
|
|
|
use PHPUnit\Framework\TestCase; |
|
11
|
|
|
|
|
12
|
|
|
final class LnbitsBackendInvoiceTest extends TestCase |
|
13
|
|
|
{ |
|
14
|
|
|
public function test_request_invoice_when_api_returns_null(): void |
|
15
|
|
|
{ |
|
16
|
|
|
$httpApi = $this->createStub(HttpApiInterface::class); |
|
17
|
|
|
$httpApi->method('postRequestInvoice')->willReturn(null); |
|
18
|
|
|
|
|
19
|
|
|
$invoice = new LnbitsBackendInvoice($httpApi, [ |
|
20
|
|
|
'api_endpoint' => 'endpoint', |
|
21
|
|
|
'api_key' => 'key', |
|
22
|
|
|
]); |
|
23
|
|
|
$actual = $invoice->requestInvoice(100); |
|
24
|
|
|
|
|
25
|
|
|
$expected = (new BackendInvoiceResponse()) |
|
26
|
|
|
->setStatus('ERROR') |
|
27
|
|
|
->setPaymentRequest('Backend "LnBits" unreachable'); |
|
28
|
|
|
|
|
29
|
|
|
self::assertEquals($expected, $actual); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function test_request_invoice_when_api_returns_no_payment_request(): void |
|
33
|
|
|
{ |
|
34
|
|
|
$httpApi = $this->createStub(HttpApiInterface::class); |
|
35
|
|
|
$httpApi->method('postRequestInvoice')->willReturn([]); |
|
36
|
|
|
|
|
37
|
|
|
$invoice = new LnbitsBackendInvoice($httpApi, [ |
|
38
|
|
|
'api_endpoint' => 'endpoint', |
|
39
|
|
|
'api_key' => 'key', |
|
40
|
|
|
]); |
|
41
|
|
|
$actual = $invoice->requestInvoice(100); |
|
42
|
|
|
|
|
43
|
|
|
$expected = (new BackendInvoiceResponse()) |
|
44
|
|
|
->setStatus('ERROR') |
|
45
|
|
|
->setPaymentRequest('No payment_request found'); |
|
46
|
|
|
|
|
47
|
|
|
self::assertEquals($expected, $actual); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function test_request_invoice_when_api_returns_payment_request(): void |
|
51
|
|
|
{ |
|
52
|
|
|
$httpApi = $this->createStub(HttpApiInterface::class); |
|
53
|
|
|
$httpApi->method('postRequestInvoice')->willReturn([ |
|
54
|
|
|
'payment_request' => 'ln1234567890', |
|
55
|
|
|
]); |
|
56
|
|
|
|
|
57
|
|
|
$invoice = new LnbitsBackendInvoice($httpApi, [ |
|
58
|
|
|
'api_endpoint' => 'endpoint', |
|
59
|
|
|
'api_key' => 'key', |
|
60
|
|
|
]); |
|
61
|
|
|
$actual = $invoice->requestInvoice(100); |
|
62
|
|
|
|
|
63
|
|
|
$expected = (new BackendInvoiceResponse()) |
|
64
|
|
|
->setPaymentRequest('ln1234567890'); |
|
65
|
|
|
|
|
66
|
|
|
self::assertEquals($expected, $actual); |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|