package email

import (
	"context"
	"testing"

	"kra/internal/config"
)

func TestDefaultRecipientsIgnoreEmptyConfiguration(t *testing.T) {
	runtime := config.NewStore(&config.Config{Data: &config.Data{}, Admin: &config.Admin{Email: &config.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 := config.NewStore(&config.Config{Data: &config.Data{}, Admin: &config.Admin{Email: &config.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")
	}
}
