prop/test/microwaveprop_web/controllers/beacon_monitor_controller_test.exs
Graham McIntire fb49eb016d
feat(monitors): schema migration + remove user self-service creation
- Add hardware/config fields migration to beacon_monitors table
- Update BeaconMonitor schema with provision/config changesets
- Add context functions: create_hardware, update_config, list_all_monitors
- Remove user-facing monitor creation (browser POST + API POST)
- Update settings page: show assigned monitors table with hardware info
- Update profile page: show assigned monitors, remove register links
- Fix all tests to match new API
2026-07-21 18:28:51 -05:00

32 lines
1.1 KiB
Elixir

defmodule MicrowavepropWeb.BeaconMonitorControllerTest do
use MicrowavepropWeb.ConnCase, async: true
import Microwaveprop.AccountsFixtures
alias Microwaveprop.BeaconMonitors
setup :register_and_log_in_user
describe "DELETE /users/beacon-monitors/:id" do
test "deletes a monitor owned by the current user", %{conn: conn, user: user} do
{:ok, monitor} = BeaconMonitors.create_monitor(user, %{"name" => "Bye"})
conn = delete(conn, ~p"/users/beacon-monitors/#{monitor.id}")
assert redirected_to(conn) == ~p"/users/settings"
assert Phoenix.Flash.get(conn.assigns.flash, :info) =~ "deleted"
assert BeaconMonitors.list_monitors_for_user(user) == []
end
test "does not delete a monitor owned by another user", %{conn: conn} do
other = user_fixture()
{:ok, monitor} = BeaconMonitors.create_monitor(other, %{"name" => "Theirs"})
conn = delete(conn, ~p"/users/beacon-monitors/#{monitor.id}")
assert redirected_to(conn) == ~p"/users/settings"
assert Phoenix.Flash.get(conn.assigns.flash, :error) =~ "not found"
assert [_] = BeaconMonitors.list_monitors_for_user(other)
end
end
end