AUTOGEN: Locations.

This commit is contained in:
codevictory
2021-03-30 22:40:29 +03:00
parent 200d695586
commit adacd91591
12 changed files with 474 additions and 0 deletions

View File

@@ -0,0 +1,72 @@
defmodule Runosaari.AreaTest do
use Runosaari.DataCase
alias Runosaari.Area
describe "locations" do
alias Runosaari.Area.Location
@valid_attrs %{address: "some address", description: "some description", max_seats: 42, name: "some name", reserved_seats: 42}
@update_attrs %{address: "some updated address", description: "some updated description", max_seats: 43, name: "some updated name", reserved_seats: 43}
@invalid_attrs %{address: nil, description: nil, max_seats: nil, name: nil, reserved_seats: nil}
def location_fixture(attrs \\ %{}) do
{:ok, location} =
attrs
|> Enum.into(@valid_attrs)
|> Area.create_location()
location
end
test "list_locations/0 returns all locations" do
location = location_fixture()
assert Area.list_locations() == [location]
end
test "get_location!/1 returns the location with given id" do
location = location_fixture()
assert Area.get_location!(location.id) == location
end
test "create_location/1 with valid data creates a location" do
assert {:ok, %Location{} = location} = Area.create_location(@valid_attrs)
assert location.address == "some address"
assert location.description == "some description"
assert location.max_seats == 42
assert location.name == "some name"
assert location.reserved_seats == 42
end
test "create_location/1 with invalid data returns error changeset" do
assert {:error, %Ecto.Changeset{}} = Area.create_location(@invalid_attrs)
end
test "update_location/2 with valid data updates the location" do
location = location_fixture()
assert {:ok, %Location{} = location} = Area.update_location(location, @update_attrs)
assert location.address == "some updated address"
assert location.description == "some updated description"
assert location.max_seats == 43
assert location.name == "some updated name"
assert location.reserved_seats == 43
end
test "update_location/2 with invalid data returns error changeset" do
location = location_fixture()
assert {:error, %Ecto.Changeset{}} = Area.update_location(location, @invalid_attrs)
assert location == Area.get_location!(location.id)
end
test "delete_location/1 deletes the location" do
location = location_fixture()
assert {:ok, %Location{}} = Area.delete_location(location)
assert_raise Ecto.NoResultsError, fn -> Area.get_location!(location.id) end
end
test "change_location/1 returns a location changeset" do
location = location_fixture()
assert %Ecto.Changeset{} = Area.change_location(location)
end
end
end

View File

@@ -0,0 +1,88 @@
defmodule RunosaariWeb.LocationControllerTest do
use RunosaariWeb.ConnCase
alias Runosaari.Area
@create_attrs %{address: "some address", description: "some description", max_seats: 42, name: "some name", reserved_seats: 42}
@update_attrs %{address: "some updated address", description: "some updated description", max_seats: 43, name: "some updated name", reserved_seats: 43}
@invalid_attrs %{address: nil, description: nil, max_seats: nil, name: nil, reserved_seats: nil}
def fixture(:location) do
{:ok, location} = Area.create_location(@create_attrs)
location
end
describe "index" do
test "lists all locations", %{conn: conn} do
conn = get(conn, Routes.location_path(conn, :index))
assert html_response(conn, 200) =~ "Listing Locations"
end
end
describe "new location" do
test "renders form", %{conn: conn} do
conn = get(conn, Routes.location_path(conn, :new))
assert html_response(conn, 200) =~ "New Location"
end
end
describe "create location" do
test "redirects to show when data is valid", %{conn: conn} do
conn = post(conn, Routes.location_path(conn, :create), location: @create_attrs)
assert %{id: id} = redirected_params(conn)
assert redirected_to(conn) == Routes.location_path(conn, :show, id)
conn = get(conn, Routes.location_path(conn, :show, id))
assert html_response(conn, 200) =~ "Show Location"
end
test "renders errors when data is invalid", %{conn: conn} do
conn = post(conn, Routes.location_path(conn, :create), location: @invalid_attrs)
assert html_response(conn, 200) =~ "New Location"
end
end
describe "edit location" do
setup [:create_location]
test "renders form for editing chosen location", %{conn: conn, location: location} do
conn = get(conn, Routes.location_path(conn, :edit, location))
assert html_response(conn, 200) =~ "Edit Location"
end
end
describe "update location" do
setup [:create_location]
test "redirects when data is valid", %{conn: conn, location: location} do
conn = put(conn, Routes.location_path(conn, :update, location), location: @update_attrs)
assert redirected_to(conn) == Routes.location_path(conn, :show, location)
conn = get(conn, Routes.location_path(conn, :show, location))
assert html_response(conn, 200) =~ "some updated address"
end
test "renders errors when data is invalid", %{conn: conn, location: location} do
conn = put(conn, Routes.location_path(conn, :update, location), location: @invalid_attrs)
assert html_response(conn, 200) =~ "Edit Location"
end
end
describe "delete location" do
setup [:create_location]
test "deletes chosen location", %{conn: conn, location: location} do
conn = delete(conn, Routes.location_path(conn, :delete, location))
assert redirected_to(conn) == Routes.location_path(conn, :index)
assert_error_sent 404, fn ->
get(conn, Routes.location_path(conn, :show, location))
end
end
end
defp create_location(_) do
location = fixture(:location)
%{location: location}
end
end