1
- import pytest
2
- import pytest_asyncio # noqa: F401
3
- from loguru import logger # noqa: F401
4
-
5
- from lnbits .core .crud import get_wallet # noqa: F401
6
- from tests .helpers import credit_wallet # noqa: F401
7
- from tests .mocks import WALLET # noqa: F401
8
-
9
-
10
- @pytest .mark .asyncio
11
- async def test_invoices_unknown_invoice (client ):
12
- response = await client .get ("/invoices/pay/u" )
13
- assert response .json () == {"detail" : "Invoice does not exist." }
14
-
15
-
16
- @pytest .mark .asyncio
17
- async def test_invoices_api_create_invoice_valid (client , invoices_wallet ):
18
- query = {
19
- "status" : "open" ,
20
- "currency" : "EUR" ,
21
- "company_name" : "LNbits, Inc." ,
22
- "first_name" : "Ben" ,
23
- "last_name" : "Arc" ,
24
-
25
- "items" : [
26
- {"amount" : 2.34 , "description" : "Item 1" },
27
- {"amount" : 0.98 , "description" : "Item 2" },
28
- ],
29
- }
30
-
31
- status = query ["status" ]
32
- currency = query ["currency" ]
33
- fname = query ["first_name" ]
34
- total = sum (d ["amount" ] for d in query ["items" ])
35
-
36
- response = await client .post (
37
- "/invoices/api/v1/invoice" ,
38
- json = query ,
39
- headers = {"X-Api-Key" : invoices_wallet .inkey },
40
- )
41
-
42
- assert response .status_code == 201
43
- data = response .json ()
44
-
45
- assert data ["status" ] == status
46
- assert data ["wallet" ] == invoices_wallet .id
47
- assert data ["currency" ] == currency
48
- assert data ["first_name" ] == fname
49
- assert sum (d ["amount" ] / 100 for d in data ["items" ]) == total
50
-
51
-
52
- @pytest .mark .asyncio
53
- async def test_invoices_api_partial_pay_invoice (
54
- client , accounting_invoice , adminkey_headers_from
55
- ):
56
- invoice_id = accounting_invoice ["id" ]
57
- amount_to_pay = int (5.05 * 100 ) # mock invoice total amount is 10 USD
58
-
59
- # ask for an invoice
60
- response = await client .post (
61
- f"/invoices/api/v1/invoice/{ invoice_id } /payments?famount={ amount_to_pay } "
62
- )
63
- assert response .status_code < 300
64
- data = response .json ()
65
- payment_hash = data ["payment_hash" ]
66
-
67
- # pay the invoice
68
- data = {"out" : True , "bolt11" : data ["payment_request" ]}
69
- response = await client .post (
70
- "/api/v1/payments" , json = data , headers = adminkey_headers_from
71
- )
72
- assert response .status_code < 300
73
- assert len (response .json ()["payment_hash" ]) == 64
74
- assert len (response .json ()["checking_id" ]) > 0
75
-
76
- # check invoice is paid
77
- response = await client .get (
78
- f"/invoices/api/v1/invoice/{ invoice_id } /payments/{ payment_hash } "
79
- )
80
- assert response .status_code == 200
81
- assert response .json ()["paid" ] is True
82
-
83
- # check invoice status
84
- response = await client .get (f"/invoices/api/v1/invoice/{ invoice_id } " )
85
- assert response .status_code == 200
86
- data = response .json ()
87
-
88
- assert data ["status" ] == "open"
1
+ # import pytest
2
+
3
+ # import pytest_asyncio
4
+ # from lnbits.core.crud import get_wallet
5
+ # from loguru import logger
6
+
7
+ # from tests.helpers import credit_wallet
8
+ # from tests.mocks import WALLET
9
+
10
+
11
+ # @pytest.mark.asyncio
12
+ # async def test_invoices_unknown_invoice(client):
13
+ # response = await client.get("/invoices/pay/u")
14
+ # assert response.json() == {"detail": "Invoice does not exist."}
15
+
16
+
17
+ # @pytest.mark.asyncio
18
+ # async def test_invoices_api_create_invoice_valid(client, invoices_wallet):
19
+ # query = {
20
+ # "status": "open",
21
+ # "currency": "EUR",
22
+ # "company_name": "LNbits, Inc.",
23
+ # "first_name": "Ben",
24
+ # "last_name": "Arc",
25
+
26
+ # "items": [
27
+ # {"amount": 2.34, "description": "Item 1"},
28
+ # {"amount": 0.98, "description": "Item 2"},
29
+ # ],
30
+ # }
31
+
32
+ # status = query["status"]
33
+ # currency = query["currency"]
34
+ # fname = query["first_name"]
35
+ # total = sum(d["amount"] for d in query["items"])
36
+
37
+ # response = await client.post(
38
+ # "/invoices/api/v1/invoice",
39
+ # json=query,
40
+ # headers={"X-Api-Key": invoices_wallet.inkey},
41
+ # )
42
+
43
+ # assert response.status_code == 201
44
+ # data = response.json()
45
+
46
+ # assert data["status"] == status
47
+ # assert data["wallet"] == invoices_wallet.id
48
+ # assert data["currency"] == currency
49
+ # assert data["first_name"] == fname
50
+ # assert sum(d["amount"] / 100 for d in data["items"]) == total
51
+
52
+
53
+ # @pytest.mark.asyncio
54
+ # async def test_invoices_api_partial_pay_invoice(
55
+ # client, accounting_invoice, adminkey_headers_from
56
+ # ):
57
+ # invoice_id = accounting_invoice["id"]
58
+ # amount_to_pay = int(5.05 * 100) # mock invoice total amount is 10 USD
59
+
60
+ # # ask for an invoice
61
+ # response = await client.post(
62
+ # f"/invoices/api/v1/invoice/{invoice_id}/payments?famount={amount_to_pay}"
63
+ # )
64
+ # assert response.status_code < 300
65
+ # data = response.json()
66
+ # payment_hash = data["payment_hash"]
67
+
68
+ # # pay the invoice
69
+ # data = {"out": True, "bolt11": data["payment_request"]}
70
+ # response = await client.post(
71
+ # "/api/v1/payments", json=data, headers=adminkey_headers_from
72
+ # )
73
+ # assert response.status_code < 300
74
+ # assert len(response.json()["payment_hash"]) == 64
75
+ # assert len(response.json()["checking_id"]) > 0
76
+
77
+ # # check invoice is paid
78
+ # response = await client.get(
79
+ # f"/invoices/api/v1/invoice/{invoice_id}/payments/{payment_hash}"
80
+ # )
81
+ # assert response.status_code == 200
82
+ # assert response.json()["paid"] is True
83
+
84
+ # # check invoice status
85
+ # response = await client.get(f"/invoices/api/v1/invoice/{invoice_id}")
86
+ # assert response.status_code == 200
87
+ # data = response.json()
88
+
89
+ # assert data["status"] == "open"
89
90
90
91
91
92
####
@@ -95,7 +96,9 @@ async def test_invoices_api_partial_pay_invoice(
95
96
###
96
97
97
98
# @pytest.mark.asyncio
98
- # async def test_invoices_api_full_pay_invoice(client, accounting_invoice, adminkey_headers_to):
99
+ # async def test_invoices_api_full_pay_invoice(
100
+ # client, accounting_invoice, adminkey_headers_to\
101
+ # ):
99
102
# invoice_id = accounting_invoice["id"]
100
103
# print(accounting_invoice["id"])
101
104
# amount_to_pay = int(10.20 * 100)
0 commit comments