mirror of
https://github.com/outbackdingo/firezone.git
synced 2026-01-28 18:18:55 +00:00
Checkpoint LiveView tests
This commit is contained in:
@@ -8,13 +8,7 @@ defmodule FgHttpWeb.MockEvents do
|
||||
"""
|
||||
|
||||
def create_device do
|
||||
{:ok,
|
||||
%{
|
||||
private_key: "privkey",
|
||||
public_key: "pubkey",
|
||||
server_public_key: "server_pubkey",
|
||||
preshared_key: "preshared_key"
|
||||
}}
|
||||
{:ok, "privkey", "pubkey", "server_pubkey", "preshared_key"}
|
||||
end
|
||||
|
||||
def delete_device(pubkey) do
|
||||
|
||||
@@ -3,7 +3,6 @@ defmodule FgHttpWeb.Router do
|
||||
Main Application Router
|
||||
"""
|
||||
|
||||
alias FgHttpWeb.{BlacklistLive, DeviceDetailsLive, WhitelistLive}
|
||||
use FgHttpWeb, :router
|
||||
|
||||
# View emails locally in development
|
||||
@@ -26,8 +25,7 @@ defmodule FgHttpWeb.Router do
|
||||
scope "/", FgHttpWeb do
|
||||
pipe_through :browser
|
||||
live "/live/device_details", DeviceDetailsLive
|
||||
live "/live/whitelist", WhitelistLive
|
||||
live "/live/blacklist", BlacklistLive
|
||||
live "/live/rules", RulesLive
|
||||
|
||||
resources "/password_resets", PasswordResetController, only: [:update, :new, :create]
|
||||
get "/password_resets/:reset_token", PasswordResetController, :edit
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<div class="content">
|
||||
<h3>Devices</h3>
|
||||
<h3 class="title">Devices</h3>
|
||||
|
||||
<table class="table">
|
||||
<thead>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<div class="content">
|
||||
<h3><%= @device.name %></h3>
|
||||
<h3 class="title"><%= @device.name %></h3>
|
||||
|
||||
<div class="columns">
|
||||
<div class="column is-6">
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<div class="columns">
|
||||
<div class="column is-4">
|
||||
<div class="content">
|
||||
<h3>Edit Account</h3>
|
||||
<h3 class="title">Edit Account</h3>
|
||||
|
||||
<%= form_for @changeset, Routes.user_path(@conn, :update), fn f -> %>
|
||||
<%= if @changeset.action do %>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<div class="columns">
|
||||
<div class="column is-4">
|
||||
<div class="content">
|
||||
<h3>Your Account</h3>
|
||||
<h3 class="title">Your Account</h3>
|
||||
|
||||
<dl>
|
||||
<dt>
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
defmodule FgHttp.DevicesTest do
|
||||
use FgHttp.DataCase
|
||||
import FgHttp.TestHelpers
|
||||
use FgHttp.DataCase, async: true
|
||||
alias FgHttp.Devices
|
||||
|
||||
describe "list_devices/0" do
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
defmodule FgHttpWeb.DeviceControllerUnauthedTest do
|
||||
use FgHttpWeb.ConnCase, async: true
|
||||
import FgHttp.TestHelpers
|
||||
|
||||
@update_attrs %{name: "some updated name"}
|
||||
|
||||
describe "index" do
|
||||
test "redirects to new session", %{unauthed_conn: conn} do
|
||||
@@ -11,32 +8,23 @@ defmodule FgHttpWeb.DeviceControllerUnauthedTest do
|
||||
end
|
||||
end
|
||||
|
||||
describe "create device" do
|
||||
describe "show" do
|
||||
setup [:create_device]
|
||||
|
||||
test "redirects to new session", %{unauthed_conn: conn, device: device} do
|
||||
test_conn = get(conn, Routes.device_path(conn, :show, device))
|
||||
assert redirected_to(test_conn) == Routes.session_path(test_conn, :new)
|
||||
end
|
||||
end
|
||||
|
||||
describe "create" do
|
||||
test "redirects to new session", %{unauthed_conn: conn} do
|
||||
test_conn = post(conn, Routes.device_path(conn, :create))
|
||||
assert redirected_to(test_conn) == Routes.session_path(test_conn, :new)
|
||||
end
|
||||
end
|
||||
|
||||
describe "edit device" do
|
||||
setup [:create_device]
|
||||
|
||||
test "redirects to new session", %{unauthed_conn: conn, device: device} do
|
||||
test_conn = get(conn, Routes.device_path(conn, :edit, device))
|
||||
assert redirected_to(test_conn) == Routes.session_path(test_conn, :new)
|
||||
end
|
||||
end
|
||||
|
||||
describe "update device" do
|
||||
setup [:create_device]
|
||||
|
||||
test "redirects to new session", %{unauthed_conn: conn, device: device} do
|
||||
test_conn = put(conn, Routes.device_path(conn, :update, device), device: @update_attrs)
|
||||
assert redirected_to(test_conn) == Routes.session_path(test_conn, :new)
|
||||
end
|
||||
end
|
||||
|
||||
describe "delete device" do
|
||||
describe "delete" do
|
||||
setup [:create_device]
|
||||
|
||||
test "redirects to new session", %{unauthed_conn: conn, device: device} do
|
||||
@@ -48,10 +36,6 @@ end
|
||||
|
||||
defmodule FgHttpWeb.DeviceControllerAuthedTest do
|
||||
use FgHttpWeb.ConnCase, async: true
|
||||
import FgHttp.TestHelpers
|
||||
|
||||
@update_attrs %{name: "some updated name"}
|
||||
@invalid_attrs %{public_key: nil}
|
||||
|
||||
describe "show" do
|
||||
setup [:create_device]
|
||||
@@ -67,12 +51,12 @@ defmodule FgHttpWeb.DeviceControllerAuthedTest do
|
||||
|
||||
test "lists all devices", %{authed_conn: conn, device: device} do
|
||||
test_conn = get(conn, Routes.device_path(conn, :index))
|
||||
assert html_response(test_conn, 200) =~ "Listing Devices"
|
||||
assert html_response(test_conn, 200) =~ "<h3 class=\"title\">Devices</h3>"
|
||||
assert html_response(test_conn, 200) =~ device.name
|
||||
end
|
||||
end
|
||||
|
||||
describe "create device" do
|
||||
describe "create" do
|
||||
test "redirects when data is valid", %{authed_conn: conn} do
|
||||
test_conn = post(conn, Routes.device_path(conn, :create))
|
||||
devices = FgHttp.Devices.list_devices()
|
||||
@@ -81,33 +65,7 @@ defmodule FgHttpWeb.DeviceControllerAuthedTest do
|
||||
end
|
||||
end
|
||||
|
||||
describe "edit device" do
|
||||
setup [:create_device]
|
||||
|
||||
test "renders form for editing chosen device", %{authed_conn: conn, device: device} do
|
||||
test_conn = get(conn, Routes.device_path(conn, :edit, device))
|
||||
assert html_response(test_conn, 200) =~ "Edit Device"
|
||||
end
|
||||
end
|
||||
|
||||
describe "update device" do
|
||||
setup [:create_device]
|
||||
|
||||
test "redirects when data is valid", %{authed_conn: conn, device: device} do
|
||||
test_conn = put(conn, Routes.device_path(conn, :update, device), device: @update_attrs)
|
||||
assert redirected_to(test_conn) == Routes.device_path(conn, :show, device)
|
||||
|
||||
test_conn = get(conn, Routes.device_path(conn, :show, device))
|
||||
assert html_response(test_conn, 200) =~ "some updated name"
|
||||
end
|
||||
|
||||
test "renders errors when data is invalid", %{authed_conn: conn, device: device} do
|
||||
conn = put(conn, Routes.device_path(conn, :update, device), device: @invalid_attrs)
|
||||
assert html_response(conn, 200) =~ "Edit Device"
|
||||
end
|
||||
end
|
||||
|
||||
describe "delete device" do
|
||||
describe "delete" do
|
||||
setup [:create_device]
|
||||
|
||||
test "deletes chosen device", %{authed_conn: conn, device: device} do
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
defmodule FgHttpWeb.DeviceDetailsLiveTest do
|
||||
use FgHttpWeb.ConnCase, async: true
|
||||
|
||||
setup :create_device
|
||||
|
||||
test "connected mount", %{authed_conn: conn, device: device} do
|
||||
path = Routes.device_path(conn, :show, device)
|
||||
{:ok, view, html} = live(conn, path)
|
||||
assert html =~ "<h3 class=\"title\">#{device.name}</h3>"
|
||||
end
|
||||
end
|
||||
3
apps/fg_http/test/fg_http_web/live/rules_live_test.exs
Normal file
3
apps/fg_http/test/fg_http_web/live/rules_live_test.exs
Normal file
@@ -0,0 +1,3 @@
|
||||
defmodule FgHttpWeb.RulesLiveTest do
|
||||
use FgHttpWeb.ConnCase, async: true
|
||||
end
|
||||
@@ -23,6 +23,7 @@ defmodule FgHttpWeb.ChannelCase do
|
||||
quote do
|
||||
# Import conveniences for testing with channels
|
||||
use Phoenix.ChannelTest
|
||||
import FgHttp.TestHelpers
|
||||
|
||||
# The default endpoint for testing
|
||||
@endpoint FgHttpWeb.Endpoint
|
||||
|
||||
@@ -26,6 +26,8 @@ defmodule FgHttpWeb.ConnCase do
|
||||
# Import conveniences for testing with connections
|
||||
import Plug.Conn
|
||||
import Phoenix.ConnTest
|
||||
import Phoenix.LiveViewTest
|
||||
import FgHttp.TestHelpers
|
||||
alias FgHttpWeb.Router.Helpers, as: Routes
|
||||
|
||||
# The default endpoint for testing
|
||||
|
||||
@@ -26,6 +26,7 @@ defmodule FgHttp.DataCase do
|
||||
import Ecto.Changeset
|
||||
import Ecto.Query
|
||||
import FgHttp.DataCase
|
||||
import FgHttp.TestHelpers
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user