add shops context, clothes and users-clothes
users-clothes is a many-to-many unique relationship
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
defmodule PokemonCouture.ShopsTest do
|
||||
use PokemonCouture.DataCase
|
||||
|
||||
alias PokemonCouture.Shops
|
||||
|
||||
describe "clothes" do
|
||||
alias PokemonCouture.Shops.Clothes
|
||||
|
||||
@valid_attrs %{game: "some game", location: "some location", name: "some name"}
|
||||
@update_attrs %{game: "some updated game", location: "some updated location", name: "some updated name"}
|
||||
@invalid_attrs %{game: nil, location: nil, name: nil}
|
||||
|
||||
def clothes_fixture(attrs \\ %{}) do
|
||||
{:ok, clothes} =
|
||||
attrs
|
||||
|> Enum.into(@valid_attrs)
|
||||
|> Shops.create_clothes()
|
||||
|
||||
clothes
|
||||
end
|
||||
|
||||
test "list_clothes/0 returns all clothes" do
|
||||
clothes = clothes_fixture()
|
||||
assert Shops.list_clothes() == [clothes]
|
||||
end
|
||||
|
||||
test "get_clothes!/1 returns the clothes with given id" do
|
||||
clothes = clothes_fixture()
|
||||
assert Shops.get_clothes!(clothes.id) == clothes
|
||||
end
|
||||
|
||||
test "create_clothes/1 with valid data creates a clothes" do
|
||||
assert {:ok, %Clothes{} = clothes} = Shops.create_clothes(@valid_attrs)
|
||||
assert clothes.game == "some game"
|
||||
assert clothes.location == "some location"
|
||||
assert clothes.name == "some name"
|
||||
end
|
||||
|
||||
test "create_clothes/1 with invalid data returns error changeset" do
|
||||
assert {:error, %Ecto.Changeset{}} = Shops.create_clothes(@invalid_attrs)
|
||||
end
|
||||
|
||||
test "update_clothes/2 with valid data updates the clothes" do
|
||||
clothes = clothes_fixture()
|
||||
assert {:ok, %Clothes{} = clothes} = Shops.update_clothes(clothes, @update_attrs)
|
||||
assert clothes.game == "some updated game"
|
||||
assert clothes.location == "some updated location"
|
||||
assert clothes.name == "some updated name"
|
||||
end
|
||||
|
||||
test "update_clothes/2 with invalid data returns error changeset" do
|
||||
clothes = clothes_fixture()
|
||||
assert {:error, %Ecto.Changeset{}} = Shops.update_clothes(clothes, @invalid_attrs)
|
||||
assert clothes == Shops.get_clothes!(clothes.id)
|
||||
end
|
||||
|
||||
test "delete_clothes/1 deletes the clothes" do
|
||||
clothes = clothes_fixture()
|
||||
assert {:ok, %Clothes{}} = Shops.delete_clothes(clothes)
|
||||
assert_raise Ecto.NoResultsError, fn -> Shops.get_clothes!(clothes.id) end
|
||||
end
|
||||
|
||||
test "change_clothes/1 returns a clothes changeset" do
|
||||
clothes = clothes_fixture()
|
||||
assert %Ecto.Changeset{} = Shops.change_clothes(clothes)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,88 @@
|
||||
defmodule PokemonCoutureWeb.ClothesControllerTest do
|
||||
use PokemonCoutureWeb.ConnCase
|
||||
|
||||
alias PokemonCouture.Shops
|
||||
|
||||
@create_attrs %{game: "some game", location: "some location", name: "some name"}
|
||||
@update_attrs %{game: "some updated game", location: "some updated location", name: "some updated name"}
|
||||
@invalid_attrs %{game: nil, location: nil, name: nil}
|
||||
|
||||
def fixture(:clothes) do
|
||||
{:ok, clothes} = Shops.create_clothes(@create_attrs)
|
||||
clothes
|
||||
end
|
||||
|
||||
describe "index" do
|
||||
test "lists all clothes", %{conn: conn} do
|
||||
conn = get(conn, Routes.clothes_path(conn, :index))
|
||||
assert html_response(conn, 200) =~ "Listing Clothes"
|
||||
end
|
||||
end
|
||||
|
||||
describe "new clothes" do
|
||||
test "renders form", %{conn: conn} do
|
||||
conn = get(conn, Routes.clothes_path(conn, :new))
|
||||
assert html_response(conn, 200) =~ "New Clothes"
|
||||
end
|
||||
end
|
||||
|
||||
describe "create clothes" do
|
||||
test "redirects to show when data is valid", %{conn: conn} do
|
||||
conn = post(conn, Routes.clothes_path(conn, :create), clothes: @create_attrs)
|
||||
|
||||
assert %{id: id} = redirected_params(conn)
|
||||
assert redirected_to(conn) == Routes.clothes_path(conn, :show, id)
|
||||
|
||||
conn = get(conn, Routes.clothes_path(conn, :show, id))
|
||||
assert html_response(conn, 200) =~ "Show Clothes"
|
||||
end
|
||||
|
||||
test "renders errors when data is invalid", %{conn: conn} do
|
||||
conn = post(conn, Routes.clothes_path(conn, :create), clothes: @invalid_attrs)
|
||||
assert html_response(conn, 200) =~ "New Clothes"
|
||||
end
|
||||
end
|
||||
|
||||
describe "edit clothes" do
|
||||
setup [:create_clothes]
|
||||
|
||||
test "renders form for editing chosen clothes", %{conn: conn, clothes: clothes} do
|
||||
conn = get(conn, Routes.clothes_path(conn, :edit, clothes))
|
||||
assert html_response(conn, 200) =~ "Edit Clothes"
|
||||
end
|
||||
end
|
||||
|
||||
describe "update clothes" do
|
||||
setup [:create_clothes]
|
||||
|
||||
test "redirects when data is valid", %{conn: conn, clothes: clothes} do
|
||||
conn = put(conn, Routes.clothes_path(conn, :update, clothes), clothes: @update_attrs)
|
||||
assert redirected_to(conn) == Routes.clothes_path(conn, :show, clothes)
|
||||
|
||||
conn = get(conn, Routes.clothes_path(conn, :show, clothes))
|
||||
assert html_response(conn, 200) =~ "some updated game"
|
||||
end
|
||||
|
||||
test "renders errors when data is invalid", %{conn: conn, clothes: clothes} do
|
||||
conn = put(conn, Routes.clothes_path(conn, :update, clothes), clothes: @invalid_attrs)
|
||||
assert html_response(conn, 200) =~ "Edit Clothes"
|
||||
end
|
||||
end
|
||||
|
||||
describe "delete clothes" do
|
||||
setup [:create_clothes]
|
||||
|
||||
test "deletes chosen clothes", %{conn: conn, clothes: clothes} do
|
||||
conn = delete(conn, Routes.clothes_path(conn, :delete, clothes))
|
||||
assert redirected_to(conn) == Routes.clothes_path(conn, :index)
|
||||
assert_error_sent 404, fn ->
|
||||
get(conn, Routes.clothes_path(conn, :show, clothes))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
defp create_clothes(_) do
|
||||
clothes = fixture(:clothes)
|
||||
%{clothes: clothes}
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user