Skip to content

Commit

Permalink
Add test for new credential and credential live
Browse files Browse the repository at this point in the history
  • Loading branch information
zacksiri committed Feb 27, 2024
1 parent 4f918e2 commit 4bb0bca
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
36 changes: 36 additions & 0 deletions test/polar_web/live/dashboard/credential/new_live_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
defmodule PolarWeb.Dashboard.Credential.NewLiveTest do
use PolarWeb.ConnCase, async: true

import Phoenix.LiveViewTest
import Polar.AccountsFixtures

alias Polar.Repo
alias Polar.Accounts
alias Polar.Accounts.Space

setup %{conn: conn} do
user = user_fixture()

conn = log_in_user(conn, user)

{:ok, space} = Accounts.create_space(user, %{name: "test-space-456"})

%{conn: conn, space: space}
end

describe "New credential creation" do
test "create credential", %{conn: conn, space: space} do
{:ok, lv, _html} = live(conn, ~p"/dashboard/spaces/#{space.id}/credentials/new")

lv
|> form("#new-credential-form", %{
"credential" => %{"name" => "new-cred-test", "type" => "lxd", "expires_in" => "2592000"}
})
|> render_submit()

credential = Repo.get_by!(Space.Credential, name: "new-cred-test")

assert_redirect(lv, ~p"/dashboard/spaces/#{space.id}/credentials/#{credential.id}")
end
end
end
34 changes: 34 additions & 0 deletions test/polar_web/live/dashboard/credential_live_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
defmodule PolarWeb.Dashboard.CredentialLiveTest do
use PolarWeb.ConnCase, async: true

import Phoenix.LiveViewTest
import Polar.AccountsFixtures

alias Polar.Accounts

setup %{conn: conn} do
user = user_fixture()

{:ok, space} = Accounts.create_space(user, %{name: "test-space-123"})

{:ok, credential} =
Accounts.create_space_credential(space, user, %{
expires_in: 1_296_000,
name: "test-cred",
type: "lxd"
})

conn = log_in_user(conn, user)

%{conn: conn, user: user, space: space, credential: credential}
end

describe "credential detail" do
test "can see detail of credential", %{conn: conn, space: space, credential: credential} do
{:ok, _lv, html} =
live(conn, ~p"/dashboard/spaces/#{space.id}/credentials/#{credential.id}")

assert html =~ "lxc remote add opsmaru"
end
end
end

0 comments on commit 4bb0bca

Please sign in to comment.