chore: generate resources for pastes

Signed-off-by: SphericalKat <amolele@gmail.com>
This commit is contained in:
sphericalkat committed 2021-08-12 03:28:28 +05:30
1 parent 5a7bece725
commit 99ad54cf68
13 files changed
+431

No files matched your search

+66
View File
@@ -0,0 +1,66 @@
defmodule Ketbin.PastesTest do
use Ketbin.DataCase
alias Ketbin.Pastes
describe "pastes" do
alias Ketbin.Pastes.Paste
@valid_attrs %{content: "some content", is_url: true}
@update_attrs %{content: "some updated content", is_url: false}
@invalid_attrs %{content: nil, is_url: nil}
def paste_fixture(attrs \\ %{}) do
{:ok, paste} =
attrs
|> Enum.into(@valid_attrs)
|> Pastes.create_paste()
paste
end
test "list_pastes/0 returns all pastes" do
paste = paste_fixture()
assert Pastes.list_pastes() == [paste]
end
test "get_paste!/1 returns the paste with given id" do
paste = paste_fixture()
assert Pastes.get_paste!(paste.id) == paste
end
test "create_paste/1 with valid data creates a paste" do
assert {:ok, %Paste{} = paste} = Pastes.create_paste(@valid_attrs)
assert paste.content == "some content"
assert paste.is_url == true
end
test "create_paste/1 with invalid data returns error changeset" do
assert {:error, %Ecto.Changeset{}} = Pastes.create_paste(@invalid_attrs)
end
test "update_paste/2 with valid data updates the paste" do
paste = paste_fixture()
assert {:ok, %Paste{} = paste} = Pastes.update_paste(paste, @update_attrs)
assert paste.content == "some updated content"
assert paste.is_url == false
end
test "update_paste/2 with invalid data returns error changeset" do
paste = paste_fixture()
assert {:error, %Ecto.Changeset{}} = Pastes.update_paste(paste, @invalid_attrs)
assert paste == Pastes.get_paste!(paste.id)
end
test "delete_paste/1 deletes the paste" do
paste = paste_fixture()
assert {:ok, %Paste{}} = Pastes.delete_paste(paste)
assert_raise Ecto.NoResultsError, fn -> Pastes.get_paste!(paste.id) end
end
test "change_paste/1 returns a paste changeset" do
paste = paste_fixture()
assert %Ecto.Changeset{} = Pastes.change_paste(paste)
end
end
end
@@ -0,0 +1,88 @@
defmodule KetbinWeb.PasteControllerTest do
use KetbinWeb.ConnCase
alias Ketbin.Pastes
@create_attrs %{content: "some content", is_url: true}
@update_attrs %{content: "some updated content", is_url: false}
@invalid_attrs %{content: nil, is_url: nil}
def fixture(:paste) do
{:ok, paste} = Pastes.create_paste(@create_attrs)
paste
end
describe "index" do
test "lists all pastes", %{conn: conn} do
conn = get(conn, Routes.paste_path(conn, :index))
assert html_response(conn, 200) =~ "Listing Pastes"
end
end
describe "new paste" do
test "renders form", %{conn: conn} do
conn = get(conn, Routes.paste_path(conn, :new))
assert html_response(conn, 200) =~ "New Paste"
end
end
describe "create paste" do
test "redirects to show when data is valid", %{conn: conn} do
conn = post(conn, Routes.paste_path(conn, :create), paste: @create_attrs)
assert %{id: id} = redirected_params(conn)
assert redirected_to(conn) == Routes.paste_path(conn, :show, id)
conn = get(conn, Routes.paste_path(conn, :show, id))
assert html_response(conn, 200) =~ "Show Paste"
end
test "renders errors when data is invalid", %{conn: conn} do
conn = post(conn, Routes.paste_path(conn, :create), paste: @invalid_attrs)
assert html_response(conn, 200) =~ "New Paste"
end
end
describe "edit paste" do
setup [:create_paste]
test "renders form for editing chosen paste", %{conn: conn, paste: paste} do
conn = get(conn, Routes.paste_path(conn, :edit, paste))
assert html_response(conn, 200) =~ "Edit Paste"
end
end
describe "update paste" do
setup [:create_paste]
test "redirects when data is valid", %{conn: conn, paste: paste} do
conn = put(conn, Routes.paste_path(conn, :update, paste), paste: @update_attrs)
assert redirected_to(conn) == Routes.paste_path(conn, :show, paste)
conn = get(conn, Routes.paste_path(conn, :show, paste))
assert html_response(conn, 200) =~ "some updated content"
end
test "renders errors when data is invalid", %{conn: conn, paste: paste} do
conn = put(conn, Routes.paste_path(conn, :update, paste), paste: @invalid_attrs)
assert html_response(conn, 200) =~ "Edit Paste"
end
end
describe "delete paste" do
setup [:create_paste]
test "deletes chosen paste", %{conn: conn, paste: paste} do
conn = delete(conn, Routes.paste_path(conn, :delete, paste))
assert redirected_to(conn) == Routes.paste_path(conn, :index)
assert_error_sent 404, fn ->
get(conn, Routes.paste_path(conn, :show, paste))
end
end
end
defp create_paste(_) do
paste = fixture(:paste)
%{paste: paste}
end
end