create gists
This commit is contained in:
parent
79a17290d5
commit
43a8412f06
90 changed files with 1777 additions and 2107 deletions
88
test/zoeyscomputer_web/controllers/gist_controller_test.exs
Normal file
88
test/zoeyscomputer_web/controllers/gist_controller_test.exs
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
defmodule ZoeyscomputerWeb.GistControllerTest do
|
||||
use ZoeyscomputerWeb.ConnCase
|
||||
|
||||
import Zoeyscomputer.GistsFixtures
|
||||
|
||||
alias Zoeyscomputer.Gists.Gist
|
||||
|
||||
@create_attrs %{
|
||||
code: "some code",
|
||||
lang: "some lang"
|
||||
}
|
||||
@update_attrs %{
|
||||
code: "some updated code",
|
||||
lang: "some updated lang"
|
||||
}
|
||||
@invalid_attrs %{code: nil, lang: nil}
|
||||
|
||||
setup %{conn: conn} do
|
||||
{:ok, conn: put_req_header(conn, "accept", "application/json")}
|
||||
end
|
||||
|
||||
describe "index" do
|
||||
test "lists all gists", %{conn: conn} do
|
||||
conn = get(conn, ~p"/api/gists")
|
||||
assert json_response(conn, 200)["data"] == []
|
||||
end
|
||||
end
|
||||
|
||||
describe "create gist" do
|
||||
test "renders gist when data is valid", %{conn: conn} do
|
||||
conn = post(conn, ~p"/api/gists", gist: @create_attrs)
|
||||
assert %{"id" => id} = json_response(conn, 201)["data"]
|
||||
|
||||
conn = get(conn, ~p"/api/gists/#{id}")
|
||||
|
||||
assert %{
|
||||
"id" => ^id,
|
||||
"code" => "some code",
|
||||
"lang" => "some lang"
|
||||
} = json_response(conn, 200)["data"]
|
||||
end
|
||||
|
||||
test "renders errors when data is invalid", %{conn: conn} do
|
||||
conn = post(conn, ~p"/api/gists", gist: @invalid_attrs)
|
||||
assert json_response(conn, 422)["errors"] != %{}
|
||||
end
|
||||
end
|
||||
|
||||
describe "update gist" do
|
||||
setup [:create_gist]
|
||||
|
||||
test "renders gist when data is valid", %{conn: conn, gist: %Gist{id: id} = gist} do
|
||||
conn = put(conn, ~p"/api/gists/#{gist}", gist: @update_attrs)
|
||||
assert %{"id" => ^id} = json_response(conn, 200)["data"]
|
||||
|
||||
conn = get(conn, ~p"/api/gists/#{id}")
|
||||
|
||||
assert %{
|
||||
"id" => ^id,
|
||||
"code" => "some updated code",
|
||||
"lang" => "some updated lang"
|
||||
} = json_response(conn, 200)["data"]
|
||||
end
|
||||
|
||||
test "renders errors when data is invalid", %{conn: conn, gist: gist} do
|
||||
conn = put(conn, ~p"/api/gists/#{gist}", gist: @invalid_attrs)
|
||||
assert json_response(conn, 422)["errors"] != %{}
|
||||
end
|
||||
end
|
||||
|
||||
describe "delete gist" do
|
||||
setup [:create_gist]
|
||||
|
||||
test "deletes chosen gist", %{conn: conn, gist: gist} do
|
||||
conn = delete(conn, ~p"/api/gists/#{gist}")
|
||||
assert response(conn, 204)
|
||||
|
||||
assert_error_sent 404, fn ->
|
||||
get(conn, ~p"/api/gists/#{gist}")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
defp create_gist(_) do
|
||||
gist = gist_fixture()
|
||||
%{gist: gist}
|
||||
end
|
||||
end
|
||||
113
test/zoeyscomputer_web/live/gist_live_test.exs
Normal file
113
test/zoeyscomputer_web/live/gist_live_test.exs
Normal file
|
|
@ -0,0 +1,113 @@
|
|||
defmodule ZoeyscomputerWeb.GistLiveTest do
|
||||
use ZoeyscomputerWeb.ConnCase
|
||||
|
||||
import Phoenix.LiveViewTest
|
||||
import Zoeyscomputer.GistsFixtures
|
||||
|
||||
@create_attrs %{code: "some code", lang: "some lang"}
|
||||
@update_attrs %{code: "some updated code", lang: "some updated lang"}
|
||||
@invalid_attrs %{code: nil, lang: nil}
|
||||
|
||||
defp create_gist(_) do
|
||||
gist = gist_fixture()
|
||||
%{gist: gist}
|
||||
end
|
||||
|
||||
describe "Index" do
|
||||
setup [:create_gist]
|
||||
|
||||
test "lists all gists", %{conn: conn, gist: gist} do
|
||||
{:ok, _index_live, html} = live(conn, ~p"/gists")
|
||||
|
||||
assert html =~ "Listing Gists"
|
||||
assert html =~ gist.code
|
||||
end
|
||||
|
||||
test "saves new gist", %{conn: conn} do
|
||||
{:ok, index_live, _html} = live(conn, ~p"/gists")
|
||||
|
||||
assert index_live |> element("a", "New Gist") |> render_click() =~
|
||||
"New Gist"
|
||||
|
||||
assert_patch(index_live, ~p"/gists/new")
|
||||
|
||||
assert index_live
|
||||
|> form("#gist-form", gist: @invalid_attrs)
|
||||
|> render_change() =~ "can't be blank"
|
||||
|
||||
assert index_live
|
||||
|> form("#gist-form", gist: @create_attrs)
|
||||
|> render_submit()
|
||||
|
||||
assert_patch(index_live, ~p"/gists")
|
||||
|
||||
html = render(index_live)
|
||||
assert html =~ "Gist created successfully"
|
||||
assert html =~ "some code"
|
||||
end
|
||||
|
||||
test "updates gist in listing", %{conn: conn, gist: gist} do
|
||||
{:ok, index_live, _html} = live(conn, ~p"/gists")
|
||||
|
||||
assert index_live |> element("#gists-#{gist.id} a", "Edit") |> render_click() =~
|
||||
"Edit Gist"
|
||||
|
||||
assert_patch(index_live, ~p"/gists/#{gist}/edit")
|
||||
|
||||
assert index_live
|
||||
|> form("#gist-form", gist: @invalid_attrs)
|
||||
|> render_change() =~ "can't be blank"
|
||||
|
||||
assert index_live
|
||||
|> form("#gist-form", gist: @update_attrs)
|
||||
|> render_submit()
|
||||
|
||||
assert_patch(index_live, ~p"/gists")
|
||||
|
||||
html = render(index_live)
|
||||
assert html =~ "Gist updated successfully"
|
||||
assert html =~ "some updated code"
|
||||
end
|
||||
|
||||
test "deletes gist in listing", %{conn: conn, gist: gist} do
|
||||
{:ok, index_live, _html} = live(conn, ~p"/gists")
|
||||
|
||||
assert index_live |> element("#gists-#{gist.id} a", "Delete") |> render_click()
|
||||
refute has_element?(index_live, "#gists-#{gist.id}")
|
||||
end
|
||||
end
|
||||
|
||||
describe "Show" do
|
||||
setup [:create_gist]
|
||||
|
||||
test "displays gist", %{conn: conn, gist: gist} do
|
||||
{:ok, _show_live, html} = live(conn, ~p"/gists/#{gist}")
|
||||
|
||||
assert html =~ "Show Gist"
|
||||
assert html =~ gist.code
|
||||
end
|
||||
|
||||
test "updates gist within modal", %{conn: conn, gist: gist} do
|
||||
{:ok, show_live, _html} = live(conn, ~p"/gists/#{gist}")
|
||||
|
||||
assert show_live |> element("a", "Edit") |> render_click() =~
|
||||
"Edit Gist"
|
||||
|
||||
assert_patch(show_live, ~p"/gists/#{gist}/show/edit")
|
||||
|
||||
assert show_live
|
||||
|> form("#gist-form", gist: @invalid_attrs)
|
||||
|> render_change() =~ "can't be blank"
|
||||
|
||||
assert show_live
|
||||
|> form("#gist-form", gist: @update_attrs)
|
||||
|> render_submit()
|
||||
|
||||
assert_patch(show_live, ~p"/gists/#{gist}")
|
||||
|
||||
html = render(show_live)
|
||||
assert html =~ "Gist updated successfully"
|
||||
assert html =~ "some updated code"
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue