This repository has been archived by the owner on Dec 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#21: Add testing for new func & task
- Loading branch information
Showing
2 changed files
with
28 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,17 @@ | ||
defmodule Mix.Tasks.SmartHomeTest do | ||
use ExUnit.Case | ||
import ExUnit.CaptureIO | ||
|
||
require Logger | ||
|
||
@jwt_pattern ~r/[A-Za-z0-9-_=]+\.[A-Za-z0-9-_=]+\.?[A-Za-z0-9-_.+\/=]*$/m | ||
|
||
test "Mix task returns a valid JWT" do | ||
out = capture_io(fn -> Mix.Tasks.SmartHome.GenToken.run([]) end) | ||
|
||
jwt = Regex.run(@jwt_pattern, out) |> List.first() | ||
|
||
decoded = AuthPlug.Token.verify_jwt!(jwt) | ||
assert %{"id" => 1} = decoded | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
defmodule SmartHomeAuth.HelperTest do | ||
use ExUnit.Case, async: true | ||
|
||
test "gen_auth_token generates a correct token" do | ||
token = SmartHomeAuth.gen_auth_token() | ||
|
||
decoded = AuthPlug.Token.verify_jwt!(token) | ||
|
||
assert %{"id" => 1} = decoded | ||
end | ||
end |