diff options
Diffstat (limited to 'internal/app/app_test.go')
| -rw-r--r-- | internal/app/app_test.go | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/internal/app/app_test.go b/internal/app/app_test.go index e770060..d430e11 100644 --- a/internal/app/app_test.go +++ b/internal/app/app_test.go @@ -291,6 +291,8 @@ func TestMalformedCEP(t *testing.T) { } } +// A CEP in a numeric band the Correios never handed to any municipality: the +// 404 carries no faixa, and the answer is the one the bot has always given. func TestCEPNotFound(t *testing.T) { tg, api := newFakeTelegram(t), newFakeCEPIS(t) tg.push(privateMessage(1, 555, "99999999")) @@ -300,6 +302,54 @@ func TestCEPNotFound(t *testing.T) { if !strings.Contains(sent[0].Text, "não encontrado") { t.Fatalf("reply = %q, want a not-found message", sent[0].Text) } + if strings.Contains(sent[0].Text, "cairia em") { + t.Fatalf("named a municipality the API did not send: %q", sent[0].Text) + } +} + +// The "-000" guess for Areal/RJ, which never received that number. The reply +// still says the CEP does not exist, and adds where it would have been. +func TestCEPNotFoundNamesTheMunicipality(t *testing.T) { + tg, api := newFakeTelegram(t), newFakeCEPIS(t) + tg.push(privateMessage(1, 555, "25845-000")) + start(t, testConfig(tg, api)) + + sent := waitForMessages(t, tg, 1) + text := sent[0].Text + for _, needed := range []string{ + "não encontrado", "Areal/RJ", "118 CEPs", "25845-001", "25849-899", "esparsa", + } { + if !strings.Contains(text, needed) { + t.Fatalf("reply is missing %q: %q", needed, text) + } + } + if strings.Contains(text, "📮") { + t.Fatalf("a failure must not be formatted as a hit: %q", text) + } + if strings.Contains(text, "25845-000") { + t.Fatalf("the reply hands back the CEP that just failed: %q", text) + } +} + +func TestInlineNotFoundNamesTheMunicipality(t *testing.T) { + tg, api := newFakeTelegram(t), newFakeCEPIS(t) + tg.push(inlineQuery(1, 555, "25845000")) + start(t, testConfig(tg, api)) + + waitFor(t, "inline answer", 10*time.Second, func() bool { return len(tg.inlineAnswers()) >= 1 }) + results := tg.inlineAnswers()[0].Results + if len(results) != 1 { + t.Fatalf("got %d results, want 1", len(results)) + } + if results[0].Title != "CEP não encontrado" { + t.Fatalf("title = %q", results[0].Title) + } + if !strings.Contains(results[0].Description, "Areal/RJ") { + t.Fatalf("description = %q, want the municipality named", results[0].Description) + } + if !strings.Contains(results[0].InputMessageContent.MessageText, "118 CEPs") { + t.Fatalf("message = %q", results[0].InputMessageContent.MessageText) + } } func TestAPIServerError(t *testing.T) { |