Raising the area cap to 4600 put it above the largest area clamp/1 can emit (45° lat × 100° lon = 4500 sq deg), so :viewport_too_large became unreachable and the 413 handlers in both cell controllers became dead code. Remove the cap, the error branch, the max_viewport_area_sq_deg/0 accessor and both payload_too_large/1 handlers. The clamp is what bounds request cost: post-clamp nothing can ask for more than the full grid (~92k cells, ~1.4 MB), which is materialized once per valid_time and served from cache, so a global viewport costs no more than a fully zoomed-out map. Replaces the cap test with one asserting the clamp never lets absurd input escape the supported extent — the property the guard was standing in for.
54 lines
2.1 KiB
Elixir
54 lines
2.1 KiB
Elixir
defmodule MicrowavepropWeb.GridBoundsTest do
|
|
use ExUnit.Case, async: true
|
|
|
|
alias MicrowavepropWeb.GridBounds
|
|
|
|
describe "clamp/1" do
|
|
test "passes nil through" do
|
|
assert GridBounds.clamp(nil) == {:ok, nil}
|
|
end
|
|
|
|
test "passes a small viewport through unchanged" do
|
|
bounds = %{"south" => 30.0, "north" => 35.0, "west" => -100.0, "east" => -90.0}
|
|
assert {:ok, ^bounds} = GridBounds.clamp(bounds)
|
|
end
|
|
|
|
test "clamps south/north/west/east to the supported extent" do
|
|
bounds = %{"south" => -50.0, "north" => 90.0, "west" => -200.0, "east" => 50.0}
|
|
|
|
assert {:ok, %{"south" => 20.0, "north" => 65.0, "west" => -150.0, "east" => -50.0}} =
|
|
GridBounds.clamp(bounds)
|
|
end
|
|
|
|
# The map's own `minZoom: 4` produces a viewport that clamps to the
|
|
# full extent. Rejecting it blanked the overlay whenever a user
|
|
# zoomed all the way out, so the clamped full grid must be served.
|
|
test "serves global bounds by clamping them to the supported extent" do
|
|
global = %{"south" => -90.0, "north" => 90.0, "west" => -180.0, "east" => 180.0}
|
|
|
|
assert {:ok, %{"south" => 20.0, "north" => 65.0, "west" => -150.0, "east" => -50.0}} =
|
|
GridBounds.clamp(global)
|
|
end
|
|
|
|
# The clamp is the only thing bounding request cost, so its output
|
|
# must never exceed the grid extent no matter how absurd the input.
|
|
test "clamped output never escapes the supported extent" do
|
|
absurd = %{"south" => -1.0e6, "north" => 1.0e6, "west" => -1.0e6, "east" => 1.0e6}
|
|
|
|
assert {:ok, %{"south" => 20.0, "north" => 65.0, "west" => -150.0, "east" => -50.0}} =
|
|
GridBounds.clamp(absurd)
|
|
end
|
|
|
|
test "rejects inverted bounds" do
|
|
inverted = %{"south" => 40.0, "north" => 30.0, "west" => -90.0, "east" => -100.0}
|
|
assert GridBounds.clamp(inverted) == {:error, :invalid_bounds}
|
|
end
|
|
|
|
test "rejects malformed bounds" do
|
|
assert GridBounds.clamp(%{}) == {:error, :invalid_bounds}
|
|
|
|
assert GridBounds.clamp(%{"south" => "x", "north" => 1, "west" => 1, "east" => 1}) ==
|
|
{:error, :invalid_bounds}
|
|
end
|
|
end
|
|
end
|