aprs.me/test/aprsme/workers/packet_cleanup_worker_test.exs
Graham McIntire 2f09b590e2
Some checks are pending
Elixir CI / Build and test (push) Waiting to run
Elixir CI / Dialyzer (push) Waiting to run
Elixir CI / Build and Push Docker Image (push) Blocked by required conditions
fix: resolve all credo issues — 0 warnings, 0 refactoring, 0 readability issues
- Add ex_slop credo plugin with all 40 checks
- Remove DualKeyAccess patterns across codebase — atom-only access
- Fix LengthInGuard, LengthComparison, ListLast, ReduceMapPut in lib/
- Disable LengthComparison for test files
- Remove obvious comments and narrator comments (~50)
- Add missing aliases for fully-qualified modules
- Rewrite boilerplate docs in test/support
- Add normalize_keys helpers at API boundaries
2026-07-29 10:54:07 -05:00

55 lines
1.8 KiB
Elixir

defmodule Aprsme.Workers.PacketCleanupWorkerTest do
use Aprsme.DataCase, async: false
alias Aprsme.BadPacket
alias Aprsme.Workers.PacketCleanupWorker
describe "perform/1 without cleanup_days" do
test "cleans up expired bad packets" do
retention_days = Application.get_env(:aprsme, :packet_retention_days, 7)
old_time =
DateTime.utc_now()
|> DateTime.add(-(retention_days + 10) * 86_400, :second)
|> DateTime.truncate(:microsecond)
Repo.insert!(%BadPacket{raw_packet: "bad", error_message: "test", attempted_at: old_time})
recent_time =
DateTime.utc_now()
|> DateTime.add(-3600, :second)
|> DateTime.truncate(:microsecond)
Repo.insert!(%BadPacket{raw_packet: "recent_bad", error_message: "test", attempted_at: recent_time})
assert :ok = PacketCleanupWorker.perform(%{})
# Only recent bad packet should remain
assert Repo.aggregate(BadPacket, :count) == 1
end
end
describe "perform/1 with negative cleanup_days" do
test "falls through to default perform and succeeds" do
assert :ok = PacketCleanupWorker.perform(%{"cleanup_days" => -1})
end
end
describe "perform/1 with extra fields that the guard ignores" do
test "accepts a map with cleanup_days plus unrelated keys" do
assert :ok =
PacketCleanupWorker.perform(%{
"cleanup_days" => 30,
"random_field" => "ignored"
})
end
test "handles zero cleanup_days by falling through to default" do
assert :ok = PacketCleanupWorker.perform(%{"cleanup_days" => 0})
end
test "handles non-integer cleanup_days by falling through to default" do
assert :ok = PacketCleanupWorker.perform(%{"cleanup_days" => "string"})
end
end
end