package render

import (
	"testing"

	"leadb2b.org/internal/api"
)

func TestNormalizeCEPDigits(t *testing.T) {
	if got := NormalizeCEPDigits("11667-483"); got != "11667483" {
		t.Fatalf("got %q", got)
	}
	if NormalizeCEPDigits("123") != "" {
		t.Fatal("expected invalid")
	}
}

func TestFilterItemsByCEP(t *testing.T) {
	items := []api.EstabelecimentoOut{
		{CNPJ: "1", CEP: "11667483"},
		{CNPJ: "2", CEP: "11667-483"},
		{CNPJ: "3", CEP: "11660650"},
	}
	out := FilterItemsByCEP(items, "11667483")
	if len(out) != 2 {
		t.Fatalf("got %d items", len(out))
	}
}

func TestApplySearchDefaults_noForcedFilters(t *testing.T) {
	p := ApplySearchDefaults(SearchForm{CEP: "11667483"})
	if len(p.SituacaoCadastral) != 0 || p.IdentificadorMatrizFilial != "" {
		t.Fatalf("unexpected defaults: situacao=%v unidade=%q", p.SituacaoCadastral, p.IdentificadorMatrizFilial)
	}
}
