-
-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: do not use
meck
when testing metrics controller (#593)
Not only it is not needed, it was harmful, as it was incorrect (the mock wasn't removed after test), which was causing some other tests to fail unexpectedly.
- Loading branch information
Showing
8 changed files
with
55 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
2.2.0 | ||
2.2.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
[ | ||
import_deps: [:ecto, :stream_data], | ||
inputs: ["**/*.{ex, exs}"] | ||
inputs: ["**/*.{ex,exs}"] | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,31 @@ | ||
defmodule Supavisor.JwtTest do | ||
use ExUnit.Case, async: true | ||
alias Supavisor.Jwt | ||
|
||
@subject Supavisor.Jwt | ||
|
||
@secret "my_secret_key" | ||
@wrong_secret "my_wrong_secret_key" | ||
|
||
describe "authorize/2" do | ||
test "returns claims for a valid token" do | ||
{:ok, token, _} = create_valid_jwt_token() | ||
assert {:ok, claims} = Jwt.authorize(token, @secret) | ||
token = create_valid_jwt_token() | ||
assert {:ok, claims} = @subject.authorize(token, @secret) | ||
assert claims["role"] == "test" | ||
end | ||
|
||
test "raises an error for non-binary token" do | ||
assert_raise FunctionClauseError, fn -> | ||
Jwt.authorize(123, @secret) | ||
@subject.authorize(123, @secret) | ||
end | ||
end | ||
|
||
test "returns signature_error for a wrong secret" do | ||
{:ok, token, _} = create_valid_jwt_token() | ||
assert {:error, :signature_error} = Jwt.authorize(token, @wrong_secret) | ||
token = create_valid_jwt_token() | ||
assert {:error, :signature_error} = @subject.authorize(token, @wrong_secret) | ||
end | ||
end | ||
|
||
defp create_valid_jwt_token do | ||
exp = Joken.current_time() + 3600 | ||
claims = %{"role" => "test", "exp" => exp} | ||
signer = Joken.Signer.create("HS256", @secret) | ||
Joken.encode_and_sign(claims, signer) | ||
@subject.Token.gen!(%{"role" => "test"}, @secret) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters