feat: Site orders reach Tiny filled in as the store's own
All checks were successful
Build and deploy / Validate source (push) Successful in 5s
Build and deploy / Integration suite on a real stack (push) Successful in 3m6s
Build and deploy / Secret scan and release gate (push) Successful in 8s
Build and deploy / Publish images (push) Successful in 58s

Read from two of Dropstar's store orders: a paid order now carries its
forma de recebimento (Pix or credit card) with one parcel on the day, the
carrier with freight paid by the sender (Correios with the contract's PAC or
SEDEX, Jadlog's .PACKAGE, or the DropStar carrier with "Retirar
pessoalmente" and "Retirar em loja" for pickup), and the expected date in
working days. Formas de envio and de frete are looked up by name and code;
the two formas de recebimento and the carrier, which the app may not list,
are Dropstar's ids. Category, seller and tag wait for Dropstar's answer.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Cauê Faleiros
2026-10-19 13:34:41 -03:00
parent 7f7b684dbd
commit b2e718449b
4 changed files with 128 additions and 30 deletions

View File

@@ -49,8 +49,13 @@ class FakeTinyCase(unittest.TestCase):
self.orders = []
self.calls = []
self.refuse_status = 0
self.methods = {'77': {'id': 77, 'nome': 'Retirar pessoalmente', 'tipo': '6'},
'78': {'id': 78, 'nome': 'Correios', 'tipo': '1'}}
self.methods = {'77': {'id': 77, 'nome': 'Retirar pessoalmente', 'tipo': '6',
'formasFrete': [{'id': 771, 'nome': 'Retirar em loja'}]},
'78': {'id': 78, 'nome': 'Correios', 'tipo': '1',
'formasFrete': [{'id': 782, 'nome': 'SEDEX CONTRATO AG (03220)', 'codigo': '03220'},
{'id': 781, 'nome': 'PAC CONTRATO AG (03298)', 'codigo': '03298'}]},
'80': {'id': 80, 'nome': 'Jadlog', 'tipo': '7',
'formasFrete': [{'id': 801, 'nome': '.PACKAGE', 'codigo': '3'}]}}
self.products = {value: {'id': int(value), 'sku': f'DTF-{value}', 'descricao': f'Produto {value}',
'situacao': 'A', 'precos': {'preco': 14.9}} for value in PRODUCTS.values()}
@@ -299,17 +304,39 @@ class TinyStatusTests(FakeTinyCase):
'not-applicable')
self.assertEqual(self.calls, [])
def test_pickup_orders_carry_the_pickup_forma_de_envio(self):
self.assertEqual(order_payload(PICKUP, 1)['transportador'], {'formaEnvio': {'id': 77}})
self.assertNotIn('transportador', order_payload(PAID, 1))
with mock.patch.dict(os.environ, {'TINY_FORMA_ENVIO_RETIRADA': ''}):
self.assertNotIn('transportador', order_payload(PICKUP, 1))
def test_orders_are_filled_in_as_the_store_s_own(self):
from datetime import date
from app.tiny import PICKUP_CARRIER, RECEIPT_METHODS
thursday = date(2026, 9, 24)
with mock.patch.dict(os.environ, {'FREIGHT_PRODUCTION_DAYS': '1'}):
pickup = order_payload({**PICKUP, 'payment': {'method': 'pix'}}, 1, thursday, shipping=self.tiny.shipping)
# Pickup: the DropStar carrier, "Retirar pessoalmente" and "Retirar em loja", ready after production.
self.assertEqual(pickup['transportador'], {'fretePorConta': 'R', 'id': PICKUP_CARRIER,
'formaEnvio': {'id': 77}, 'formaFrete': {'id': 771}})
self.assertEqual(pickup['dataPrevista'], '2026-09-25')
self.assertEqual(pickup['pagamento'], {'formaRecebimento': {'id': RECEIPT_METHODS['pix']},
'parcelas': [{'dias': 0, 'data': '2026-09-24', 'valor': 84.72, 'formaRecebimento': {'id': RECEIPT_METHODS['pix']}}]})
# Delivery: the Correios contract's PAC or SEDEX, or Jadlog; the date in working days.
for service, method, frete in (('pac', 78, 781), ('sedex', 78, 782), ('jadlog', 80, 801)):
order = {**PAID['order'], 'freight': {'service': service, 'total_cents': 1500, 'days': 6}}
sent = order_payload({**PAID, 'order': order, 'payment': {'method': 'card'}}, 1, thursday,
shipping=self.tiny.shipping)
self.assertEqual(sent['transportador'], {'fretePorConta': 'R', 'formaEnvio': {'id': method},
'formaFrete': {'id': frete}}, service)
self.assertEqual(sent['dataPrevista'], '2026-10-02')
self.assertEqual(sent['pagamento']['formaRecebimento'], {'id': RECEIPT_METHODS['card']})
# Looked up once per service.
self.assertEqual(self.calls.count(('GET', '/formas-envio/78')), 2)
# A test order, or a carrier Tiny does not have: the order still goes, without them.
plain = order_payload(PAID, 1, thursday, shipping=self.tiny.shipping)
self.assertNotIn('transportador', plain)
self.assertNotIn('pagamento', plain)
def test_pickup_forma_de_envio_is_found_by_name(self):
from app.tiny import check, find_pickup
with mock.patch.dict(os.environ, {'TINY_FORMA_ENVIO_RETIRADA': ''}):
self.tiny.deliver('k1', PICKUP)
self.assertEqual(self.orders[0]['transportador'], {'formaEnvio': {'id': 77}})
self.assertEqual(self.orders[0]['transportador']['formaEnvio'], {'id': 77})
self.assertEqual(check(orders=self.tiny)['forma de envio de retirada'], 'ok')
# Dropstar's account also has "Retirar na loja": the exact name wins.
self.methods['79'] = {'id': 79, 'nome': 'Retirar na loja', 'tipo': '6'}