summaryrefslogtreecommitdiffstats
path: root/test/support
diff options
context:
space:
mode:
authorMurilo Ijanc <[email protected]>2026-07-27 20:21:38 -0300
committerMurilo Ijanc <[email protected]>2026-07-27 20:21:38 -0300
commitf9f1d248f3a3a2b781507195e00527db1e39f8d3 (patch)
treef99b24f5923e436339b8e8ddb8af6ac854488439 /test/support
parent075683ff44a254e99adbad8a0372ef80ff06151a (diff)
downloadelixir-071f0ea39f80d7dc8a81331e56ec1d9bb936893e.tar.gz
Carry the municipality on a not-found CEPHEADv0.2.0main
A CEP that fails is rarely a random number: it is usually someone who knows the city and guessed, most often the -000 that 957 municipalities never received. The API now answers 404 with an optional faixa naming the municipality that number would have belonged to, so the caller can say "you are in Areal, but not at that number" instead of a dead end. It stays an error. Cepis.Faixa hangs off Cepis.NotFoundError as context for the failure, never as an address, and parsing is deliberately tolerant: an absent, truncated or unreadable faixa yields nil rather than costing the caller a clean definitive answer. The bounds are the smallest and largest CEP that actually exist there, not the range the Correios publish, and almost nothing between them is valid — hence ceps and density/1, so nobody reads the pair as a list of numbers to try.
Diffstat (limited to 'test/support')
-rw-r--r--test/support/server_case.ex20
1 files changed, 20 insertions, 0 deletions
diff --git a/test/support/server_case.ex b/test/support/server_case.ex
index a64bb05..8af08cb 100644
--- a/test/support/server_case.ex
+++ b/test/support/server_case.ex
@@ -44,8 +44,28 @@ defmodule Cepis.ServerCase do
@csv_header "cep,logradouro,complemento,unidade,bairro,localidade,uf,estado,regiao,ibge,gia,ddd,siafi"
+ @faixa %{
+ "localidade" => "Areal",
+ "uf" => "RJ",
+ "estado" => "Rio de Janeiro",
+ "regiao" => "Sudeste",
+ "ibge" => "3300225",
+ "cep_ini" => "25845001",
+ "cep_fim" => "25849899",
+ "ceps" => 118
+ }
+
def address_fixture(extra \\ %{}), do: Map.merge(@address, extra)
+ def faixa_fixture(extra \\ %{}), do: Map.merge(@faixa, extra)
+
+ def not_found_fixture(extra \\ %{}) do
+ Map.merge(
+ %{"erro" => "cep_nao_encontrado", "mensagem" => "CEP não existe na base do DNE"},
+ extra
+ )
+ end
+
def json(term), do: IO.iodata_to_binary(:json.encode(term))
def csv(rows), do: Enum.join([@csv_header | rows], "\n") <> "\n"