From e197283bff3bd3c928d1be3600af25efbb6de83a Mon Sep 17 00:00:00 2001 From: nelsonic Date: Fri, 24 Apr 2020 10:41:38 +0100 Subject: [PATCH] add tests for generate_jwt!/2 for #9 --- test/token_test.exs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 test/token_test.exs diff --git a/test/token_test.exs b/test/token_test.exs new file mode 100644 index 0000000..417e7ef --- /dev/null +++ b/test/token_test.exs @@ -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: "alex@dwyl.com", 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