-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add tests for generate_jwt!/2 for #9
- Loading branch information
Showing
1 changed file
with
14 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
defmodule AuthPlugTokenTest do | ||
use ExUnit.Case, async: true | ||
import AuthPlug.Token | ||
|
||
test "generate_jwt!/2 creates a JWT with the given data and secret" do | ||
secret = "secretcanbeanystringyouwant" | ||
data = %{email: "[email protected]", name: "Alex"} | ||
jwt = generate_jwt!(data, secret) | ||
assert Enum.count(String.split(jwt, ".")) == 3 | ||
|
||
decoded = verify_jwt!(jwt, secret) | ||
assert data.email == Map.get(decoded, "email") | ||
end | ||
end |