refactor: improve error handling and documentation in PermissionSets
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
- Add explicit ArgumentError for invalid permission set names with helpful message - Soften performance claim in documentation (intended to be constant-time) - Add tests for error handling - Improve maintainability with guard clause for invalid inputs
This commit is contained in:
parent
9b0d022767
commit
7845117fad
2 changed files with 32 additions and 2 deletions
|
|
@ -567,4 +567,27 @@ defmodule Mv.Authorization.PermissionSetsTest do
|
|||
{:error, :invalid_permission_set}
|
||||
end
|
||||
end
|
||||
|
||||
describe "get_permissions/1 - error handling" do
|
||||
test "raises ArgumentError for invalid permission set with helpful message" do
|
||||
assert_raise ArgumentError,
|
||||
~r/invalid permission set: :invalid\. Must be one of:/,
|
||||
fn ->
|
||||
PermissionSets.get_permissions(:invalid)
|
||||
end
|
||||
end
|
||||
|
||||
test "error message includes all valid permission sets" do
|
||||
error =
|
||||
assert_raise ArgumentError, fn ->
|
||||
PermissionSets.get_permissions(:unknown)
|
||||
end
|
||||
|
||||
error_message = Exception.message(error)
|
||||
assert error_message =~ "own_data"
|
||||
assert error_message =~ "read_only"
|
||||
assert error_message =~ "normal_user"
|
||||
assert error_message =~ "admin"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue