From 881e0dcd4feba1805e25c8c645479e7dfa08fd77 Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Fri, 24 Apr 2026 08:34:04 -0500 Subject: [PATCH] test: DeviceCache non-test-env initial load path --- test/aprsme/device_cache_test.exs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/test/aprsme/device_cache_test.exs b/test/aprsme/device_cache_test.exs index 9de18a5..d103dad 100644 --- a/test/aprsme/device_cache_test.exs +++ b/test/aprsme/device_cache_test.exs @@ -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