feat: a Tiny order goes with the seller in the customer's registration (Marcus, 2026-11-26)
Some checks failed
Build and deploy / Validate source (push) Successful in 7s
Build and deploy / Integration suite on a real stack (push) Successful in 8m24s
Build and deploy / Secret scan and release gate (push) Successful in 11s
Build and deploy / Publish images (push) Has been cancelled

Tiny does not fill the seller on an order created through its API, and it
cannot be set afterwards (order 151250). The existing contact's seller, from
its dados complementares, now goes in the order; it wins over who assembled a
montador Venda. No seller in the registration: the assembler's, or none for a
Site order. A failed reading never holds the order.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Cauê Faleiros
2026-11-27 09:16:53 -03:00
parent 70837e2e06
commit ffc7d3153a
2 changed files with 56 additions and 8 deletions

View File

@@ -51,6 +51,7 @@ class FakeTinyCase(unittest.TestCase):
self.calls = []
self.refuse_status = 0
self.refuse_tag = 0
self.refuse_contact = False
self.tags = {}
self.methods = {'77': {'id': 77, 'nome': 'Retirar pessoalmente', 'tipo': '6',
'formasFrete': [{'id': 771, 'nome': 'Retirar em loja'}]},
@@ -73,6 +74,11 @@ class FakeTinyCase(unittest.TestCase):
if request.method == 'GET' and path == '/contatos':
cnpj = request.url.params.get('cpfCnpj')
return httpx.Response(200, json={'itens': [c for c in self.contacts if cnpj in (None, c['cpfCnpj'])]})
if request.method == 'GET' and path.startswith('/contatos/'):
wanted = int(path.rsplit('/', 1)[-1])
if self.refuse_contact:
return httpx.Response(503, text='indisponível')
return httpx.Response(200, json=next(c for c in self.contacts if c['id'] == wanted))
if request.method == 'POST' and path == '/contatos':
contact = {**json.loads(request.content), 'id': 500 + len(self.contacts)}
self.contacts.append(contact)
@@ -240,6 +246,33 @@ class TinyTests(FakeTinyCase):
self.assertEqual(self.tiny.deliver('k1', PAID)['status'], 'already-created')
self.assertEqual(len(self.orders), 1)
def test_the_seller_of_an_existing_contact_goes_with_the_order(self):
# Marcus, 2026-11-26: the seller in the customer's registration
# (dados complementares); Tiny does not fill it on an API order.
self.contacts.append({'id': 321, 'cpfCnpj': '11.222.333/0001-81', 'vendedor': {'id': 977231477, 'nome': 'Lais'}})
self.tiny.deliver('k1', PAID)
self.assertEqual(self.orders[0]['vendedor'], {'id': 977231477})
def test_the_registration_seller_wins_over_who_assembled_a_venda(self):
self.contacts.append({'id': 321, 'cpfCnpj': '11.222.333/0001-81', 'vendedor': {'id': 977231477}})
venda = {**PAID, 'order': {**PAID['order'], 'seller': {'id': 2001, 'name': 'Kedma'}}}
self.tiny.deliver('k1', venda)
self.assertEqual(self.orders[0]['vendedor'], {'id': 977231477})
def test_without_a_registration_seller_the_assembler_or_none(self):
self.contacts.append({'id': 321, 'cpfCnpj': '11.222.333/0001-81', 'vendedor': {'id': 0, 'nome': ''}})
venda = {**PAID, 'order': {**PAID['order'], 'seller': {'id': 2001, 'name': 'Kedma'}}}
self.tiny.deliver('k1', venda)
self.assertEqual(self.orders[0]['vendedor'], {'id': 2001})
self.tiny.deliver('k2', {**PAID, 'number': 43})
self.assertNotIn('vendedor', self.orders[1])
def test_a_failed_seller_reading_does_not_hold_the_order(self):
self.contacts.append({'id': 321, 'cpfCnpj': '11.222.333/0001-81', 'vendedor': {'id': 977231477}})
self.refuse_contact = True
self.assertEqual(self.tiny.deliver('k1', PAID)['status'], 'created')
self.assertNotIn('vendedor', self.orders[0])
def test_a_contact_typed_without_punctuation_is_found_too(self):
self.contacts.append({'id': 322, 'cpfCnpj': '11222333000181'})
self.tiny.deliver('k1', PAID)