mirror of
https://github.com/outbackdingo/firezone.git
synced 2026-01-27 10:18:54 +00:00
Mock authentication for tests
This commit is contained in:
@@ -8,15 +8,14 @@ defmodule FgHttpWeb.NewDeviceLive do
|
||||
alias FgHttp.Devices.Device
|
||||
alias FgHttpWeb.Router.Helpers, as: Routes
|
||||
|
||||
def mount(_params, %{}, socket) do
|
||||
user_id = "1"
|
||||
if connected?(socket), do: wait_for_device(socket)
|
||||
def mount(_params, %{"current_user_id" => user_id}, socket) do
|
||||
if connected?(socket), do: wait_for_device_connect(socket)
|
||||
|
||||
device = %Device{id: "1", user_id: user_id}
|
||||
{:ok, assign(socket, :device, device)}
|
||||
end
|
||||
|
||||
defp wait_for_device(_socket) do
|
||||
defp wait_for_device_connect(_socket) do
|
||||
# XXX: pass socket to fg_vpn somehow
|
||||
:timer.send_after(3000, self(), :update)
|
||||
end
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<h1>New Device</h1>
|
||||
|
||||
<%= live_render(@conn, FgHttpWeb.NewDeviceLive) %>
|
||||
<%= live_render(@conn, FgHttpWeb.NewDeviceLive, session: %{"current_user_id" => @conn.assigns.current_user.id}) %>
|
||||
|
||||
<p>
|
||||
<%= link "Back", to: Routes.device_path(@conn, :index) %>
|
||||
|
||||
@@ -27,6 +27,9 @@ defmodule FgHttpWeb.DeviceControllerTest do
|
||||
|
||||
describe "new device" do
|
||||
test "renders form", %{conn: conn} do
|
||||
# Mock authentication
|
||||
conn = Plug.Conn.assign(conn, :current_user, fixture(:user))
|
||||
|
||||
conn = get(conn, Routes.device_path(conn, :new))
|
||||
assert html_response(conn, 200) =~ "New Device"
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user