package email

import (
	"errors"
	"strings"
	"testing"
)

func TestExplainSMTP(t *testing.T) {
	// The real refusal, from an operator's Outlook account.
	outlook := errors.New("SMTP AUTH failed: 535 5.7.139 Authentication unsuccessful, basic authentication is disabled.")
	if got := explainSMTP(outlook); !strings.Contains(got, "Microsoft has switched off") {
		t.Errorf("the Microsoft policy refusal is not explained: %q", got)
	}
	// A plain wrong password must NOT claim a policy: the advice would send the
	// operator to an administrator over a typo.
	wrong := errors.New("535 5.7.8 authentication failed")
	got := explainSMTP(wrong)
	if strings.Contains(got, "Microsoft") {
		t.Errorf("a wrong password was explained as a Microsoft policy: %q", got)
	}
	if !strings.Contains(got, "rejected the username") {
		t.Errorf("a wrong password is not explained: %q", got)
	}
	// Anything else is left to speak for itself.
	if got := explainSMTP(errors.New("dial tcp: i/o timeout")); got != "" {
		t.Errorf("an unrelated error got an explanation: %q", got)
	}
}
