test: StatusLive.Index health_score 3/4 render paths
This commit is contained in:
parent
d02178d417
commit
1b8d359f41
1 changed files with 59 additions and 0 deletions
|
|
@ -13,6 +13,65 @@ defmodule AprsmeWeb.StatusLive.IndexTest do
|
|||
assert html =~ "APRS-IS Connection"
|
||||
end
|
||||
|
||||
test "renders health score 3 (stable under 1 hour)", %{conn: conn} do
|
||||
_ =
|
||||
case :ets.info(:query_cache) do
|
||||
:undefined -> :ets.new(:query_cache, [:named_table, :public, :set])
|
||||
_ -> :ok
|
||||
end
|
||||
|
||||
status = %{
|
||||
connected: true,
|
||||
server: "test.aprs.test",
|
||||
port: 14_580,
|
||||
connected_at: DateTime.add(DateTime.utc_now(), -1000, :second),
|
||||
uptime_seconds: 1000,
|
||||
login_id: "N0CALL",
|
||||
filter: "r/33/-96/100",
|
||||
packet_stats: %{total_packets: 10, last_packet_at: DateTime.utc_now(), packets_per_second: 1},
|
||||
stored_packet_count: 50,
|
||||
oldest_packet_timestamp: DateTime.add(DateTime.utc_now(), -3600, :second)
|
||||
}
|
||||
|
||||
Aprsme.Cache.put(:query_cache, "aprs_status", status)
|
||||
|
||||
{:ok, _lv, html} = live(conn, ~p"/status", on_error: :warn)
|
||||
# Uptime 1000s < 3600 → score 3. 50 stored packets.
|
||||
assert html =~ "System Status"
|
||||
assert html =~ "Connected"
|
||||
|
||||
Aprsme.Cache.del(:query_cache, "aprs_status")
|
||||
end
|
||||
|
||||
test "renders health score 4 (stable under 1 day)", %{conn: conn} do
|
||||
_ =
|
||||
case :ets.info(:query_cache) do
|
||||
:undefined -> :ets.new(:query_cache, [:named_table, :public, :set])
|
||||
_ -> :ok
|
||||
end
|
||||
|
||||
status = %{
|
||||
connected: true,
|
||||
server: "test",
|
||||
port: 14_580,
|
||||
connected_at: DateTime.add(DateTime.utc_now(), -10_000, :second),
|
||||
# Uptime 10,000s is between 3600 and 86_400 → score 4.
|
||||
uptime_seconds: 10_000,
|
||||
login_id: "N0CALL",
|
||||
filter: "r/0/0/100",
|
||||
packet_stats: %{total_packets: 1, last_packet_at: nil, packets_per_second: 0},
|
||||
stored_packet_count: 0,
|
||||
oldest_packet_timestamp: nil
|
||||
}
|
||||
|
||||
Aprsme.Cache.put(:query_cache, "aprs_status", status)
|
||||
|
||||
{:ok, _lv, html} = live(conn, ~p"/status", on_error: :warn)
|
||||
assert html =~ "Connected"
|
||||
|
||||
Aprsme.Cache.del(:query_cache, "aprs_status")
|
||||
end
|
||||
|
||||
test "renders the connected-path template when cache has a live status", %{conn: conn} do
|
||||
# Ensure the cache ETS table exists for test.
|
||||
_ =
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue