summaryrefslogtreecommitdiffstats
path: root/test/cepis/health_test.exs
diff options
context:
space:
mode:
Diffstat (limited to 'test/cepis/health_test.exs')
-rw-r--r--test/cepis/health_test.exs45
1 files changed, 45 insertions, 0 deletions
diff --git a/test/cepis/health_test.exs b/test/cepis/health_test.exs
new file mode 100644
index 0000000..47a49c2
--- /dev/null
+++ b/test/cepis/health_test.exs
@@ -0,0 +1,45 @@
+defmodule Cepis.HealthTest do
+ use Cepis.ServerCase
+
+ test "reads the live database identifier", %{server: server, client: client} do
+ body =
+ json(%{
+ "status" => "ok",
+ "dne" => "26071",
+ "ceps" => 1_596_168,
+ "geo" => 894_489,
+ "base_gerada_em" => "2026-07-24T03:48:28Z"
+ })
+
+ FakeServer.respond(server, "/health", {200, body, []})
+
+ assert {:ok, health} = Cepis.health(client)
+ assert Cepis.Health.ok?(health)
+ assert health.dne == "26071"
+ assert health.ceps == 1_596_168
+ assert health.geo == 894_489
+ assert health.base_gerada_em == "2026-07-24T03:48:28Z"
+ end
+
+ test "a degraded API is a diagnosis, not a failure", %{server: server, client: client} do
+ body = json(%{"status" => "degradado", "dne" => "", "ceps" => 0, "geo" => 0})
+ FakeServer.respond(server, "/health", {503, body, []})
+
+ assert {:ok, health} = Cepis.health(client)
+ refute Cepis.Health.ok?(health)
+ assert health.status == "degradado"
+ end
+
+ test "a 503 on /health is not retried", %{server: server, client: client} do
+ FakeServer.respond(server, "/health", {503, json(%{"status" => "degradado"}), []})
+
+ assert {:ok, _health} = Cepis.health(client)
+ assert FakeServer.count(server, "/health") == 1
+ end
+
+ test "the bang variant returns the struct", %{server: server, client: client} do
+ FakeServer.respond(server, "/health", {200, json(%{"status" => "ok"}), []})
+
+ assert %Cepis.Health{status: "ok"} = Cepis.health!(client)
+ end
+end