Skip to content

Instantly share code, notes, and snippets.

@Fadhil
Created May 5, 2016 14:44
Show Gist options
  • Save Fadhil/176ef1cfbe3f1b37f0c957f19982e613 to your computer and use it in GitHub Desktop.
Save Fadhil/176ef1cfbe3f1b37f0c957f19982e613 to your computer and use it in GitHub Desktop.
defmodule Plug.AnonymousTest do
use ExUnit.Case, async: true
use Plug.Test
require IEx
alias Plug.Anonymous
defmodule SomeApp do
defmodule SomeController do
use Plug.Builder
plug :fetch_session
plug Anonymous
end
end
test "assigns user_id session key" do
conn = conn(:get, "/") |> SomeApp.SomeController.call([]) |> fetch_cookies
refute conn.cookies["anonymous_id"] == nil
end
test "returns existing user session key" do
conn = conn(:get, "/")# |> fetch_cookies
conn = conn |> put_resp_cookie("anonymous_id", "some_id")
conn |> SomeApp.SomeController.call([])# |> fetch_cookies
assert conn.cookies["anonymous_id"] == "some_id"
end
test "raises Error if User is not provided" do
conn = conn(:get, "/") |> SomeApp.SomeController.call([])
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment