wip iugu
This commit is contained in:
@@ -1,21 +1,91 @@
|
||||
from decimal import Decimal
|
||||
|
||||
import requests
|
||||
from aws_lambda_powertools.utilities.typing.lambda_context import LambdaContext
|
||||
from layercake.dynamodb import DynamoDBPersistenceLayer
|
||||
from layercake.dynamodb import DynamoDBPersistenceLayer, KeyPair
|
||||
|
||||
import events.payments.create_invoice as app
|
||||
|
||||
from ...test_iugu import MockResponse
|
||||
|
||||
def test_create_invoice(
|
||||
dynamodb_seeds,
|
||||
dynamodb_persistence_layer: DynamoDBPersistenceLayer,
|
||||
lambda_context: LambdaContext,
|
||||
):
|
||||
event = {
|
||||
order_id = '121c1140-779d-4664-8d99-4a006a22f547'
|
||||
|
||||
|
||||
def _event(payment_method: str) -> dict:
|
||||
return {
|
||||
'detail': {
|
||||
'new_image': {
|
||||
'id': '',
|
||||
'sk': '0'
|
||||
'id': order_id,
|
||||
'sk': '0',
|
||||
'total': Decimal(' 267.3'),
|
||||
'name': 'Beta Educação',
|
||||
'payment_method': payment_method,
|
||||
'create_date': '2026-01-07T19:07:49.272967-03:00',
|
||||
'due_date': '2026-01-12T00:35:44.897447-03:00',
|
||||
'coupon': '10OFF',
|
||||
'discount': Decimal('-29.7'),
|
||||
'updated_at': '2026-01-07T19:07:51.512605-03:00',
|
||||
'tenant_id': 'cJtK9SsnJhKPyxESe7g3DG',
|
||||
'email': 'org+15608435000190@users.noreply.saladeaula.digital',
|
||||
'org_id': 'cJtK9SsnJhKPyxESe7g3DG',
|
||||
'cnpj': '15608435000190',
|
||||
'status': 'PENDING',
|
||||
'subtotal': Decimal('297'),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
assert app.lambda_handler(event, lambda_context) # type: ignore
|
||||
|
||||
def test_create_bank_slip_invoice(
|
||||
monkeypatch,
|
||||
dynamodb_seeds,
|
||||
dynamodb_persistence_layer: DynamoDBPersistenceLayer,
|
||||
lambda_context: LambdaContext,
|
||||
):
|
||||
monkeypatch.setattr(
|
||||
requests,
|
||||
'post',
|
||||
lambda *args, **kwargs: MockResponse(
|
||||
'tests/samples/iugu_invoice_bank_slip.json'
|
||||
),
|
||||
)
|
||||
|
||||
assert app.lambda_handler(_event('BANK_SLIP'), lambda_context) # type: ignore
|
||||
|
||||
invoice = dynamodb_persistence_layer.get_item(KeyPair(order_id, 'INVOICE'))
|
||||
|
||||
assert (
|
||||
invoice['secure_url']
|
||||
== 'https://checkout.iugu.com/invoices/16f7aa3d-2e0b-41e9-987b-1dc95b957456-d7a2'
|
||||
)
|
||||
assert invoice['secure_id'] == '16f7aa3d-2e0b-41e9-987b-1dc95b957456-d7a2'
|
||||
assert (
|
||||
invoice['bank_slip']['bank_slip_url']
|
||||
== 'https://boletos.iugu.com/v1/public/invoice/16f7aa3d-2e0b-41e9-987b-1dc95b957456-d7a2/bank_slip'
|
||||
)
|
||||
|
||||
|
||||
def test_create_bank_slip_pix(
|
||||
monkeypatch,
|
||||
dynamodb_seeds,
|
||||
dynamodb_persistence_layer: DynamoDBPersistenceLayer,
|
||||
lambda_context: LambdaContext,
|
||||
):
|
||||
monkeypatch.setattr(
|
||||
requests,
|
||||
'post',
|
||||
lambda *args, **kwargs: MockResponse('tests/samples/iugu_invoice_pix.json'),
|
||||
)
|
||||
|
||||
assert app.lambda_handler(_event('PIX'), lambda_context) # type: ignore
|
||||
|
||||
invoice = dynamodb_persistence_layer.get_item(KeyPair(order_id, 'INVOICE'))
|
||||
|
||||
assert (
|
||||
invoice['pix']['qrcode_text']
|
||||
== 'http://faturas.iugu.com/iugu_pix/970cb579-c396-4e59-a323-ce61ae04f7bc-196c/test/pay'
|
||||
)
|
||||
assert (
|
||||
invoice['pix']['qrcode_text']
|
||||
== 'http://faturas.iugu.com/iugu_pix/970cb579-c396-4e59-a323-ce61ae04f7bc-196c/test/pay'
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user