feat: the team no longer gets alert e-mails; the Kanban user form drops the option
All checks were successful
Build and deploy / Validate source (push) Successful in 47s
Build and deploy / Integration suite on a real stack (push) Successful in 3m38s
Build and deploy / Secret scan and release gate (push) Successful in 9s
Build and deploy / Publish images (push) Successful in 1m20s
All checks were successful
Build and deploy / Validate source (push) Successful in 47s
Build and deploy / Integration suite on a real stack (push) Successful in 3m38s
Build and deploy / Secret scan and release gate (push) Successful in 9s
Build and deploy / Publish images (push) Successful in 1m20s
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
"""E-mail: a customer's password recovery, and the team's alerts.
|
||||
"""E-mail: a customer's password recovery, signup codes and order confirmation.
|
||||
|
||||
Run inside the API container: python -m tests.mail_test
|
||||
The local stack keeps e-mail in the database (MAIL_ADAPTER=log); the SMTP
|
||||
@@ -247,7 +247,7 @@ def smtp_delivery(tag):
|
||||
(kind, to, subject, body, html)).fetchone()['id']
|
||||
for kind, subject, body, html in (
|
||||
('reset', 'Crie uma nova senha · DTF Dropstar', 'link secreto ção', None),
|
||||
('alert', 'Pedido pago', 'olá equipe', None),
|
||||
('test', 'Teste de e-mail', 'olá equipe', None),
|
||||
('code', '123456 é o seu código', 'código 123456', '<p>código 123456</p>'))]
|
||||
mail.send_pending(db.connect, ids=ids)
|
||||
assert len(sink.messages) == 3, sink.messages
|
||||
@@ -261,17 +261,17 @@ def smtp_delivery(tag):
|
||||
assert first['From'] == 'DTF Dropstar <nao-responda@dropstar.test>'
|
||||
assert first.get_content().strip() == 'link secreto ção'
|
||||
with db.connect() as c:
|
||||
sent = {r['kind']: r for r in queued(c, to, 'reset') + queued(c, to, 'alert') + queued(c, to, 'code')}
|
||||
# A recovery link or a signup code is erased once sent; an alert keeps its text.
|
||||
sent = {r['kind']: r for r in queued(c, to, 'reset') + queued(c, to, 'test') + queued(c, to, 'code')}
|
||||
# A recovery link or a signup code is erased once sent; other messages keep their text.
|
||||
assert sent['reset']['sent_at'] and sent['reset']['body'] == ''
|
||||
assert sent['code']['sent_at'] and sent['code']['body'] == '' and sent['code']['html'] is None
|
||||
assert sent['alert']['sent_at'] and sent['alert']['body'] == 'olá equipe'
|
||||
assert sent['test']['sent_at'] and sent['test']['body'] == 'olá equipe'
|
||||
|
||||
# A server that does not answer: retried later, with the error kept.
|
||||
os.environ['SMTP_PORT'] = '1'
|
||||
with db.connect() as c:
|
||||
failing = c.execute('''INSERT INTO dtf_local.mail_queue(kind,to_addr,subject,body,available_at)
|
||||
VALUES('alert',%s,'x','y',now()+interval '1 hour') RETURNING id''', (to,)).fetchone()['id']
|
||||
VALUES('test',%s,'x','y',now()+interval '1 hour') RETURNING id''', (to,)).fetchone()['id']
|
||||
mail.send_pending(db.connect, ids=[failing])
|
||||
with db.connect() as c:
|
||||
row = c.execute('SELECT * FROM dtf_local.mail_queue WHERE id=%s', (failing,)).fetchone()
|
||||
@@ -288,38 +288,27 @@ def smtp_delivery(tag):
|
||||
sink.shutdown()
|
||||
|
||||
|
||||
def alerts(tag):
|
||||
"""Who gets the team's alerts, and that a paid order sends one."""
|
||||
def order_confirmation(tag):
|
||||
"""A paid order sends the customer the confirmation, and the team nothing."""
|
||||
su = Client()
|
||||
su.call('/session')
|
||||
wants, quiet, away = (f'{n}-{tag}@example.test' for n in ('alertas', 'quieto', 'fora'))
|
||||
for address, on, active in ((wants, True, True), (quiet, False, True), (away, True, False)):
|
||||
su.call('/operator/users', {'name': address, 'email': address, 'role': 'gestao', 'password': PASSWORD,
|
||||
'alerts': on, 'active': active}, operator=True)
|
||||
users = {u['email']: u for u in su.call('/operator/users', operator=True)['users']}
|
||||
assert users[wants]['alerts'] is True and users[quiet]['alerts'] is False
|
||||
board = su.call('/operator/board', operator=True)
|
||||
assert board['providers']['mail']['adapter'] == 'log' and board['providers']['mail']['alerts'] >= 1
|
||||
|
||||
customer = Client()
|
||||
customer.call('/session')
|
||||
uid = upload_bytes(customer, b'MAIL ALERT ARTWORK')
|
||||
uid = upload_bytes(customer, b'MAIL ORDER ARTWORK')
|
||||
item = item_spec('file', '1.2', 0, uid)
|
||||
quote = customer.call('/quotes', {'request_key': str(uuid4()), 'items': [item],
|
||||
'customer': {'cnpj': CNPJ, 'zap': '16999990000', 'mail': f'alerta-{tag}@example.test'},
|
||||
'customer': {'cnpj': CNPJ, 'zap': '16999990000', 'mail': f'pedido-{tag}@example.test'},
|
||||
'freight': {'service': 'pickup'}})
|
||||
approved_quote(customer, quote, [item])
|
||||
order = customer.call('/orders/dev-paid', {'quote_id': quote['id']})
|
||||
with db.connect() as c:
|
||||
[alert] = [r for r in queued(c, wants, 'alert') if f"#{order['number']}" in r['subject']]
|
||||
assert 'pago' in alert['subject'] and '11.222.333/0001-81' in alert['body'] and '1,2 m' in alert['body']
|
||||
assert 'Abrir no Kanban: http' in alert['body']
|
||||
# The customer gets the confirmation, with the order in the account.
|
||||
[confirmed] = queued(c, f'alerta-{tag}@example.test', 'order')
|
||||
[confirmed] = queued(c, f'pedido-{tag}@example.test', 'order')
|
||||
assert confirmed['subject'] == f"Recebemos seu pedido #{order['number']} · DTF Dropstar"
|
||||
assert f"/conta/pedidos?order={order['id']}" in confirmed['body'] and 'Retirada em Franca-SP' in confirmed['body']
|
||||
assert f"Recebemos seu pedido #{order['number']}" in confirmed['html'] and 'Ver meu pedido' in confirmed['html']
|
||||
assert not queued(c, quiet, 'alert') and not queued(c, away, 'alert')
|
||||
assert not c.execute("SELECT 1 FROM dtf_local.mail_queue WHERE kind='alert' AND subject LIKE %s",
|
||||
(f"%#{order['number']} %",)).fetchone()
|
||||
# The test message goes to whoever asked for it.
|
||||
sent = su.call('/operator/mail/test', {}, operator=True)
|
||||
with db.connect() as c:
|
||||
@@ -393,11 +382,11 @@ def run():
|
||||
signup(tag)
|
||||
email_change(tag)
|
||||
smtp_delivery(tag)
|
||||
order, quote = alerts(tag)
|
||||
order, quote = order_confirmation(tag)
|
||||
made.append((order, quote))
|
||||
claimed_orders(tag, made)
|
||||
print('PASS: password recovery by a one-time link, signup and e-mail changes confirmed by an e-mailed code, '
|
||||
'SMTP delivery and retry, alerts to who asked for them, guest orders brought by CPF/CNPJ and e-mail')
|
||||
'SMTP delivery and retry, order confirmation and no team alerts, guest orders brought by CPF/CNPJ and e-mail')
|
||||
finally:
|
||||
with db.connect() as c:
|
||||
for order, quote in made:
|
||||
|
||||
Reference in New Issue
Block a user