Skip to content

Commit

Permalink
Add session tests
Browse files Browse the repository at this point in the history
  • Loading branch information
trenpixster committed Apr 18, 2016
1 parent fefbcff commit 0059a41
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
27 changes: 27 additions & 0 deletions test/interactors/create_session_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
defmodule CreateSessionTest do
alias Addict.Interactors.CreateSession
use ExUnit.Case, async: true
use Plug.Test

@session_opts Plug.Session.init [
store: :cookie,
key: "_test",
encryption_salt: "abcdefgh",
signing_salt: "abcdefgh"
]

test "it adds the :current_user key to the session" do
fake_user = %{id: 123, email: "john.doe@example.com"}

conn = conn(:get, "/")
|> Plug.Session.call(@session_opts)
|> fetch_session

assert Plug.Conn.get_session(conn, :current_user) == nil

{:ok, conn} = CreateSession.call(conn, fake_user)

assert Plug.Conn.get_session(conn, :current_user) == fake_user
end

end
26 changes: 26 additions & 0 deletions test/interactors/destroy_session_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
defmodule DestroySessionTest do
alias Addict.Interactors.{CreateSession, DestroySession}
use ExUnit.Case, async: true
use Plug.Test

@session_opts Plug.Session.init [
store: :cookie,
key: "_test",
encryption_salt: "abcdefgh",
signing_salt: "abcdefgh"
]

test "it removes the :current_user key from the session" do
fake_user = %{id: 123, email: "john.doe@example.com"}

conn = conn(:get, "/")
|> Plug.Session.call(@session_opts)
|> fetch_session
{:ok, conn} = CreateSession.call(conn, fake_user)

{:ok, conn} = DestroySession.call(conn)

assert Plug.Conn.get_session(conn, :current_user) == nil
end

end

0 comments on commit 0059a41

Please sign in to comment.