Checkpoint passing tests

This commit is contained in:
Jamil Bou Kheir
2021-12-14 15:49:31 -08:00
parent 205f93b7ba
commit e64db67672
8 changed files with 73 additions and 23 deletions

View File

@@ -39,7 +39,8 @@ defmodule FzHttp.Application do
FzHttp.Repo,
FzHttp.Vault,
FzHttpWeb.Endpoint,
{Phoenix.PubSub, name: FzHttp.PubSub}
{Phoenix.PubSub, name: FzHttp.PubSub},
FzHttpWeb.Presence
]
end
end

View File

@@ -0,0 +1,13 @@
<%= render FzHttpWeb.SharedView, "heading.html", page_title: @page_title %>
<section class="section is-main-section">
<%= render FzHttpWeb.SharedView, "flash.html", assigns %>
<h4 class="title is-4">Security Settings</h4>
<div class="block">
<p>
Manage security-related settings.
</p>
</div>
</section>

View File

@@ -0,0 +1,14 @@
defmodule FzHttpWeb.SettingLive.Security do
@moduledoc """
Manages security LiveView
"""
use FzHttpWeb, :live_view
@impl Phoenix.LiveView
def mount(params, session, socket) do
{:ok,
socket
|> assign(:page_title, "Security Settings")
|> assign_defaults(params, session)}
end
end

View File

@@ -30,6 +30,10 @@ defmodule FzHttpWeb.LayoutView do
@doc """
Generate class for nav links
"""
def nav_class(%{request_path: "/"} = _conn, ~r"devices") do
"is-active has-icon"
end
def nav_class(%{request_path: request_path} = _conn, regex) do
if String.match?(request_path, regex) do
"is-active has-icon"

View File

@@ -1,29 +1,46 @@
defmodule FzHttpWeb.NotificationChannelTest do
use FzHttpWeb.ChannelCase
use FzHttpWeb.ChannelCase, async: true
alias FzHttp.UsersFixtures
alias FzHttpWeb.NotificationChannel
describe "channel join" do
setup do
setup _tags do
user = UsersFixtures.user()
socket =
FzHttpWeb.UserSocket
|> socket(user.id, %{remote_ip: "127.0.0.1"})
%{
user: FzHttp.UsersFixtures.user(),
socket: socket(user.id, %{})
user: user,
socket: socket,
token: Phoenix.Token.sign(socket, "channel auth", user.id)
}
end
test "joins channel with valid token", %{user: user} do
# token = Phoenix.Token.sign
test "joins channel with valid token", %{token: token, socket: socket, user: user} do
payload = %{
"token" => token,
"user_agent" => "test"
}
{:ok, _, test_socket} =
socket
|> subscribe_and_join(NotificationChannel, "notification:session", payload)
assert test_socket.assigns.current_user.id == user.id
end
test "prevents joining with expired token", %{user: user} do
end
test "prevents joining with invalid token", %{token: _token, socket: socket, user: _user} do
payload = %{
"token" => "foobar",
"user_agent" => "test"
}
test "prevents joining with invalid token", %{user: user} do
assert {:error, %{reason: "unauthorized"}} ==
socket
|> subscribe_and_join(NotificationChannel, "notification:session", payload)
end
end
test "broadcasts are pushed to the client", %{socket: socket} do
broadcast_from!(socket, "broadcast", %{"some" => "data"})
assert_push "broadcast", %{"some" => "data"}
end
end

View File

@@ -41,7 +41,7 @@ defmodule FzHttpWeb.DeviceLive.ShowTest do
path = Routes.device_show_path(conn, :show, device)
{:ok, _view, html} = live(conn, path)
assert html =~ "#{device.name}"
assert html =~ "<p class=\"card-header-title\">Details</p>"
assert html =~ "<h4 class=\"title is-4\">Details</h4>"
end
test "opens modal", %{authed_conn: conn, device: device} do
@@ -220,7 +220,7 @@ defmodule FzHttpWeb.DeviceLive.ShowTest do
{:ok, view, _html} = live(conn, path)
view
|> element("a", "Delete")
|> element("button", "Delete Device #{device.name}")
|> render_click()
_flash = assert_redirected(view, Routes.device_index_path(conn, :index))

View File

@@ -3,16 +3,16 @@ defmodule FzHttpWeb.SettingLive.SecurityTest do
describe "authenticated mount" do
test "loads the active sessions table", %{authed_conn: conn} do
path = Routes.setting_security_path(conn, :show)
path = Routes.setting_security_path(conn, :security)
{:ok, _view, html} = live(conn, path)
assert html =~ "Active Browser Sessions"
assert html =~ "<h4 class=\"title is-4\">Security Settings</h4>"
end
end
describe "unauthenticated mount" do
test "redirects to not authorized", %{unauthed_conn: conn} do
path = Routes.setting_security_path(conn, :show)
path = Routes.setting_security_path(conn, :security)
expected_path = Routes.session_path(conn, :new)
assert {:error, {:redirect, %{to: ^expected_path}}} = live(conn, path)

View File

@@ -9,15 +9,16 @@ defmodule FzHttpWeb.LayoutViewTest do
# import Phoenix.HTML
describe "nav_class/2" do
test "it computes nav class for root route" do
assert LayoutView.nav_class("/", "devices") == "is-active has-icon"
assert LayoutView.nav_class(%{request_path: "/"}, ~r"devices") == "is-active has-icon"
end
test "it computes nav class for account route" do
assert LayoutView.nav_class("/account", "account") == "is-active has-icon"
assert LayoutView.nav_class(%{request_path: "/account"}, ~r"account") ==
"is-active has-icon"
end
test "it defaults to has-icon" do
assert LayoutView.nav_class("Blah", "foo") == " has-icon"
assert LayoutView.nav_class(%{request_path: "Blah"}, ~r"foo") == "has-icon"
end
end
end