package mailer

import (
	"bytes"
	"context"
	"log/slog"
	"strings"
	"testing"
)

// TestLogMailerWritesEmailToLog pins the dev fallback contract: with no SMTP
// configured, the email (including any link/token in the body) must still
// reach the developer via the structured log, clearly marked as unsent.
func TestLogMailerWritesEmailToLog(t *testing.T) {
	var buf bytes.Buffer
	m := &LogMailer{Log: slog.New(slog.NewTextHandler(&buf, nil))}

	if err := m.Send(context.Background(), "buyer@erp.com", "Reset Kata Sandi", "link: https://example.test/reset-password?token=ABC123"); err != nil {
		t.Fatalf("LogMailer.Send returned error: %v", err)
	}

	out := buf.String()
	for _, want := range []string{"SMTP not configured", "buyer@erp.com", "Reset Kata Sandi", "token=ABC123"} {
		if !strings.Contains(out, want) {
			t.Fatalf("log output missing %q: %s", want, out)
		}
	}
}
