Files
dtf-system/tests/test_payment_messages.py
Cauê Faleiros 959ed37b15
All checks were successful
Build and deploy / Validate source (push) Successful in 1m22s
Build and deploy / Integration suite on a real stack (push) Successful in 4m10s
Build and deploy / Secret scan and release gate (push) Successful in 9s
Build and deploy / Publish images (push) Successful in 1m11s
feat: a refused payment says what happened and what to do, in plain Portuguese
A refused card showed Mercado Pago's code ("Pagamento recusado pelo Mercado
Pago (cc_rejected_insufficient_amount)"), a request it refused showed its
cause list, and some errors were in English ("Quote is already paid",
"Payment provider unavailable; try again"). Each now becomes one sentence:
"O cartão não tem limite suficiente para este valor. Use outro cartão ou
pague com PIX." The codes still go to the log and, on the Kanban's "Cartão
recusado" badge, beside the same sentence. A form check the customer cannot
read is replaced by a general one, and every error a customer or operator
can meet in the quote, upload, account and artwork routes is in Portuguese.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-06 15:54:14 -03:00

31 lines
1.6 KiB
Python

"""Refused payments become one plain sentence for the customer."""
import unittest
from app import payment_messages as messages
class PaymentMessageTests(unittest.TestCase):
def test_a_refused_card_says_what_happened_and_what_to_do(self):
self.assertIn('limite suficiente', messages.rejection('cc_rejected_insufficient_amount'))
self.assertIn('código de segurança', messages.rejection('cc_rejected_bad_filled_security_code'))
self.assertIn('Ligue para o banco', messages.rejection('cc_rejected_call_for_authorize'))
# An unknown or missing code still reads as a sentence, never as the code.
for detail in ('cc_rejected_something_new', None, ''):
self.assertEqual(messages.rejection(detail), messages.REJECTED)
self.assertNotIn('cc_', messages.rejection(detail))
def test_a_refused_request_names_the_field_to_fix(self):
body = {'message': 'invalid parameters', 'cause': [{'code': 324, 'description': 'Invalid identification'}]}
self.assertIn('CPF ou CNPJ', messages.refusal(body))
self.assertEqual(messages.refusal({'cause': [{'code': 10113}]}), messages.NOT_PROCESSED)
self.assertEqual(messages.refusal({}), messages.NOT_PROCESSED)
def test_quote_refusals_are_in_portuguese(self):
self.assertIn('24 horas', messages.quote_refusal('quote expired before payment'))
self.assertIn('cancelada', messages.quote_refusal('quote was discarded'))
self.assertTrue(messages.quote_refusal('anything else').startswith('Não foi possível'))
if __name__ == '__main__':
unittest.main()