Skip to content

Commit

Permalink
add test for api_key/0 with DWYL_API_KEY #14 💯
Browse files Browse the repository at this point in the history
  • Loading branch information
nelsonic committed Apr 27, 2020
1 parent bd045ed commit b612845
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,14 @@ echo ".env" >> .gitignore

### 3. Protect a Route

Open your project's `router.ex` file. e.g:




### (Optional) Update `endpoint.ex`





Expand Down
13 changes: 12 additions & 1 deletion test/token_test.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
defmodule AuthPlugTokenTest do
use ExUnit.Case, async: true
use ExUnit.Case, async: false
import AuthPlug.Token

test "api_key/0 with AUTH_API_KEY" do
assert api_key() == System.get_env("AUTH_API_KEY")
end


test "generate_jwt!/2 creates a JWT with the given data and secret" do
secret = "secretcanbeanystringyouwant"
data = %{email: "[email protected]", name: "Alex"}
Expand All @@ -21,4 +26,10 @@ defmodule AuthPlugTokenTest do
{:ok, decoded} = verify_jwt(jwt, secret)
assert data.email == Map.get(decoded, "email")
end

test "api_key/0 with DWYL_API_KEY" do
System.put_env("DWYL_API_KEY", System.get_env("AUTH_API_KEY"))
assert api_key() == System.get_env("AUTH_API_KEY")
# System.put_env("DWYL_API_KEY", nil)
end
end

0 comments on commit b612845

Please sign in to comment.