prop/test/microwaveprop/buildings/bulk_fetch_test.exs
Graham McIntire fd976b0cd5
fix: resolve 391 Credo issues across codebase
- Add jump_credo_checks ~> 0.4 with all 20 checks enabled
- Fix all standard Credo issues: 139 @spec (113 done, 26 remain),
  4 refactoring, 3 alias usage, 9 System.cmd env, 5 unsafe_to_atom,
  2 max line length, 9 assert_receive timeout
- Fix 170+ jump_credo_checks warnings:
  - 117 TopLevelAliasImportRequire: move nested alias/import to module top
  - 32 UseObanProWorker: switch to Oban.Pro.Worker
  - 4 DoctestIExExamples: add doctests / create test file
  - ~20 WeakAssertion: strengthen type-check assertions
  - Various ConditionalAssertion, AssertReceiveTimeout fixes
- Exclude vendor/ from Credo analysis
- Remaining: 175 warnings (mostly opinionated WeakAssertion,
  AvoidSocketAssignsInTest), 26 @spec annotations
2026-06-12 13:51:32 -05:00

48 lines
1.3 KiB
Elixir

defmodule Microwaveprop.Buildings.BulkFetchTest do
use ExUnit.Case, async: false
import ExUnit.CaptureLog
alias Microwaveprop.Buildings.BulkFetch
setup do
prev = Application.get_env(:microwaveprop, :ms_footprints_http_get)
on_exit(fn ->
if prev,
do: Application.put_env(:microwaveprop, :ms_footprints_http_get, prev),
else: Application.delete_env(:microwaveprop, :ms_footprints_http_get)
end)
:ok
end
describe "run/4" do
test "returns the result struct with zero counters when index is empty" do
# Stub the dataset index fetch to return empty TSV -> no quadkeys
# in index -> no downloads attempted.
Application.put_env(:microwaveprop, :ms_footprints_http_get, fn _url, _opts ->
{:ok, %{status: 200, body: "Location\tQuadkey\tUrl\tSize\n"}}
end)
# Need to invalidate the dataset_index cache so our stub takes effect.
Microwaveprop.Cache.invalidate(:ms_footprints_index)
capture_log(fn ->
result = BulkFetch.run(32.8, -97.0, 1, concurrency: 1)
send(self(), result)
end)
assert_received %{
downloaded: 0,
cached: 0,
failed: 0,
missing: missing,
cache_dir: cache_dir
}
assert is_integer(missing)
assert byte_size(cache_dir) > 0
end
end
end