Files
dexi/test/dexi/accounts/administration_test.exs
T

36 lines
1.1 KiB
Elixir

defmodule Dexi.Accounts.AdministrationTest do
use Dexi.DataCase, async: true
import Dexi.AccountsFixtures
alias Dexi.Accounts
test "admin commands are idempotent" do
pubkey = unique_public_key()
assert {:ok, first} = Accounts.create_or_promote_admin(pubkey)
assert first.role == :admin
assert {:ok, second} = Accounts.create_or_promote_admin(pubkey)
assert second.role == :admin
assert {:ok, user} = Accounts.remove_admin(pubkey)
assert user.role == :user
end
test "fresh database authorization rejects a stale admin struct" do
admin = admin_fixture()
target = user_fixture()
assert {:ok, _user} = Accounts.remove_admin(admin.pubkey)
assert {:error, :unauthorized} = Accounts.set_role(admin, target, :admin)
assert {:error, :unauthorized} =
Accounts.update_user_details(admin, target, %{name: "Not allowed"})
end
test "an admin cannot demote itself through the user interface service" do
admin = admin_fixture()
assert {:error, :self_demotion} = Accounts.set_role(admin, admin, :user)
end
end