Skip to content
This repository has been archived by the owner on Dec 6, 2022. It is now read-only.

Commit

Permalink
#21: Add testing for new func & task
Browse files Browse the repository at this point in the history
  • Loading branch information
th0mas committed Aug 26, 2020
1 parent 9ee32aa commit 84c5263
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
17 changes: 17 additions & 0 deletions test/mix/tasks/smart_home_test.exs
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
11 changes: 11 additions & 0 deletions test/smart_home_auth/helper_test.exs
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

0 comments on commit 84c5263

Please sign in to comment.