diff options
Diffstat (limited to 'internal/bot/format_test.go')
| -rw-r--r-- | internal/bot/format_test.go | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/internal/bot/format_test.go b/internal/bot/format_test.go index 513db36..8e10b3e 100644 --- a/internal/bot/format_test.go +++ b/internal/bot/format_test.go @@ -7,8 +7,6 @@ import ( "testing" cepis "cep.is/go" - - "cep.is/telegrambot/internal/lookup" ) func decodeAddress(t *testing.T, body string) *cepis.Address { @@ -118,11 +116,14 @@ func TestErrorMessagesAreDistinct(t *testing.T) { } } -func notFound(faixa *lookup.Faixa) error { - return &lookup.NotFoundError{Faixa: faixa, Err: cepis.ErrCEPNotFound} +// notFound builds the error the client library returns for a CEP absent from +// the DNE, with the municipality the API named on the 404 — or without one, +// for a CEP in a band no municipality owns. +func notFound(faixa *cepis.Faixa) error { + return &cepis.Error{Kind: cepis.ErrCEPNotFound, Faixa: faixa} } -var areal = &lookup.Faixa{ +var areal = &cepis.Faixa{ Localidade: "Areal", UF: "RJ", Estado: "Rio de Janeiro", Regiao: "Sudeste", IBGE: "3300225", CEPIni: "25845001", CEPFim: "25849899", CEPs: 118, } @@ -168,7 +169,7 @@ func TestNotFoundWithoutFaixaIsUnchanged(t *testing.T) { for name, err := range map[string]error{ "plain sentinel": cepis.ErrCEPNotFound, "no faixa": notFound(nil), - "empty faixa": notFound(&lookup.Faixa{}), + "empty faixa": notFound(&cepis.Faixa{}), } { if got := ErrorMessage(err); got != want { t.Fatalf("%s:\n got %q\nwant %q", name, got, want) @@ -177,7 +178,7 @@ func TestNotFoundWithoutFaixaIsUnchanged(t *testing.T) { } func TestNotFoundEscapesTheMunicipality(t *testing.T) { - text := ErrorMessage(notFound(&lookup.Faixa{ + text := ErrorMessage(notFound(&cepis.Faixa{ Localidade: "Santa <b>Rita</b> & Cia", UF: "M&G", CEPIni: "25845001", CEPFim: "25849899", CEPs: 2, })) @@ -194,32 +195,32 @@ func TestNotFoundEscapesTheMunicipality(t *testing.T) { // take the sentence down with it. func TestNotFoundDegradesFieldByField(t *testing.T) { cases := map[string]struct { - faixa *lookup.Faixa + faixa *cepis.Faixa present []string absent []string }{ "no count": { - faixa: &lookup.Faixa{Localidade: "Areal", UF: "RJ", CEPIni: "25845001", CEPFim: "25849899"}, + faixa: &cepis.Faixa{Localidade: "Areal", UF: "RJ", CEPIni: "25845001", CEPFim: "25849899"}, present: []string{"Areal/RJ", "25845-001", "25849-899", "esparsa"}, absent: []string{"CEPs,"}, }, "no range": { - faixa: &lookup.Faixa{Localidade: "Areal", UF: "RJ", CEPs: 118}, + faixa: &cepis.Faixa{Localidade: "Areal", UF: "RJ", CEPs: 118}, present: []string{"Areal/RJ", "118 CEPs"}, absent: []string{"<code>", "esparsa"}, }, "only the name": { - faixa: &lookup.Faixa{Localidade: "Areal"}, + faixa: &cepis.Faixa{Localidade: "Areal"}, present: []string{"cairia em <b>Areal</b>."}, absent: []string{"<code>", "esparsa", "Areal/"}, }, "single CEP": { - faixa: &lookup.Faixa{Localidade: "Vila", UF: "SP", CEPIni: "12345678", CEPFim: "12345678", CEPs: 1}, + faixa: &cepis.Faixa{Localidade: "Vila", UF: "SP", CEPIni: "12345678", CEPFim: "12345678", CEPs: 1}, present: []string{"1 CEP."}, absent: []string{"12345-678"}, }, "unusable range": { - faixa: &lookup.Faixa{Localidade: "Areal", UF: "RJ", CEPIni: "abc", CEPFim: "2584", CEPs: 118}, + faixa: &cepis.Faixa{Localidade: "Areal", UF: "RJ", CEPIni: "abc", CEPFim: "2584", CEPs: 118}, present: []string{"118 CEPs."}, absent: []string{"abc", "2584"}, }, @@ -251,7 +252,7 @@ func TestInlineErrorDescriptionNamesTheMunicipality(t *testing.T) { } // Titles and descriptions are plain text: escaping them would show the // entities to the user. - got := inlineErrorDescription(notFound(&lookup.Faixa{Localidade: "Santa & Cia", UF: "SP"})) + got := inlineErrorDescription(notFound(&cepis.Faixa{Localidade: "Santa & Cia", UF: "SP"})) if !strings.Contains(got, "Santa & Cia/SP") { t.Fatalf("description = %q", got) } |