From 093713f042d5becb416570733a3ab70afc8d94e3 Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Fri, 24 Apr 2026 08:18:57 -0500 Subject: [PATCH] test: DeviceIdentification lookup_device_from_db fallback path --- test/aprsme/device_identification_test.exs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/test/aprsme/device_identification_test.exs b/test/aprsme/device_identification_test.exs index 6b77206..17793b3 100644 --- a/test/aprsme/device_identification_test.exs +++ b/test/aprsme/device_identification_test.exs @@ -203,6 +203,27 @@ defmodule Aprsme.DeviceIdentificationTest do end end + describe "lookup_device_from_db fallback when cache is unavailable" do + test "lookup_device_by_identifier falls back to direct DB when DeviceCache is unavailable" do + Repo.delete_all(Devices) + + Repo.insert!(%Devices{ + identifier: "DBEXACT", + vendor: "Test", + model: "Exact" + }) + + # Clear the cache so the code path exercises the DB lookup. + Aprsme.Cache.put(:device_cache, :all_devices, nil) + + # Cache miss → DeviceCache returns nil and also triggers async refresh. + # Direct lookup_device_by_identifier goes via DeviceCache here. + result = DeviceIdentification.lookup_device_by_identifier("DBEXACT") + # Either cache miss → nil, or cache refresh filled and matched. + assert is_nil(result) or (is_struct(result, Devices) and result.identifier == "DBEXACT") + end + end + describe "upsert_devices/1 with all three groups" do test "processes devices from mice and micelegacy groups" do Repo.delete_all(Devices)