Ash FrameworkAF
Ash Framework5mo ago
13 replies
theopechli

How to test policies correctly?

Hello, I am confused a tiny bit about policy testing.

As an example, right now what I do is the following:

assert match?({:error, _}, Accounts.get_user_by_email(users.admin.email, actor: users.user))


Previously, I was doing this:

assert Accounts.get_user_by_email(
  users.admin.email,
  actor: users.user,
  not_found_error?: false
) == {:ok, nil}


Both pass, but I am unsure as to what I should be doing... Maybe matching on the type of error is better (not found, forbidden, etc), instead of matching on any error?
Solution
You can use Ash.can or for code interfaces their can_ variant
Was this page helpful?