feat(mail): redesign the email templates in the Lincodex style

This commit is contained in:
shira committed 2026-10-10 02:21:45 +03:00
1 parent 3c4acff803
commit a0869d81a1
26 files changed
+363 -103

No files matched your search

+16 -15
View File
@@ -42,8 +42,9 @@ const (
deliveryAccount = "integration"
deliveryOtherAccount = "integration-eu"
deliveryMessageID = "4ef9a417-02e9-4d39-ad75-9611e0fcc33c"
// deliveryV2Version is a template version that exists only in this test.
deliveryV2Version = "notification.v2"
// deliveryLaterVersion is a template version that exists only in this test:
// it is later than the committed notification.v2.
deliveryLaterVersion = "notification.v3"
// renamedDeliveryConsumer replays requests as a renamed consumer would:
// the dedup markers of the real name do not apply to it.
renamedDeliveryConsumer = "notification_delivery_replay"
@@ -91,12 +92,12 @@ func (buffer *syncBuffer) String() string {
return buffer.buffer.String()
}
// v2Renderer stands for a later template version: it renders other copy
// under notification.v2 without touching the committed templates.
type v2Renderer struct{}
// laterVersionRenderer stands for a later template version: it renders other
// copy under deliveryLaterVersion without touching the committed templates.
type laterVersionRenderer struct{}
func (v2Renderer) RenderNotification(mailtemplate.NotificationData) (domain.MailContent, error) {
return domain.NewMailContent(domain.MailKindNotification, deliveryV2Version,
func (laterVersionRenderer) RenderNotification(mailtemplate.NotificationData) (domain.MailContent, error) {
return domain.NewMailContent(domain.MailKindNotification, deliveryLaterVersion,
"Новая версия письма", "Текст новой версии шаблона.\n", "<p>Текст новой версии шаблона.</p>\n")
}
@@ -181,7 +182,7 @@ func TestMailDelivery(t *testing.T) {
t.Fatal("the delivery does not name the event it came from")
case delivery.RecipientUserID() != recipient.ID || delivery.Recipient().Address() != deliveryRecipientAddress:
t.Fatal("the delivery is not addressed to the recipient account")
case delivery.Kind() != domain.MailKindNotification || content.TemplateVersion() != "notification.v1":
case delivery.Kind() != domain.MailKindNotification || content.TemplateVersion() != "notification.v2":
t.Fatalf("delivery kind %s, version %s", delivery.Kind(), content.TemplateVersion())
case delivery.ProviderAccount() != harness.account:
t.Fatal("the delivery is not pinned to the configured provider account")
@@ -203,22 +204,22 @@ func TestMailDelivery(t *testing.T) {
harness.apply(ctx, t, notification.DeliveryConsumerName, harness.handler, firstEvent)
original := harness.getDelivery(ctx, t, pool, first)
// The template moves to notification.v2. A new request gets the new
// The template moves on to a later version. A new request gets the new
// version; a replay of the first request under another consumer name
// finds the request consumed and stores nothing.
v2Handler := harness.newHandler(v2Renderer{})
laterHandler := harness.newHandler(laterVersionRenderer{})
second := harness.requestNotification(ctx, t, recipient)
harness.apply(ctx, t, notification.DeliveryConsumerName, v2Handler, harness.outboxEvent(ctx, t, second))
harness.apply(ctx, t, renamedDeliveryConsumer, v2Handler, firstEvent)
harness.apply(ctx, t, notification.DeliveryConsumerName, laterHandler, harness.outboxEvent(ctx, t, second))
harness.apply(ctx, t, renamedDeliveryConsumer, laterHandler, firstEvent)
assertRowCount(ctx, t, pool, pgx.Identifier{"deliveries"}, 2)
if got := harness.getDelivery(ctx, t, pool, second).Content(); got.TemplateVersion() != deliveryV2Version {
t.Fatalf("the new request rendered %s, want %s", got.TemplateVersion(), deliveryV2Version)
if got := harness.getDelivery(ctx, t, pool, second).Content(); got.TemplateVersion() != deliveryLaterVersion {
t.Fatalf("the new request rendered %s, want %s", got.TemplateVersion(), deliveryLaterVersion)
}
// Read through a fresh pool and store, as another instance would.
kept := harness.getDelivery(ctx, t, newPoolFor(ctx, t, env.Config.DatabaseURL), first).Content()
want := original.Content()
if kept.TemplateVersion() != "notification.v1" || kept.Subject() != want.Subject() ||
if kept.TemplateVersion() != "notification.v2" || kept.Subject() != want.Subject() ||
kept.Text() != want.Text() || kept.HTML() != want.HTML() || kept.Hash() != want.Hash() {
t.Fatal("the stored delivery changed after the template version changed")
}