mirror of
https://github.com/plausible/analytics.git
synced 2024-12-26 11:02:52 +03:00
5de43b758d
* Set pg pool size for MIX_ENV=test
* Include slow tests in CI run
* Exclude slow tests by default
* Mark tests slow/async where applicable
* Restructure captcha mocks
* Revert async where env is relied upon
* Add --max-failures=1 to CI run
* Set warnings as errors
* Disable async where various mocks are used
* Revert "Disable async where various mocks are used"
This reverts commit 2446b72a29
.
* Disable async for test using vcr
45 lines
1.2 KiB
Elixir
45 lines
1.2 KiB
Elixir
defmodule PlausibleWeb.AuthPlugTest do
|
|
use Plausible.DataCase, async: true
|
|
use Plug.Test
|
|
alias PlausibleWeb.AuthPlug
|
|
|
|
test "does nothing if user is not logged in" do
|
|
conn =
|
|
conn(:get, "/")
|
|
|> init_test_session(%{})
|
|
|> AuthPlug.call(%{})
|
|
|
|
assert is_nil(conn.assigns[:current_user])
|
|
end
|
|
|
|
test "looks up current user if they are logged in" do
|
|
user = insert(:user)
|
|
subscription = insert(:subscription, user: user)
|
|
|
|
conn =
|
|
conn(:get, "/")
|
|
|> init_test_session(%{current_user_id: user.id})
|
|
|> AuthPlug.call(%{})
|
|
|
|
assert conn.assigns[:current_user].id == user.id
|
|
assert conn.assigns[:current_user].subscription.id == subscription.id
|
|
end
|
|
|
|
test "looks up the latest subscription" do
|
|
user = insert(:user)
|
|
|
|
_old_subscription =
|
|
insert(:subscription, user: user, inserted_at: Timex.now() |> Timex.shift(days: -1))
|
|
|
|
subscription = insert(:subscription, user: user, inserted_at: Timex.now())
|
|
|
|
conn =
|
|
conn(:get, "/")
|
|
|> init_test_session(%{current_user_id: user.id})
|
|
|> AuthPlug.call(%{})
|
|
|
|
assert conn.assigns[:current_user].id == user.id
|
|
assert conn.assigns[:current_user].subscription.id == subscription.id
|
|
end
|
|
end
|