feat: customers buy with a CPF or a CNPJ
All checks were successful
Build and deploy / Validate source (push) Successful in 1m38s
Build and deploy / Integration suite on a real stack (push) Successful in 4m57s
Build and deploy / Secret scan and release gate (push) Successful in 13s
Build and deploy / Publish images (push) Successful in 2m1s
All checks were successful
Build and deploy / Validate source (push) Successful in 1m38s
Build and deploy / Integration suite on a real stack (push) Successful in 4m57s
Build and deploy / Secret scan and release gate (push) Successful in 13s
Build and deploy / Publish images (push) Successful in 2m1s
The cart and the account signup take either document, each with its own mask and check digits. Tiny gets a person (F) for a CPF, Mercado Pago the matching identification type, and only CNPJs go to the company registry. The Kanban, the account page and the alerts show which one it is. Also pins the Correios test's clock: its fake token expired today, so the suite failed from Oct 16 on. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -107,7 +107,14 @@ try{
|
||||
// The items come back after a reload; the customer's details do not.
|
||||
assert.deepEqual(await site.eval(`['fCnpj','fZap','fMail'].map(id=>$(id).value)`),['','','']);
|
||||
assert.equal(await site.eval('document.getElementById("bPagar").disabled'),true);
|
||||
// A CPF or a CNPJ, each in its own mask; this order is a person's.
|
||||
await site.fill('#fCnpj','11222333000181');
|
||||
assert.equal(await site.eval(`$('fCnpj').value`),'11.222.333/0001-81');
|
||||
await site.fill('#fCnpj','52998224724');
|
||||
assert.equal(await site.eval(`$('fCnpj').value`),'529.982.247-24');
|
||||
assert.equal(await site.eval('docOk(cliente.cnpj)'),false);
|
||||
await site.fill('#fCnpj','52998224725');
|
||||
assert.equal(await site.eval(`$('fCnpj').value+' '+$('fCnpj').classList.contains('bom')`),'529.982.247-25 true');
|
||||
await site.fill('#fZap','11999999999');
|
||||
await site.fill('#fMail','local-browser@example.test');
|
||||
assert.equal(await site.eval('pedido[0].localFiles[0].name'),'local-test.cdr');
|
||||
|
||||
@@ -166,6 +166,9 @@ def run():
|
||||
client.call('/quotes',{**draft,'items':[outside]},expected=422)
|
||||
client.call('/quotes',{**draft,'items':[{**items[0],'metres':'1.00'}]},expected=422)
|
||||
client.call('/quotes',{**draft,'customer':{**draft['customer'],'cnpj':'11111111111111'}},expected=422)
|
||||
# A person buys with a CPF: its check digits count as a CNPJ's do.
|
||||
client.call('/quotes',{**draft,'customer':{**draft['customer'],'cnpj':'529.982.247-24'}},expected=422)
|
||||
client.call('/quotes',{**draft,'request_key':str(uuid4()),'customer':{**draft['customer'],'cnpj':'529.982.247-25'}})
|
||||
quote=client.call('/quotes',draft)
|
||||
assert quote['status']=='pending_review'
|
||||
assert client.call('/quotes/'+quote['id'])['review_reason']=='Pedido acima de 50 m'
|
||||
|
||||
@@ -23,6 +23,11 @@ class CnpjTests(unittest.TestCase):
|
||||
with self.assertRaises(httpx.HTTPError):
|
||||
cnpj.fetch('11222333000181', transport(503))
|
||||
|
||||
def test_a_cpf_is_never_looked_up(self):
|
||||
def refuse():
|
||||
raise AssertionError('a CPF reached the database')
|
||||
self.assertIsNone(cnpj.company('529.982.247-25', connect=refuse, transport=transport(500)))
|
||||
|
||||
def test_new_tiny_contacts_are_named_after_the_company(self):
|
||||
from app.tiny import contact_payload
|
||||
order = {'customer': {'cnpj': '11222333000181', 'mail': 'loja@example.test', 'zap': '16999999999'},
|
||||
|
||||
@@ -56,6 +56,8 @@ class FakeCorreios:
|
||||
|
||||
|
||||
def quotes(fake, **kwargs):
|
||||
# A fixed day before the fake token's expiry, so the test never ages.
|
||||
kwargs.setdefault('clock', lambda: datetime(2026, 10, 15, 12, tzinfo=timezone.utc))
|
||||
return CorreiosQuotes(user='8825364223', access_code='codigo-1', card='0076691373',
|
||||
transport=httpx.MockTransport(fake), **kwargs)
|
||||
|
||||
|
||||
28
tests/test_customer_document.py
Normal file
28
tests/test_customer_document.py
Normal file
@@ -0,0 +1,28 @@
|
||||
"""The customer's document: a CPF (a person) or a CNPJ (a company), with its
|
||||
check digits. Runs where pydantic is installed."""
|
||||
import unittest
|
||||
|
||||
from pydantic import ValidationError
|
||||
|
||||
from app.core.models import Customer
|
||||
|
||||
|
||||
def customer(document):
|
||||
return Customer(cnpj=document, zap='16999999999', mail='loja@example.test')
|
||||
|
||||
|
||||
class CustomerDocumentTest(unittest.TestCase):
|
||||
def test_a_cpf_or_a_cnpj_is_kept_as_digits(self):
|
||||
self.assertEqual(customer('529.982.247-25').cnpj, '52998224725')
|
||||
self.assertEqual(customer('11.222.333/0001-81').cnpj, '11222333000181')
|
||||
self.assertEqual(customer('55786635000158').cnpj, '55786635000158')
|
||||
|
||||
def test_wrong_check_digits_repeated_digits_and_other_lengths_are_refused(self):
|
||||
for document in ('529.982.247-24', '111.111.111-11', '11.222.333/0001-82', '00000000000000',
|
||||
'5299822472', '529982247250', '١١٢٢٢٣٣٣٠٠٠١٨١'):
|
||||
with self.subTest(document=document), self.assertRaises(ValidationError):
|
||||
customer(document)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -133,6 +133,10 @@ class MercadoPagoTests(unittest.TestCase):
|
||||
self.assertEqual((body['payment_method_id'], body['transaction_amount']), ('pix', 123.45))
|
||||
self.assertEqual(body['external_reference'], '11111111-2222-3333-4444-555555555555')
|
||||
self.assertEqual(body['notification_url'], 'https://dtf.example/api/payments/webhook')
|
||||
self.assertEqual(body['payer']['identification'], {'type': 'CNPJ', 'number': '11222333000181'})
|
||||
self.mp.create('22222222-2222-3333-4444-555555555555', 1000, {'mail': 'a@example.test', 'cnpj': '52998224725'})
|
||||
person = json.loads(self.requests[-1].content)
|
||||
self.assertEqual(person['payer']['identification'], {'type': 'CPF', 'number': '52998224725'})
|
||||
self.assertEqual((created['pix_qr_code'], created['status']), ('000201PIX', 'pending'))
|
||||
# The code expires in 30 minutes, in the format Mercado Pago documents.
|
||||
expires = datetime.fromisoformat(body['date_of_expiration'])
|
||||
|
||||
@@ -137,6 +137,15 @@ class TinyTests(FakeTinyCase):
|
||||
self.assertNotIn(('POST', '/contatos'), self.calls)
|
||||
self.assertEqual(self.orders[0]['idContato'], 321)
|
||||
|
||||
def test_a_cpf_customer_is_a_person_and_not_looked_up_in_the_company_registry(self):
|
||||
looked_up = []
|
||||
self.tiny.names = lambda document: looked_up.append(document)
|
||||
person = {**PAID, 'order': {**PAID['order'], 'customer': {**PAID['order']['customer'], 'cnpj': '52998224725'}}}
|
||||
self.tiny.deliver('k-cpf', person)
|
||||
self.assertEqual((self.contacts[0]['tipoPessoa'], self.contacts[0]['cpfCnpj'], self.contacts[0]['nome']),
|
||||
('F', '52998224725', 'Loja Teste'))
|
||||
self.assertEqual(looked_up, [])
|
||||
|
||||
def test_production_events_are_not_sent(self):
|
||||
self.assertEqual(self.tiny.deliver('k2', {**PAID, 'event': 'ready'})['status'], 'not-applicable')
|
||||
self.assertEqual(self.calls, [])
|
||||
|
||||
Reference in New Issue
Block a user