mirror of
https://github.com/TheRealOwenRees/chess-endgame-trainer.git
synced 2026-11-18 11:42:07 +00:00
- Scaffold password auth (email or username) with phx.gen.auth; no magic links - Add role (member/moderator/admin/super_admin) and plan (free/premium) enums - Gate /admin behind admin-or-above via plug + on_mount; hide the nav link - Add mix accounts.promote for CLI role changes - Disable email confirmation by confirming accounts at registration Closes #3
47 lines
1.2 KiB
Elixir
47 lines
1.2 KiB
Elixir
defmodule Mix.Tasks.Accounts.PromoteTest do
|
|
use Chesstrainer.DataCase
|
|
|
|
import Chesstrainer.AccountsFixtures
|
|
import ExUnit.CaptureIO
|
|
|
|
alias Chesstrainer.Accounts
|
|
|
|
test "promotes a user by username" do
|
|
user = user_fixture()
|
|
|
|
output =
|
|
capture_io(fn -> Mix.Tasks.Accounts.Promote.run([user.username, "admin"]) end)
|
|
|
|
assert output =~ "role to admin"
|
|
assert Accounts.get_user!(user.id).role == :admin
|
|
end
|
|
|
|
test "promotes a user by email" do
|
|
user = user_fixture()
|
|
|
|
capture_io(fn -> Mix.Tasks.Accounts.Promote.run([user.email, "super_admin"]) end)
|
|
|
|
assert Accounts.get_user!(user.id).role == :super_admin
|
|
end
|
|
|
|
test "raises for an unknown role" do
|
|
user = user_fixture()
|
|
|
|
assert_raise Mix.Error, ~r/Unknown role/, fn ->
|
|
Mix.Tasks.Accounts.Promote.run([user.username, "wizard"])
|
|
end
|
|
end
|
|
|
|
test "raises when the user does not exist" do
|
|
assert_raise Mix.Error, ~r/No user found/, fn ->
|
|
Mix.Tasks.Accounts.Promote.run(["nobody@example.com", "admin"])
|
|
end
|
|
end
|
|
|
|
test "raises without the expected arguments" do
|
|
assert_raise Mix.Error, ~r/Usage/, fn ->
|
|
Mix.Tasks.Accounts.Promote.run([])
|
|
end
|
|
end
|
|
end
|