package email

import (
	"context"
	"testing"

	"kra/internal/conf"
)

func TestDefaultRecipientsIgnoreEmptyConfiguration(t *testing.T) {
	runtime := conf.NewRuntime(&conf.Data{}, &conf.AdminBackend{Email: &conf.AdminBackend_Email{To: "  "}})
	repo := &emailRepo{runtime: runtime}
	if got := repo.DefaultRecipients(); len(got) != 0 {
		t.Fatalf("DefaultRecipients() = %#v, want empty", got)
	}
}

func TestSendRejectsEmptyRecipientsBeforeNetworkDial(t *testing.T) {
	runtime := conf.NewRuntime(&conf.Data{}, &conf.AdminBackend{Email: &conf.AdminBackend_Email{Host: "smtp.example.com", From: "from@example.com", Secret: "secret", Port: 25}})
	repo := &emailRepo{runtime: runtime}
	if err := repo.Send(context.Background(), []string{"  ", ""}, "subject", "body"); err == nil {
		t.Fatal("Send() accepted empty recipients")
	}
}
