prop/test/microwaveprop/format_test.exs
Graham McIntire 0c3be97abb
Some checks failed
Build base image / Build and push base image (push) Successful in 3m10s
Build and Push / Build and Push Docker Image (push) Failing after 14s
Build prop-grid-rs / Test, build, push (push) Successful in 12m52s
fix: resolve 27 security, architecture, test, and performance audit findings
P0 (security-critical):
- Gate CSV/ADIF upload tabs behind authentication, add 30s cooldown to all upload handlers
- Cap CSV/ADIF imports at 2,000 rows server-side in both parsers
- Add submitter_verified boolean to contacts (client-cannot-set, anonymous=false)
- Create k8s/secret.example.yaml with placeholders, add LIVE_VIEW_SIGNING_SALT

P1 (high-priority):
- Add Mox.verify_on_exit!() to valkey_test.exs
- Replace DateTime.utc_now() truncation with static ~U literals in map_live_test.exs
- Replace Process.sleep with render_async in pskr_spots_live_test.exs (6 occurrences)
- Add MonitorLive.Show test coverage (4 tests: owner view, non-owner redirect, config success/error)
- Extract duct-detection and mechanism-classification logic from ContactLive.Show into Propagation.PathAnalysis
- Split ContactLive.Show render into 12 function components
- Update CLAUDE.md: remove stale ML model, mark HRDPS active, add backtest/pskr dirs
- Batch CSV import enrichment jobs via new enqueue_for_contacts/1

P2 (medium-priority):
- Set secure:true on session and remember-me cookies in production
- Change SMTP TLS from verify_none to verify_peer with public_key cacerts
- Make /metrics fail-closed in production when PROMETHEUS_AUTH_TOKEN unset
- Add RateLimiter (anon_limit:10, auth_limit:60) to /api/contacts/map
- Add content-security-policy-report-only header
- Add comment noting String.to_atom is compile-time safe in hrdps_client.ex
- Delegate duplicated haversine_km to canonical Microwaveprop.Geo.haversine_km/4
- Consolidate score-tier/color/verdict formatting into Microwaveprop.Format
- Update CLAUDE.md testing section to match actual raw-string-matching practice
- Batch HrrrPointEnqueuer Repo.insert_all calls to single round-trip
- Split weather.ex (1696→216 lines) and radio.ex (1285→54 lines) into purpose-based sub-facades

P3 (low-priority):
- Add LIVE_VIEW_SIGNING_SALT warning comment, extend filter_parameters
- Add host/community validation to snmp_client.ex
- Add raw/1 safety comment in algo_live.ex
- Add hex-audit and cargo-audit Makefile targets
- Add privacy_live smoke test
- Replace notify_listener busy-poll loop with Process.monitor/1 + assert_receive
- Add ContactCommonVolumeRadar changeset validation tests (5 tests)
2026-07-27 18:19:37 -05:00

76 lines
2.9 KiB
Elixir

defmodule Microwaveprop.FormatTest do
use ExUnit.Case, async: true
alias Microwaveprop.Format
describe "distance_km/1" do
test "returns em-dash for nil" do
assert Format.distance_km(nil) == ""
end
test "formats large distances as whole numbers, miles first" do
assert Format.distance_km(235) == "146 mi (235 km)"
assert Format.distance_km(100.0) == "62 mi (100 km)"
end
test "formats short distances with one decimal" do
assert Format.distance_km(1.5) == "0.9 mi (1.5 km)"
assert Format.distance_km(9.6) == "6.0 mi (9.6 km)"
end
test "accepts Decimal input" do
assert Format.distance_km(Decimal.new("235")) == "146 mi (235 km)"
end
end
describe "propagation_tier_label/1" do
test "maps scores to tier labels" do
assert Format.propagation_tier_label(100) == "EXCELLENT"
assert Format.propagation_tier_label(80) == "EXCELLENT"
assert Format.propagation_tier_label(79) == "GOOD"
assert Format.propagation_tier_label(65) == "GOOD"
assert Format.propagation_tier_label(64) == "MARGINAL"
assert Format.propagation_tier_label(50) == "MARGINAL"
assert Format.propagation_tier_label(49) == "POOR"
assert Format.propagation_tier_label(33) == "POOR"
assert Format.propagation_tier_label(32) == "NEGLIGIBLE"
assert Format.propagation_tier_label(0) == "NEGLIGIBLE"
end
end
describe "propagation_tier_badge_class/1" do
test "maps scores to badge CSS classes" do
assert Format.propagation_tier_badge_class(100) =~ "badge-success"
assert Format.propagation_tier_badge_class(80) =~ "badge-success"
assert Format.propagation_tier_badge_class(79) =~ "badge-info"
assert Format.propagation_tier_badge_class(50) =~ "badge-warning"
assert Format.propagation_tier_badge_class(33) =~ "badge-error"
assert Format.propagation_tier_badge_class(0) =~ "badge-ghost"
end
end
describe "propagation_tier_color/1" do
test "maps scores to hex colors" do
assert Format.propagation_tier_color(100) == "#059669"
assert Format.propagation_tier_color(80) == "#059669"
assert Format.propagation_tier_color(79) == "#0d9488"
assert Format.propagation_tier_color(50) == "#ca8a04"
assert Format.propagation_tier_color(33) == "#ea580c"
assert Format.propagation_tier_color(10) == "#dc2626"
end
end
describe "terrain_verdict_class/1" do
test "maps known verdicts to badge color classes" do
assert Format.terrain_verdict_class("CLEAR") == "badge-success"
assert Format.terrain_verdict_class("FRESNEL_MINOR") == "badge-warning"
assert Format.terrain_verdict_class("FRESNEL_PARTIAL") == "badge-warning"
assert Format.terrain_verdict_class("BLOCKED") == "badge-error"
end
test "returns ghost for unknown verdicts" do
assert Format.terrain_verdict_class("UNKNOWN") == "badge-ghost"
assert Format.terrain_verdict_class(nil) == "badge-ghost"
end
end
end