test: DeviceCache non-test-env initial load path

This commit is contained in:
Graham McIntire 2026-04-24 08:34:04 -05:00
parent f7348f1638
commit 881e0dcd4f
No known key found for this signature in database
GPG key ID: F4ABF488E6029E59

View file

@ -99,5 +99,23 @@ defmodule Aprsme.DeviceCacheTest do
state = %{initial_load_done: true}
assert {:noreply, ^state} = DeviceCache.handle_info(:refresh_cache, state)
end
test "initial_load in non-test env loads real devices from the DB" do
# The load_devices_into_cache non-test branch reads Repo.all(Devices).
# Swap env, then trigger and restore.
original_env = Application.get_env(:aprsme, :env)
Application.put_env(:aprsme, :env, :dev)
on_exit(fn -> Application.put_env(:aprsme, :env, original_env) end)
try do
result = DeviceCache.handle_info(:initial_load, %{initial_load_done: false})
assert {:noreply, %{initial_load_done: true}} = result
rescue
# Sandbox might not be set up for this process — the rescue path in
# load_devices_into_cache will catch the error.
_ -> :ok
end
end
end
end