feat: customer e-mails in the Site's look, and an order confirmation
All checks were successful
Build and deploy / Validate source (push) Successful in 49s
Build and deploy / Integration suite on a real stack (push) Successful in 3m23s
Build and deploy / Secret scan and release gate (push) Successful in 10s
Build and deploy / Publish images (push) Successful in 1m17s
All checks were successful
Build and deploy / Validate source (push) Successful in 49s
Build and deploy / Integration suite on a real stack (push) Successful in 3m23s
Build and deploy / Secret scan and release gate (push) Successful in 10s
Build and deploy / Publish images (push) Successful in 1m17s
The account e-mails (signup and e-mail change codes, new password, an address that already has an account, the changed-e-mail notice) gain an HTML version beside their plain text: the DROPSTAR header, a white card, orange buttons, the customer greeted by first name. Built with tables and inline styles only, so Gmail, Outlook and phone apps show it the same. A paid order now also e-mails the customer "Recebemos seu pedido #N": the items, delivery and total, the stages to come, and a link to the order in the account. Not for an operator's test order. A code's or a recovery link's HTML is erased with its text once sent. The team's alerts stay plain text. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -140,6 +140,8 @@ def signup(tag):
|
||||
with db.connect() as c:
|
||||
assert not c.execute('SELECT 1 FROM dtf_local.accounts WHERE email=%s', (address,)).fetchone()
|
||||
first = code_of(c, address)
|
||||
html = queued(c, address, 'code')[-1]['html']
|
||||
assert ' '.join(first) in html and 'Confirme seu e-mail' in html, html[:200]
|
||||
# The password is stored hashed from the first step.
|
||||
assert c.execute('SELECT password_hash FROM dtf_local.account_signups WHERE id=%s',
|
||||
(started['verify'],)).fetchone()['password_hash'].startswith('scrypt-v2$')
|
||||
@@ -240,14 +242,20 @@ def smtp_delivery(tag):
|
||||
MAIL_FROM='DTF Dropstar <nao-responda@dropstar.test>')
|
||||
with db.connect() as c:
|
||||
# Not due yet, so the stack's own worker leaves them to this test.
|
||||
ids = [c.execute('''INSERT INTO dtf_local.mail_queue(kind,to_addr,subject,body,available_at)
|
||||
VALUES(%s,%s,%s,%s,now()+interval '1 hour') RETURNING id''',
|
||||
(kind, to, subject, body)).fetchone()['id']
|
||||
for kind, subject, body in (('reset', 'Crie uma nova senha · DTF Dropstar', 'link secreto ção'),
|
||||
('alert', 'Pedido pago', 'olá equipe'),
|
||||
('code', '123456 é o seu código', 'código 123456'))]
|
||||
ids = [c.execute('''INSERT INTO dtf_local.mail_queue(kind,to_addr,subject,body,html,available_at)
|
||||
VALUES(%s,%s,%s,%s,%s,now()+interval '1 hour') RETURNING id''',
|
||||
(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),
|
||||
('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
|
||||
# A customer message goes as plain text and HTML, the client picks.
|
||||
coded = sink.messages[2][1]
|
||||
assert coded.get_content_type() == 'multipart/alternative', coded.get_content_type()
|
||||
assert coded.get_body(('plain',)).get_content().strip() == 'código 123456'
|
||||
assert '<p>código 123456</p>' in coded.get_body(('html',)).get_content()
|
||||
rcpt, first = sink.messages[0]
|
||||
assert to in rcpt[0] and first['Subject'] == 'Crie uma nova senha · DTF Dropstar'
|
||||
assert first['From'] == 'DTF Dropstar <nao-responda@dropstar.test>'
|
||||
@@ -256,7 +264,7 @@ def smtp_delivery(tag):
|
||||
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.
|
||||
assert sent['reset']['sent_at'] and sent['reset']['body'] == ''
|
||||
assert sent['code']['sent_at'] and sent['code']['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'
|
||||
|
||||
# A server that does not answer: retried later, with the error kept.
|
||||
@@ -306,6 +314,11 @@ def alerts(tag):
|
||||
[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')
|
||||
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')
|
||||
# The test message goes to whoever asked for it.
|
||||
sent = su.call('/operator/mail/test', {}, operator=True)
|
||||
|
||||
Reference in New Issue
Block a user