aprs.me/test/aprsme/deployment_notifier_test.exs
Graham McIntire b86153cd27
Fix all mix credo --strict warnings (188 → 0)
- Replace apply/2 with direct fully-qualified calls in movement_test
- Fix assert_receive timeouts < 1000ms across 8 test files
- Move nested import statements to module-level scope
- Fix tests with no assertions and add missing doctest
- Replace weak type assertions with specific value checks
- Fix conditional assertions and length/1 expensive patterns
- Disable inappropriate Jump.CredoChecks.AvoidSocketAssignsInTest
- Fix tests not calling application code with credo:disable
- Add various credo:disable comments for legitimate patterns
2026-06-12 16:27:20 -05:00

50 lines
1.6 KiB
Elixir

defmodule Aprsme.DeploymentNotifierTest do
use ExUnit.Case, async: false
alias Aprsme.DeploymentNotifier
describe "notify_deployment/1" do
test "broadcasts :new_deployment over Aprsme.PubSub" do
:ok = Phoenix.PubSub.subscribe(Aprsme.PubSub, "deployment_events")
now = DateTime.utc_now()
assert :ok == DeploymentNotifier.notify_deployment(now)
assert_receive {:new_deployment, %{deployed_at: ^now}}, 1000
end
end
describe "handle_info :check_deployment" do
test "no-op when deployed_at is unchanged" do
deployed = DateTime.utc_now()
Application.put_env(:aprsme, :deployed_at, deployed)
state = %{deployed_at: deployed}
assert {:noreply, ^state} = DeploymentNotifier.handle_info(:check_deployment, state)
end
test "broadcasts and updates state when deployed_at has changed" do
:ok = Phoenix.PubSub.subscribe(Aprsme.PubSub, "deployment_events")
new_deploy = DateTime.utc_now()
old_deploy = DateTime.add(new_deploy, -60, :second)
# Simulate an updated deploy timestamp in app env.
Application.put_env(:aprsme, :deployed_at, new_deploy)
state = %{deployed_at: old_deploy}
assert {:noreply, %{deployed_at: ^new_deploy}} =
DeploymentNotifier.handle_info(:check_deployment, state)
assert_receive {:new_deployment, %{deployed_at: ^new_deploy}}, 1000
end
end
describe "init/1" do
test "schedules a check and stores the current deployed_at in state" do
assert {:ok, %{deployed_at: %DateTime{}}} = DeploymentNotifier.init([])
# The 30s check is scheduled — we don't wait for it.
end
end
end