-
-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tests for Supavisor.Jwt.authorize/2 #36
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
test/supavisor/jwt_test.exs
Outdated
end | ||
|
||
test "returns {:error, :token_not_a_string} for non-binary token" do | ||
assert {:error, :token_not_a_string} = Jwt.authorize(123, @secret) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
double-checking: instead of gracefully handling non-string tokens would it make sense to crash? In other words, wouldn't it be a programmer's mistake if we called this function with invalid type?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, I don't have a strong opinion on this matter. What would you recommend? Should I remove the handling of other types?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I'd remove it. Its type spec is @spec authorize(String.t(), String.t()) :: {:ok, map()} | {:error, any()}
, it accepts only strings, it's fine to raise.
For completeness, here's a random example from stdlib:
iex> Version.parse("1.0.0")
{:ok, %Version{major: 1, minor: 0, patch: 0}}
iex> Version.parse("1")
:error
iex> Version.parse(1)
** (FunctionClauseError) no function clause matching in Version.parse/1
The following arguments were given to Version.parse/1:
# 1
1
Attempted function clauses (showing 1 out of 1):
def parse(string) when is_binary(string)
(elixir 1.15.0-dev) lib/version.ex:367: Version.parse/1
iex:9: (file)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
got it, thanks for the explanation!
Co-authored-by: Wojtek Mach <wojtekmach@users.noreply.github.com>
This PR adds tests for Supavisor.Jwt.authorize/2, as recommended by @wojtekmach here