test: DeviceIdentification lookup_device_from_db fallback path

This commit is contained in:
Graham McIntire 2026-04-24 08:18:57 -05:00
parent 4f23c4005c
commit 093713f042
No known key found for this signature in database
GPG key ID: F4ABF488E6029E59

View file

@ -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)