-
+
<%= order.user_id %> |
-
+
<%= order.menu_id %> |
-
- <%= order.lunch_order_id %> |
-
+
+ <%= order.office_lunch_order_id %> |
+
<%= link "Show", to: Routes.admin_order_path(@conn, :show, order) %>
<%= link "Edit", to: Routes.admin_order_path(@conn, :edit, order) %>
diff --git a/lib/lunchbot_web/templates/admin/order/show.html.heex b/lib/lunchbot_web/templates/admin/order/show.html.heex
index eb7d13f..af4b0b3 100644
--- a/lib/lunchbot_web/templates/admin/order/show.html.heex
+++ b/lib/lunchbot_web/templates/admin/order/show.html.heex
@@ -11,22 +11,22 @@
Order Details
-
+
User:
<%= @order.user_id %>
-
+
Menu:
<%= @order.menu_id %>
-
+
Lunch order:
- <%= @order.lunch_order_id %>
+ <%= @order.office_lunch_order_id %>
-
+
diff --git a/mix.exs b/mix.exs
index 4c4a10b..a068b86 100644
--- a/mix.exs
+++ b/mix.exs
@@ -58,7 +58,8 @@ defmodule Lunchbot.MixProject do
{:dotenv, "~> 3.0.0", only: [:dev, :test]},
{:mox, "~> 1.0", only: :test},
{:phoenix_pubsub, "~> 2.0"},
- {:csv, "~> 2.4"}
+ {:csv, "~> 2.4"},
+ {:faker, "~> 0.17"}
]
end
diff --git a/mix.lock b/mix.lock
index 78930e3..fa89f43 100644
--- a/mix.lock
+++ b/mix.lock
@@ -18,6 +18,7 @@
"elixir_auth_google": {:hex, :elixir_auth_google, "1.6.3", "13f9fcecc32d8a0e5eee5d24419d603dbec495fcc9c60ac314d64ba4af17fc83", [:mix], [{:httpoison, "~> 1.8.0", [hex: :httpoison, repo: "hexpm", optional: false]}, {:jason, "~> 1.2", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "6c0e9852879b22ac20908ca155cfe389fc099de6075359adbffe5a3d8fa8592f"},
"elixir_make": {:hex, :elixir_make, "0.6.3", "bc07d53221216838d79e03a8019d0839786703129599e9619f4ab74c8c096eac", [:mix], [], "hexpm", "f5cbd651c5678bcaabdbb7857658ee106b12509cd976c2c2fca99688e1daf716"},
"esbuild": {:hex, :esbuild, "0.5.0", "d5bb08ff049d7880ee3609ed5c4b864bd2f46445ea40b16b4acead724fb4c4a3", [:mix], [{:castore, ">= 0.0.0", [hex: :castore, repo: "hexpm", optional: false]}], "hexpm", "f183a0b332d963c4cfaf585477695ea59eef9a6f2204fdd0efa00e099694ffe5"},
+ "faker": {:hex, :faker, "0.17.0", "671019d0652f63aefd8723b72167ecdb284baf7d47ad3a82a15e9b8a6df5d1fa", [:mix], [], "hexpm", "a7d4ad84a93fd25c5f5303510753789fc2433ff241bf3b4144d3f6f291658a6a"},
"file_system": {:hex, :file_system, "0.2.10", "fb082005a9cd1711c05b5248710f8826b02d7d1784e7c3451f9c1231d4fc162d", [:mix], [], "hexpm", "41195edbfb562a593726eda3b3e8b103a309b733ad25f3d642ba49696bf715dc"},
"filtrex": {:hex, :filtrex, "0.4.3", "d59e496d385b19df7e3a613ad74deca4ac5ef1666352e9e435e8442fc9ae4c70", [:mix], [{:ecto, "~> 3.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:ecto_sql, "~> 3.0", [hex: :ecto_sql, repo: "hexpm", optional: false]}, {:timex, "~> 3.1", [hex: :timex, repo: "hexpm", optional: false]}], "hexpm", "a374999d00174c3a6c617def9c9d199a2bc5928d49a227d1de622ccbadbff1d0"},
"floki": {:hex, :floki, "0.33.1", "f20f1eb471e726342b45ccb68edb9486729e7df94da403936ea94a794f072781", [:mix], [{:html_entities, "~> 0.5.0", [hex: :html_entities, repo: "hexpm", optional: false]}], "hexpm", "461035fd125f13fdf30f243c85a0b1e50afbec876cbf1ceefe6fddd2e6d712c6"},
diff --git a/priv/repo/migrations/20221111144507_add_references_to_orders.exs b/priv/repo/migrations/20221111144507_add_references_to_orders.exs
new file mode 100644
index 0000000..d734b0f
--- /dev/null
+++ b/priv/repo/migrations/20221111144507_add_references_to_orders.exs
@@ -0,0 +1,24 @@
+defmodule Lunchbot.Repo.Migrations.AddReferencesToOrders do
+ use Ecto.Migration
+
+ def change do
+ alter table(:orders) do
+ modify :user_id, references(:users, on_delete: :nilify_all)
+ # restrict means you can't delete menu_id if there are still orders that reference that menu
+ modify :menu_id, references(:menus, on_delete: :restrict)
+ modify :lunch_order_id, references(:office_lunch_orders, on_delete: :delete_all)
+ end
+
+ rename table(:orders), :lunch_order_id, to: :office_lunch_order_id
+
+ alter table(:order_items) do
+ modify :order_id, references(:orders, on_delete: :delete_all)
+ modify :item_id, references(:items, on_delete: :restrict)
+ end
+
+ alter table(:order_item_options) do
+ modify :order_item_id, references(:order_items, on_delete: :delete_all)
+ modify :option_id, references(:options, on_delete: :restrict)
+ end
+ end
+end
diff --git a/priv/repo/migrations/20221122220955_add_references_to_menu.exs b/priv/repo/migrations/20221122220955_add_references_to_menu.exs
new file mode 100644
index 0000000..f7ba036
--- /dev/null
+++ b/priv/repo/migrations/20221122220955_add_references_to_menu.exs
@@ -0,0 +1,9 @@
+defmodule Lunchbot.Repo.Migrations.AddReferencesToMenu do
+ use Ecto.Migration
+
+ def change do
+ alter table(:menus) do
+ modify :office_id, references(:offices, on_delete: :delete_all)
+ end
+ end
+end
diff --git a/test/lunchbot/lunchbot_data_test.exs b/test/lunchbot/lunchbot_data_test.exs
index 64e5701..97b4244 100644
--- a/test/lunchbot/lunchbot_data_test.exs
+++ b/test/lunchbot/lunchbot_data_test.exs
@@ -6,6 +6,7 @@ defmodule Lunchbot.LunchbotDataTest do
alias Lunchbot.Accounts
alias Lunchbot.Accounts.User
+ alias Lunchbot.LunchbotDataFixtures
@valid_attrs %{
name: "some name",
@@ -51,14 +52,14 @@ defmodule Lunchbot.LunchbotDataTest do
describe "#list_users/0" do
test "returns all users" do
- user = Map.replace!(user_fixture(), :password, nil)
+ user = Map.replace!(LunchbotDataFixtures.user_fixture(), :password, nil)
assert Accounts.list_users() == [user]
end
end
describe "#get_user!/1" do
test "returns the user with given id" do
- user = Map.replace!(user_fixture(), :password, nil)
+ user = Map.replace!(LunchbotDataFixtures.user_fixture(), :password, nil)
assert Accounts.get_user!(user.id) == user
end
end
@@ -78,7 +79,7 @@ defmodule Lunchbot.LunchbotDataTest do
describe "#update_user/2" do
test "with valid data updates the user" do
- user = user_fixture()
+ user = LunchbotDataFixtures.user_fixture()
assert {:ok, user} = Accounts.update_user(user, @update_attrs)
assert %User{} = user
assert user.name == "some updated name"
@@ -87,7 +88,7 @@ defmodule Lunchbot.LunchbotDataTest do
end
test "with invalid data returns error changeset" do
- user = Map.replace!(user_fixture(), :password, nil)
+ user = Map.replace!(LunchbotDataFixtures.user_fixture(), :password, nil)
assert {:error, %Ecto.Changeset{}} = Accounts.update_user(user, @invalid_attrs)
assert user == Accounts.get_user!(user.id)
end
@@ -95,7 +96,7 @@ defmodule Lunchbot.LunchbotDataTest do
describe "#delete_user/1" do
test "deletes the user" do
- user = user_fixture()
+ user = LunchbotDataFixtures.user_fixture()
assert {:ok, %User{}} = Accounts.delete_user(user)
assert_raise Ecto.NoResultsError, fn -> Accounts.get_user!(user.id) end
end
@@ -103,20 +104,11 @@ defmodule Lunchbot.LunchbotDataTest do
describe "#change_user/1" do
test "returns a user changeset" do
- user = user_fixture()
+ user = LunchbotDataFixtures.user_fixture()
assert %Ecto.Changeset{} = Accounts.change_user(user)
end
end
- def user_fixture(attrs \\ %{}) do
- {:ok, user} =
- attrs
- |> Enum.into(@valid_attrs)
- |> Accounts.create_user()
-
- user
- end
-
alias Lunchbot.LunchbotData.Office
@valid_attrs %{name: "some name", timezone: "some timezone"}
@@ -126,7 +118,7 @@ defmodule Lunchbot.LunchbotDataTest do
describe "#paginate_offices/1" do
test "returns paginated list of offices" do
for _ <- 1..20 do
- office_fixture()
+ LunchbotDataFixtures.office_fixture()
end
{:ok, %{offices: offices} = page} = LunchbotData.paginate_offices(%{})
@@ -144,14 +136,14 @@ defmodule Lunchbot.LunchbotDataTest do
describe "#list_offices/0" do
test "returns all offices" do
- office = office_fixture()
+ office = LunchbotDataFixtures.office_fixture()
assert LunchbotData.list_offices() == [office]
end
end
describe "#get_office!/1" do
test "returns the office with given id" do
- office = office_fixture()
+ office = LunchbotDataFixtures.office_fixture()
assert LunchbotData.get_office!(office.id) == office
end
end
@@ -170,7 +162,7 @@ defmodule Lunchbot.LunchbotDataTest do
describe "#update_office/2" do
test "with valid data updates the office" do
- office = office_fixture()
+ office = LunchbotDataFixtures.office_fixture()
assert {:ok, office} = LunchbotData.update_office(office, @update_attrs)
assert %Office{} = office
assert office.name == "some updated name"
@@ -178,7 +170,7 @@ defmodule Lunchbot.LunchbotDataTest do
end
test "with invalid data returns error changeset" do
- office = office_fixture()
+ office = LunchbotDataFixtures.office_fixture()
assert {:error, %Ecto.Changeset{}} = LunchbotData.update_office(office, @invalid_attrs)
assert office == LunchbotData.get_office!(office.id)
end
@@ -186,7 +178,7 @@ defmodule Lunchbot.LunchbotDataTest do
describe "#delete_office/1" do
test "deletes the office" do
- office = office_fixture()
+ office = LunchbotDataFixtures.office_fixture()
assert {:ok, %Office{}} = LunchbotData.delete_office(office)
assert_raise Ecto.NoResultsError, fn -> LunchbotData.get_office!(office.id) end
end
@@ -194,20 +186,11 @@ defmodule Lunchbot.LunchbotDataTest do
describe "#change_office/1" do
test "returns a office changeset" do
- office = office_fixture()
+ office = LunchbotDataFixtures.office_fixture()
assert %Ecto.Changeset{} = LunchbotData.change_office(office)
end
end
- def office_fixture(attrs \\ %{}) do
- {:ok, office} =
- attrs
- |> Enum.into(@valid_attrs)
- |> LunchbotData.create_office()
-
- office
- end
-
alias Lunchbot.LunchbotData.Menu
@valid_attrs %{name: "some name", office_id: 42}
@@ -217,7 +200,7 @@ defmodule Lunchbot.LunchbotDataTest do
describe "#paginate_menus/1" do
test "returns paginated list of menus" do
for _ <- 1..20 do
- menu_fixture()
+ LunchbotDataFixtures.menu_fixture()
end
{:ok, %{menus: menus} = page} = LunchbotData.paginate_menus(%{})
@@ -235,23 +218,30 @@ defmodule Lunchbot.LunchbotDataTest do
describe "#list_menus/0" do
test "returns all menus" do
- menu = menu_fixture()
+ menu = LunchbotDataFixtures.menu_fixture()
assert LunchbotData.list_menus() == [menu]
end
end
describe "#get_menu!/1" do
test "returns the menu with given id" do
- menu = menu_fixture()
+ menu = LunchbotDataFixtures.menu_fixture()
assert LunchbotData.get_menu!(menu.id) == menu
end
end
describe "#create_menu/1" do
test "with valid data creates a menu" do
- assert {:ok, %Menu{} = menu} = LunchbotData.create_menu(@valid_attrs)
- assert menu.name == "some name"
- assert menu.office_id == 42
+ office = LunchbotDataFixtures.office_fixture()
+
+ params = %{
+ name: "Pizza Master",
+ office_id: office.id
+ }
+
+ assert {:ok, %Menu{} = menu} = LunchbotData.create_menu(params)
+ assert menu.name == params.name
+ assert menu.office_id == office.id
end
test "with invalid data returns error changeset" do
@@ -261,15 +251,22 @@ defmodule Lunchbot.LunchbotDataTest do
describe "#update_menu/2" do
test "with valid data updates the menu" do
- menu = menu_fixture()
- assert {:ok, menu} = LunchbotData.update_menu(menu, @update_attrs)
+ menu = LunchbotDataFixtures.menu_fixture()
+ office = LunchbotDataFixtures.office_fixture()
+
+ params = %{
+ name: "Chowder Hound",
+ office_id: office.id
+ }
+
+ assert {:ok, menu} = LunchbotData.update_menu(menu, params)
assert %Menu{} = menu
- assert menu.name == "some updated name"
- assert menu.office_id == 43
+ assert menu.name == params.name
+ assert menu.office_id == office.id
end
test "with invalid data returns error changeset" do
- menu = menu_fixture()
+ menu = LunchbotDataFixtures.menu_fixture()
assert {:error, %Ecto.Changeset{}} = LunchbotData.update_menu(menu, @invalid_attrs)
assert menu == LunchbotData.get_menu!(menu.id)
end
@@ -277,7 +274,7 @@ defmodule Lunchbot.LunchbotDataTest do
describe "#delete_menu/1" do
test "deletes the menu" do
- menu = menu_fixture()
+ menu = LunchbotDataFixtures.menu_fixture()
assert {:ok, %Menu{}} = LunchbotData.delete_menu(menu)
assert_raise Ecto.NoResultsError, fn -> LunchbotData.get_menu!(menu.id) end
end
@@ -285,20 +282,11 @@ defmodule Lunchbot.LunchbotDataTest do
describe "#change_menu/1" do
test "returns a menu changeset" do
- menu = menu_fixture()
+ menu = LunchbotDataFixtures.menu_fixture()
assert %Ecto.Changeset{} = LunchbotData.change_menu(menu)
end
end
- def menu_fixture(attrs \\ %{}) do
- {:ok, menu} =
- attrs
- |> Enum.into(@valid_attrs)
- |> LunchbotData.create_menu()
-
- menu
- end
-
alias Lunchbot.LunchbotData.OfficeLunchOrder
@valid_attrs %{day: ~D[2022-07-07], office_id: 42, menu_id: 42}
@@ -308,7 +296,7 @@ defmodule Lunchbot.LunchbotDataTest do
describe "#paginate_office_lunch_orders/1" do
test "returns paginated list of office_lunch_orders" do
for _ <- 1..20 do
- office_lunch_order_fixture()
+ LunchbotDataFixtures.office_lunch_order_fixture()
end
{:ok, %{office_lunch_orders: office_lunch_orders} = page} =
@@ -327,14 +315,14 @@ defmodule Lunchbot.LunchbotDataTest do
describe "#list_office_lunch_orders/0" do
test "returns all office_lunch_orders" do
- office_lunch_order = office_lunch_order_fixture()
+ office_lunch_order = LunchbotDataFixtures.office_lunch_order_fixture()
assert LunchbotData.list_office_lunch_orders() == [office_lunch_order]
end
end
describe "#get_office_lunch_order!/1" do
test "returns the office_lunch_order with given id" do
- office_lunch_order = office_lunch_order_fixture()
+ office_lunch_order = LunchbotDataFixtures.office_lunch_order_fixture()
assert LunchbotData.get_office_lunch_order!(office_lunch_order.id) == office_lunch_order
end
end
@@ -355,7 +343,7 @@ defmodule Lunchbot.LunchbotDataTest do
describe "#update_office_lunch_order/2" do
test "with valid data updates the office_lunch_order" do
- office_lunch_order = office_lunch_order_fixture()
+ office_lunch_order = LunchbotDataFixtures.office_lunch_order_fixture()
assert {:ok, office_lunch_order} =
LunchbotData.update_office_lunch_order(office_lunch_order, @update_attrs)
@@ -366,7 +354,7 @@ defmodule Lunchbot.LunchbotDataTest do
end
test "with invalid data returns error changeset" do
- office_lunch_order = office_lunch_order_fixture()
+ office_lunch_order = LunchbotDataFixtures.office_lunch_order_fixture()
assert {:error, %Ecto.Changeset{}} =
LunchbotData.update_office_lunch_order(office_lunch_order, @invalid_attrs)
@@ -377,7 +365,7 @@ defmodule Lunchbot.LunchbotDataTest do
describe "#delete_office_lunch_order/1" do
test "deletes the office_lunch_order" do
- office_lunch_order = office_lunch_order_fixture()
+ office_lunch_order = LunchbotDataFixtures.office_lunch_order_fixture()
assert {:ok, %OfficeLunchOrder{}} =
LunchbotData.delete_office_lunch_order(office_lunch_order)
@@ -390,30 +378,21 @@ defmodule Lunchbot.LunchbotDataTest do
describe "#change_office_lunch_order/1" do
test "returns a office_lunch_order changeset" do
- office_lunch_order = office_lunch_order_fixture()
+ office_lunch_order = LunchbotDataFixtures.office_lunch_order_fixture()
assert %Ecto.Changeset{} = LunchbotData.change_office_lunch_order(office_lunch_order)
end
end
- def office_lunch_order_fixture(attrs \\ %{}) do
- {:ok, office_lunch_order} =
- attrs
- |> Enum.into(@valid_attrs)
- |> LunchbotData.create_office_lunch_order()
-
- office_lunch_order
- end
-
alias Lunchbot.LunchbotData.Order
- @valid_attrs %{lunch_order_id: 42, menu_id: 42, user_id: 42}
- @update_attrs %{lunch_order_id: 43, menu_id: 43, user_id: 43}
- @invalid_attrs %{lunch_order_id: nil, menu_id: nil, user_id: nil}
+ @valid_attrs %{office_lunch_order_id: 42, menu_id: 42, user_id: 42}
+ @update_attrs %{office_lunch_order_id: 43, menu_id: 43, user_id: 43}
+ @invalid_attrs %{office_lunch_order_id: nil, menu_id: nil, user_id: nil}
describe "#paginate_orders/1" do
test "returns paginated list of orders" do
for _ <- 1..20 do
- order_fixture()
+ LunchbotDataFixtures.order_fixture()
end
{:ok, %{orders: orders} = page} = LunchbotData.paginate_orders(%{})
@@ -431,24 +410,34 @@ defmodule Lunchbot.LunchbotDataTest do
describe "#list_orders/0" do
test "returns all orders" do
- order = order_fixture()
+ order = LunchbotDataFixtures.order_fixture()
assert LunchbotData.list_orders() == [order]
end
end
describe "#get_order!/1" do
test "returns the order with given id" do
- order = order_fixture()
+ order = LunchbotDataFixtures.order_fixture()
assert LunchbotData.get_order!(order.id) == order
end
end
describe "#create_order/1" do
test "with valid data creates a order" do
- assert {:ok, %Order{} = order} = LunchbotData.create_order(@valid_attrs)
- assert order.lunch_order_id == 42
- assert order.menu_id == 42
- assert order.user_id == 42
+ office_lunch_order = LunchbotDataFixtures.office_lunch_order_fixture()
+ menu = LunchbotDataFixtures.menu_fixture()
+ user = LunchbotDataFixtures.user_fixture()
+
+ params = %{
+ office_lunch_order_id: office_lunch_order.id,
+ menu_id: menu.id,
+ user_id: user.id
+ }
+
+ assert {:ok, %Order{} = order} = LunchbotData.create_order(params)
+ assert order.office_lunch_order_id == office_lunch_order.id
+ assert order.menu_id == menu.id
+ assert order.user_id == user.id
end
test "with invalid data returns error changeset" do
@@ -458,16 +447,23 @@ defmodule Lunchbot.LunchbotDataTest do
describe "#update_order/2" do
test "with valid data updates the order" do
- order = order_fixture()
- assert {:ok, order} = LunchbotData.update_order(order, @update_attrs)
+ order = LunchbotDataFixtures.order_fixture()
+ office_lunch_order = LunchbotDataFixtures.office_lunch_order_fixture()
+ menu = LunchbotDataFixtures.menu_fixture()
+ user = LunchbotDataFixtures.user_fixture()
+
+ params = %{
+ menu_id: menu.id,
+ office_lunch_order_id: office_lunch_order.id,
+ user_id: user.id
+ }
+
+ assert {:ok, order} = LunchbotData.update_order(order, params)
assert %Order{} = order
- assert order.lunch_order_id == 43
- assert order.menu_id == 43
- assert order.user_id == 43
end
test "with invalid data returns error changeset" do
- order = order_fixture()
+ order = LunchbotDataFixtures.order_fixture()
assert {:error, %Ecto.Changeset{}} = LunchbotData.update_order(order, @invalid_attrs)
assert order == LunchbotData.get_order!(order.id)
end
@@ -475,7 +471,7 @@ defmodule Lunchbot.LunchbotDataTest do
describe "#delete_order/1" do
test "deletes the order" do
- order = order_fixture()
+ order = LunchbotDataFixtures.order_fixture()
assert {:ok, %Order{}} = LunchbotData.delete_order(order)
assert_raise Ecto.NoResultsError, fn -> LunchbotData.get_order!(order.id) end
end
@@ -483,20 +479,11 @@ defmodule Lunchbot.LunchbotDataTest do
describe "#change_order/1" do
test "returns a order changeset" do
- order = order_fixture()
+ order = LunchbotDataFixtures.order_fixture()
assert %Ecto.Changeset{} = LunchbotData.change_order(order)
end
end
- def order_fixture(attrs \\ %{}) do
- {:ok, order} =
- attrs
- |> Enum.into(@valid_attrs)
- |> LunchbotData.create_order()
-
- order
- end
-
alias Lunchbot.LunchbotData.Category
@valid_attrs %{name: "some name"}
@@ -506,7 +493,7 @@ defmodule Lunchbot.LunchbotDataTest do
describe "#paginate_categories/1" do
test "returns paginated list of categories" do
for _ <- 1..20 do
- category_fixture()
+ LunchbotDataFixtures.category_fixture()
end
{:ok, %{categories: categories} = page} = LunchbotData.paginate_categories(%{})
@@ -524,14 +511,14 @@ defmodule Lunchbot.LunchbotDataTest do
describe "#list_categories/0" do
test "returns all categories" do
- category = category_fixture()
+ category = LunchbotDataFixtures.category_fixture()
assert LunchbotData.list_categories() == [category]
end
end
describe "#get_category!/1" do
test "returns the category with given id" do
- category = category_fixture()
+ category = LunchbotDataFixtures.category_fixture()
assert LunchbotData.get_category!(category.id) == category
end
end
@@ -549,14 +536,14 @@ defmodule Lunchbot.LunchbotDataTest do
describe "#update_category/2" do
test "with valid data updates the category" do
- category = category_fixture()
+ category = LunchbotDataFixtures.category_fixture()
assert {:ok, category} = LunchbotData.update_category(category, @update_attrs)
assert %Category{} = category
assert category.name == "some updated name"
end
test "with invalid data returns error changeset" do
- category = category_fixture()
+ category = LunchbotDataFixtures.category_fixture()
assert {:error, %Ecto.Changeset{}} = LunchbotData.update_category(category, @invalid_attrs)
assert category == LunchbotData.get_category!(category.id)
end
@@ -564,7 +551,7 @@ defmodule Lunchbot.LunchbotDataTest do
describe "#delete_category/1" do
test "deletes the category" do
- category = category_fixture()
+ category = LunchbotDataFixtures.category_fixture()
assert {:ok, %Category{}} = LunchbotData.delete_category(category)
assert_raise Ecto.NoResultsError, fn -> LunchbotData.get_category!(category.id) end
end
@@ -572,20 +559,11 @@ defmodule Lunchbot.LunchbotDataTest do
describe "#change_category/1" do
test "returns a category changeset" do
- category = category_fixture()
+ category = LunchbotDataFixtures.category_fixture()
assert %Ecto.Changeset{} = LunchbotData.change_category(category)
end
end
- def category_fixture(attrs \\ %{}) do
- {:ok, category} =
- attrs
- |> Enum.into(@valid_attrs)
- |> LunchbotData.create_category()
-
- category
- end
-
alias Lunchbot.LunchbotData.OrderItem
@valid_attrs %{item_id: 42, order_id: 42}
@@ -595,7 +573,7 @@ defmodule Lunchbot.LunchbotDataTest do
describe "#paginate_order_items/1" do
test "returns paginated list of order_items" do
for _ <- 1..20 do
- order_item_fixture()
+ LunchbotDataFixtures.order_item_fixture()
end
{:ok, %{order_items: order_items} = page} = LunchbotData.paginate_order_items(%{})
@@ -613,23 +591,32 @@ defmodule Lunchbot.LunchbotDataTest do
describe "#list_order_items/0" do
test "returns all order_items" do
- order_item = order_item_fixture()
+ item = LunchbotDataFixtures.item_fixture()
+ order = LunchbotDataFixtures.order_fixture()
+
+ order_item =
+ LunchbotDataFixtures.order_item_fixture(%{item_id: item.id, order_id: order.id})
+
assert LunchbotData.list_order_items() == [order_item]
end
end
describe "#get_order_item!/1" do
test "returns the order_item with given id" do
- order_item = order_item_fixture()
+ order_item = LunchbotDataFixtures.order_item_fixture()
assert LunchbotData.get_order_item!(order_item.id) == order_item
end
end
describe "#create_order_item/1" do
test "with valid data creates a order_item" do
- assert {:ok, %OrderItem{} = order_item} = LunchbotData.create_order_item(@valid_attrs)
- assert order_item.item_id == 42
- assert order_item.order_id == 42
+ order = LunchbotDataFixtures.order_fixture()
+ item = LunchbotDataFixtures.item_fixture()
+ params = %{order_id: order.id, item_id: item.id}
+
+ assert {:ok, %OrderItem{} = order_item} = LunchbotData.create_order_item(params)
+ assert order_item.item_id == item.id
+ assert order_item.order_id == order.id
end
test "with invalid data returns error changeset" do
@@ -639,15 +626,19 @@ defmodule Lunchbot.LunchbotDataTest do
describe "#update_order_item/2" do
test "with valid data updates the order_item" do
- order_item = order_item_fixture()
- assert {:ok, order_item} = LunchbotData.update_order_item(order_item, @update_attrs)
+ order_item = LunchbotDataFixtures.order_item_fixture()
+ order = LunchbotDataFixtures.order_fixture()
+ item = LunchbotDataFixtures.item_fixture()
+ params = %{order_id: order.id, item_id: item.id}
+
+ assert {:ok, order_item} = LunchbotData.update_order_item(order_item, params)
assert %OrderItem{} = order_item
- assert order_item.item_id == 43
- assert order_item.order_id == 43
+ assert order_item.item_id == item.id
+ assert order_item.order_id == order.id
end
test "with invalid data returns error changeset" do
- order_item = order_item_fixture()
+ order_item = LunchbotDataFixtures.order_item_fixture()
assert {:error, %Ecto.Changeset{}} =
LunchbotData.update_order_item(order_item, @invalid_attrs)
@@ -658,7 +649,7 @@ defmodule Lunchbot.LunchbotDataTest do
describe "#delete_order_item/1" do
test "deletes the order_item" do
- order_item = order_item_fixture()
+ order_item = LunchbotDataFixtures.order_item_fixture()
assert {:ok, %OrderItem{}} = LunchbotData.delete_order_item(order_item)
assert_raise Ecto.NoResultsError, fn -> LunchbotData.get_order_item!(order_item.id) end
end
@@ -666,20 +657,11 @@ defmodule Lunchbot.LunchbotDataTest do
describe "#change_order_item/1" do
test "returns a order_item changeset" do
- order_item = order_item_fixture()
+ order_item = LunchbotDataFixtures.order_item_fixture()
assert %Ecto.Changeset{} = LunchbotData.change_order_item(order_item)
end
end
- def order_item_fixture(attrs \\ %{}) do
- {:ok, order_item} =
- attrs
- |> Enum.into(@valid_attrs)
- |> LunchbotData.create_order_item()
-
- order_item
- end
-
alias Lunchbot.LunchbotData.Item
@valid_attrs %{
@@ -710,7 +692,7 @@ defmodule Lunchbot.LunchbotDataTest do
describe "#paginate_items/1" do
test "returns paginated list of items" do
for _ <- 1..20 do
- item_fixture()
+ LunchbotDataFixtures.item_fixture()
end
{:ok, %{items: items} = page} = LunchbotData.paginate_items(%{})
@@ -728,14 +710,14 @@ defmodule Lunchbot.LunchbotDataTest do
describe "#list_items/0" do
test "returns all items" do
- item = item_fixture()
+ item = LunchbotDataFixtures.item_fixture()
assert LunchbotData.list_items() == [item]
end
end
describe "#get_item!/1" do
test "returns the item with given id" do
- item = item_fixture()
+ item = LunchbotDataFixtures.item_fixture()
assert LunchbotData.get_item!(item.id) == item
end
end
@@ -758,7 +740,7 @@ defmodule Lunchbot.LunchbotDataTest do
describe "#update_item/2" do
test "with valid data updates the item" do
- item = item_fixture()
+ item = LunchbotDataFixtures.item_fixture()
assert {:ok, item} = LunchbotData.update_item(item, @update_attrs)
assert %Item{} = item
assert item.category_id == 43
@@ -770,7 +752,7 @@ defmodule Lunchbot.LunchbotDataTest do
end
test "with invalid data returns error changeset" do
- item = item_fixture()
+ item = LunchbotDataFixtures.item_fixture()
assert {:error, %Ecto.Changeset{}} = LunchbotData.update_item(item, @invalid_attrs)
assert item == LunchbotData.get_item!(item.id)
end
@@ -778,7 +760,7 @@ defmodule Lunchbot.LunchbotDataTest do
describe "#delete_item/1" do
test "deletes the item" do
- item = item_fixture()
+ item = LunchbotDataFixtures.item_fixture()
assert {:ok, %Item{}} = LunchbotData.delete_item(item)
assert_raise Ecto.NoResultsError, fn -> LunchbotData.get_item!(item.id) end
end
@@ -786,20 +768,11 @@ defmodule Lunchbot.LunchbotDataTest do
describe "#change_item/1" do
test "returns a item changeset" do
- item = item_fixture()
+ item = LunchbotDataFixtures.item_fixture()
assert %Ecto.Changeset{} = LunchbotData.change_item(item)
end
end
- def item_fixture(attrs \\ %{}) do
- {:ok, item} =
- attrs
- |> Enum.into(@valid_attrs)
- |> LunchbotData.create_item()
-
- item
- end
-
alias Lunchbot.LunchbotData.ItemOptionHeadings
@valid_attrs %{item_id: 42, option_heading_id: 42}
@@ -809,7 +782,7 @@ defmodule Lunchbot.LunchbotDataTest do
describe "#paginate_item_option_headings/1" do
test "returns paginated list of item_option_headings" do
for _ <- 1..20 do
- item_option_headings_fixture()
+ LunchbotDataFixtures.item_option_headings_fixture()
end
{:ok, %{item_option_headings: item_option_headings} = page} =
@@ -828,14 +801,14 @@ defmodule Lunchbot.LunchbotDataTest do
describe "#list_item_option_headings/0" do
test "returns all item_option_headings" do
- item_option_headings = item_option_headings_fixture()
+ item_option_headings = LunchbotDataFixtures.item_option_headings_fixture()
assert LunchbotData.list_item_option_headings() == [item_option_headings]
end
end
describe "#get_item_option_headings!/1" do
test "returns the item_option_headings with given id" do
- item_option_headings = item_option_headings_fixture()
+ item_option_headings = LunchbotDataFixtures.item_option_headings_fixture()
assert LunchbotData.get_item_option_headings!(item_option_headings.id) ==
item_option_headings
@@ -859,7 +832,7 @@ defmodule Lunchbot.LunchbotDataTest do
describe "#update_item_option_headings/2" do
test "with valid data updates the item_option_headings" do
- item_option_headings = item_option_headings_fixture()
+ item_option_headings = LunchbotDataFixtures.item_option_headings_fixture()
assert {:ok, item_option_headings} =
LunchbotData.update_item_option_headings(item_option_headings, @update_attrs)
@@ -870,7 +843,7 @@ defmodule Lunchbot.LunchbotDataTest do
end
test "with invalid data returns error changeset" do
- item_option_headings = item_option_headings_fixture()
+ item_option_headings = LunchbotDataFixtures.item_option_headings_fixture()
assert {:error, %Ecto.Changeset{}} =
LunchbotData.update_item_option_headings(item_option_headings, @invalid_attrs)
@@ -882,7 +855,7 @@ defmodule Lunchbot.LunchbotDataTest do
describe "#delete_item_option_headings/1" do
test "deletes the item_option_headings" do
- item_option_headings = item_option_headings_fixture()
+ item_option_headings = LunchbotDataFixtures.item_option_headings_fixture()
assert {:ok, %ItemOptionHeadings{}} =
LunchbotData.delete_item_option_headings(item_option_headings)
@@ -895,20 +868,11 @@ defmodule Lunchbot.LunchbotDataTest do
describe "#change_item_option_headings/1" do
test "returns a item_option_headings changeset" do
- item_option_headings = item_option_headings_fixture()
+ item_option_headings = LunchbotDataFixtures.item_option_headings_fixture()
assert %Ecto.Changeset{} = LunchbotData.change_item_option_headings(item_option_headings)
end
end
- def item_option_headings_fixture(attrs \\ %{}) do
- {:ok, item_option_headings} =
- attrs
- |> Enum.into(@valid_attrs)
- |> LunchbotData.create_item_option_headings()
-
- item_option_headings
- end
-
alias Lunchbot.LunchbotData.OptionHeading
@valid_attrs %{name: "some name", priority: 42}
@@ -918,7 +882,7 @@ defmodule Lunchbot.LunchbotDataTest do
describe "#paginate_option_headings/1" do
test "returns paginated list of option_headings" do
for _ <- 1..20 do
- option_headings_fixture()
+ LunchbotDataFixtures.option_headings_fixture()
end
{:ok, %{option_headings: option_headings} = page} =
@@ -937,14 +901,14 @@ defmodule Lunchbot.LunchbotDataTest do
describe "#list_option_headings/0" do
test "returns all option_headings" do
- option_headings = option_headings_fixture()
+ option_headings = LunchbotDataFixtures.option_headings_fixture()
assert LunchbotData.list_option_headings() == [option_headings]
end
end
describe "#get_option_headings!/1" do
test "returns the option_headings with given id" do
- option_headings = option_headings_fixture()
+ option_headings = LunchbotDataFixtures.option_headings_fixture()
assert LunchbotData.get_option_headings!(option_headings.id) == option_headings
end
end
@@ -965,7 +929,7 @@ defmodule Lunchbot.LunchbotDataTest do
describe "#update_option_headings/2" do
test "with valid data updates the option_headings" do
- option_headings = option_headings_fixture()
+ option_headings = LunchbotDataFixtures.option_headings_fixture()
assert {:ok, option_headings} =
LunchbotData.update_option_headings(option_headings, @update_attrs)
@@ -976,7 +940,7 @@ defmodule Lunchbot.LunchbotDataTest do
end
test "with invalid data returns error changeset" do
- option_headings = option_headings_fixture()
+ option_headings = LunchbotDataFixtures.option_headings_fixture()
assert {:error, %Ecto.Changeset{}} =
LunchbotData.update_option_headings(option_headings, @invalid_attrs)
@@ -987,7 +951,7 @@ defmodule Lunchbot.LunchbotDataTest do
describe "#delete_option_headings/1" do
test "deletes the option_headings" do
- option_headings = option_headings_fixture()
+ option_headings = LunchbotDataFixtures.option_headings_fixture()
assert {:ok, %OptionHeading{}} = LunchbotData.delete_option_headings(option_headings)
assert_raise Ecto.NoResultsError, fn ->
@@ -998,20 +962,11 @@ defmodule Lunchbot.LunchbotDataTest do
describe "#change_option_headings/1" do
test "returns a option_headings changeset" do
- option_headings = option_headings_fixture()
+ option_headings = LunchbotDataFixtures.option_headings_fixture()
assert %Ecto.Changeset{} = LunchbotData.change_option_headings(option_headings)
end
end
- def option_headings_fixture(attrs \\ %{}) do
- {:ok, option_headings} =
- attrs
- |> Enum.into(@valid_attrs)
- |> LunchbotData.create_option_headings()
-
- option_headings
- end
-
alias Lunchbot.LunchbotData.OrderItemOptions
@valid_attrs %{option_id: 42, order_item_id: 42}
@@ -1021,7 +976,7 @@ defmodule Lunchbot.LunchbotDataTest do
describe "#paginate_order_item_options/1" do
test "returns paginated list of order_item_options" do
for _ <- 1..20 do
- order_item_options_fixture()
+ LunchbotDataFixtures.order_item_options_fixture()
end
{:ok, %{order_item_options: order_item_options} = page} =
@@ -1040,25 +995,29 @@ defmodule Lunchbot.LunchbotDataTest do
describe "#list_order_item_options/0" do
test "returns all order_item_options" do
- order_item_options = order_item_options_fixture()
+ order_item_options = LunchbotDataFixtures.order_item_options_fixture()
assert LunchbotData.list_order_item_options() == [order_item_options]
end
end
describe "#get_order_item_options!/1" do
test "returns the order_item_options with given id" do
- order_item_options = order_item_options_fixture()
+ order_item_options = LunchbotDataFixtures.order_item_options_fixture()
assert LunchbotData.get_order_item_options!(order_item_options.id) == order_item_options
end
end
describe "#create_order_item_options/1" do
test "with valid data creates a order_item_options" do
+ option = LunchbotDataFixtures.options_fixture()
+ order_item = LunchbotDataFixtures.order_item_fixture()
+ params = %{option_id: option.id, order_item_id: order_item.id}
+
assert {:ok, %OrderItemOptions{} = order_item_options} =
- LunchbotData.create_order_item_options(@valid_attrs)
+ LunchbotData.create_order_item_options(params)
- assert order_item_options.option_id == 42
- assert order_item_options.order_item_id == 42
+ assert order_item_options.option_id == option.id
+ assert order_item_options.order_item_id == order_item.id
end
test "with invalid data returns error changeset" do
@@ -1068,18 +1027,21 @@ defmodule Lunchbot.LunchbotDataTest do
describe "#update_order_item_options/2" do
test "with valid data updates the order_item_options" do
- order_item_options = order_item_options_fixture()
+ order_item_options = LunchbotDataFixtures.order_item_options_fixture()
+ option = LunchbotDataFixtures.options_fixture()
+ order_item = LunchbotDataFixtures.order_item_fixture()
+ params = %{option_id: option.id, order_item_id: order_item.id}
assert {:ok, order_item_options} =
- LunchbotData.update_order_item_options(order_item_options, @update_attrs)
+ LunchbotData.update_order_item_options(order_item_options, params)
assert %OrderItemOptions{} = order_item_options
- assert order_item_options.option_id == 43
- assert order_item_options.order_item_id == 43
+ assert order_item_options.option_id == option.id
+ assert order_item_options.order_item_id == order_item.id
end
test "with invalid data returns error changeset" do
- order_item_options = order_item_options_fixture()
+ order_item_options = LunchbotDataFixtures.order_item_options_fixture()
assert {:error, %Ecto.Changeset{}} =
LunchbotData.update_order_item_options(order_item_options, @invalid_attrs)
@@ -1090,7 +1052,17 @@ defmodule Lunchbot.LunchbotDataTest do
describe "#delete_order_item_options/1" do
test "deletes the order_item_options" do
- order_item_options = order_item_options_fixture()
+ # create option
+ # create order item
+
+ option = LunchbotDataFixtures.options_fixture()
+ order_item = LunchbotDataFixtures.order_item_fixture()
+
+ order_item_options =
+ LunchbotDataFixtures.order_item_options_fixture(%{
+ option_id: option.id,
+ order_item_id: order_item.id
+ })
assert {:ok, %OrderItemOptions{}} =
LunchbotData.delete_order_item_options(order_item_options)
@@ -1103,18 +1075,17 @@ defmodule Lunchbot.LunchbotDataTest do
describe "#change_order_item_options/1" do
test "returns a order_item_options changeset" do
- order_item_options = order_item_options_fixture()
- assert %Ecto.Changeset{} = LunchbotData.change_order_item_options(order_item_options)
- end
- end
+ option = LunchbotDataFixtures.options_fixture()
+ order_item = LunchbotDataFixtures.order_item_fixture()
- def order_item_options_fixture(attrs \\ %{}) do
- {:ok, order_item_options} =
- attrs
- |> Enum.into(@valid_attrs)
- |> LunchbotData.create_order_item_options()
+ order_item_options =
+ LunchbotDataFixtures.order_item_options_fixture(%{
+ option_id: option.id,
+ order_item_id: order_item.id
+ })
- order_item_options
+ assert %Ecto.Changeset{} = LunchbotData.change_order_item_options(order_item_options)
+ end
end
alias Lunchbot.LunchbotData.Options
@@ -1150,7 +1121,7 @@ defmodule Lunchbot.LunchbotDataTest do
describe "#paginate_options/1" do
test "returns paginated list of options" do
for _ <- 1..20 do
- options_fixture()
+ LunchbotDataFixtures.options_fixture()
end
{:ok, %{options: options} = page} = LunchbotData.paginate_options(%{})
@@ -1168,14 +1139,14 @@ defmodule Lunchbot.LunchbotDataTest do
describe "#list_options/0" do
test "returns all options" do
- options = options_fixture()
+ options = LunchbotDataFixtures.options_fixture()
assert LunchbotData.list_options() == [options]
end
end
describe "#get_options!/1" do
test "returns the options with given id" do
- options = options_fixture()
+ options = LunchbotDataFixtures.options_fixture()
assert LunchbotData.get_options!(options.id) == options
end
end
@@ -1199,7 +1170,7 @@ defmodule Lunchbot.LunchbotDataTest do
describe "#update_options/2" do
test "with valid data updates the options" do
- options = options_fixture()
+ options = LunchbotDataFixtures.options_fixture()
assert {:ok, options} = LunchbotData.update_options(options, @update_attrs)
assert %Options{} = options
assert options.extra_price == 43
@@ -1212,7 +1183,7 @@ defmodule Lunchbot.LunchbotDataTest do
end
test "with invalid data returns error changeset" do
- options = options_fixture()
+ options = LunchbotDataFixtures.options_fixture()
assert {:error, %Ecto.Changeset{}} = LunchbotData.update_options(options, @invalid_attrs)
assert options == LunchbotData.get_options!(options.id)
end
@@ -1220,7 +1191,7 @@ defmodule Lunchbot.LunchbotDataTest do
describe "#delete_options/1" do
test "deletes the options" do
- options = options_fixture()
+ options = LunchbotDataFixtures.options_fixture()
assert {:ok, %Options{}} = LunchbotData.delete_options(options)
assert_raise Ecto.NoResultsError, fn -> LunchbotData.get_options!(options.id) end
end
@@ -1228,20 +1199,11 @@ defmodule Lunchbot.LunchbotDataTest do
describe "#change_options/1" do
test "returns a options changeset" do
- options = options_fixture()
+ options = LunchbotDataFixtures.options_fixture()
assert %Ecto.Changeset{} = LunchbotData.change_options(options)
end
end
- def options_fixture(attrs \\ %{}) do
- {:ok, options} =
- attrs
- |> Enum.into(@valid_attrs)
- |> LunchbotData.create_options()
-
- options
- end
-
alias Lunchbot.LunchbotData.MenuCategories
@valid_attrs %{category_id: 42, menu_id: 42}
@@ -1251,7 +1213,7 @@ defmodule Lunchbot.LunchbotDataTest do
describe "#paginate_menu_categories/1" do
test "returns paginated list of menu_categories" do
for _ <- 1..20 do
- menu_categories_fixture()
+ LunchbotDataFixtures.menu_categories_fixture()
end
{:ok, %{menu_categories: menu_categories} = page} =
@@ -1270,14 +1232,14 @@ defmodule Lunchbot.LunchbotDataTest do
describe "#list_menu_categories/0" do
test "returns all menu_categories" do
- menu_categories = menu_categories_fixture()
+ menu_categories = LunchbotDataFixtures.menu_categories_fixture()
assert LunchbotData.list_menu_categories() == [menu_categories]
end
end
describe "#get_menu_categories!/1" do
test "returns the menu_categories with given id" do
- menu_categories = menu_categories_fixture()
+ menu_categories = LunchbotDataFixtures.menu_categories_fixture()
assert LunchbotData.get_menu_categories!(menu_categories.id) == menu_categories
end
end
@@ -1298,7 +1260,7 @@ defmodule Lunchbot.LunchbotDataTest do
describe "#update_menu_categories/2" do
test "with valid data updates the menu_categories" do
- menu_categories = menu_categories_fixture()
+ menu_categories = LunchbotDataFixtures.menu_categories_fixture()
assert {:ok, menu_categories} =
LunchbotData.update_menu_categories(menu_categories, @update_attrs)
@@ -1309,7 +1271,7 @@ defmodule Lunchbot.LunchbotDataTest do
end
test "with invalid data returns error changeset" do
- menu_categories = menu_categories_fixture()
+ menu_categories = LunchbotDataFixtures.menu_categories_fixture()
assert {:error, %Ecto.Changeset{}} =
LunchbotData.update_menu_categories(menu_categories, @invalid_attrs)
@@ -1320,7 +1282,7 @@ defmodule Lunchbot.LunchbotDataTest do
describe "#delete_menu_categories/1" do
test "deletes the menu_categories" do
- menu_categories = menu_categories_fixture()
+ menu_categories = LunchbotDataFixtures.menu_categories_fixture()
assert {:ok, %MenuCategories{}} = LunchbotData.delete_menu_categories(menu_categories)
assert_raise Ecto.NoResultsError, fn ->
@@ -1331,17 +1293,8 @@ defmodule Lunchbot.LunchbotDataTest do
describe "#change_menu_categories/1" do
test "returns a menu_categories changeset" do
- menu_categories = menu_categories_fixture()
+ menu_categories = LunchbotDataFixtures.menu_categories_fixture()
assert %Ecto.Changeset{} = LunchbotData.change_menu_categories(menu_categories)
end
end
-
- def menu_categories_fixture(attrs \\ %{}) do
- {:ok, menu_categories} =
- attrs
- |> Enum.into(@valid_attrs)
- |> LunchbotData.create_menu_categories()
-
- menu_categories
- end
end
diff --git a/test/lunchbot_web/controllers/admin/menu_controller_test.exs b/test/lunchbot_web/controllers/admin/menu_controller_test.exs
index 0cb7090..87ed2af 100644
--- a/test/lunchbot_web/controllers/admin/menu_controller_test.exs
+++ b/test/lunchbot_web/controllers/admin/menu_controller_test.exs
@@ -1,14 +1,12 @@
defmodule LunchbotWeb.Admin.MenuControllerTest do
use LunchbotWeb.ConnCase
- alias Lunchbot.LunchbotData
+ alias Lunchbot.LunchbotDataFixtures
- @create_attrs %{name: "some name", office_id: 42}
- @update_attrs %{name: "some updated name", office_id: 43}
@invalid_attrs %{name: nil, office_id: nil}
def fixture(:menu) do
- {:ok, menu} = LunchbotData.create_menu(@create_attrs)
+ {:ok, menu} = LunchbotDataFixtures.menu_fixture()
menu
end
@@ -32,7 +30,14 @@ defmodule LunchbotWeb.Admin.MenuControllerTest do
describe "create menu" do
test "redirects to show when data is valid", %{conn: conn} do
- conn = post conn, Routes.admin_menu_path(conn, :create), menu: @create_attrs
+ office = LunchbotDataFixtures.office_fixture()
+
+ params = %{
+ name: "Menu name",
+ office_id: office.id
+ }
+
+ conn = post conn, Routes.admin_menu_path(conn, :create), menu: params
assert %{id: id} = redirected_params(conn)
assert redirected_to(conn) == Routes.admin_menu_path(conn, :show, id)
@@ -60,7 +65,14 @@ defmodule LunchbotWeb.Admin.MenuControllerTest do
setup [:create_menu]
test "redirects when data is valid", %{conn: conn, menu: menu} do
- conn = put conn, Routes.admin_menu_path(conn, :update, menu), menu: @update_attrs
+ office = LunchbotDataFixtures.office_fixture()
+
+ params = %{
+ name: "some updated name",
+ office_id: office.id
+ }
+
+ conn = put conn, Routes.admin_menu_path(conn, :update, menu), menu: params
assert redirected_to(conn) == Routes.admin_menu_path(conn, :show, menu)
conn = get(conn, Routes.admin_menu_path(conn, :show, menu))
@@ -87,7 +99,7 @@ defmodule LunchbotWeb.Admin.MenuControllerTest do
end
defp create_menu(_) do
- menu = fixture(:menu)
+ menu = LunchbotDataFixtures.menu_fixture()
{:ok, menu: menu}
end
end
diff --git a/test/lunchbot_web/controllers/admin/order_controller_test.exs b/test/lunchbot_web/controllers/admin/order_controller_test.exs
index 67c505b..23fcad4 100644
--- a/test/lunchbot_web/controllers/admin/order_controller_test.exs
+++ b/test/lunchbot_web/controllers/admin/order_controller_test.exs
@@ -1,14 +1,14 @@
defmodule LunchbotWeb.Admin.OrderControllerTest do
use LunchbotWeb.ConnCase
- alias Lunchbot.LunchbotData
+ alias Lunchbot.LunchbotDataFixtures
+ alias Inspect.Lunchbot
+ alias LunchbotDataFixtures
- @create_attrs %{lunch_order_id: 42, menu_id: 42, user_id: 42}
- @update_attrs %{lunch_order_id: 43, menu_id: 43, user_id: 43}
- @invalid_attrs %{lunch_order_id: nil, menu_id: nil, user_id: nil}
+ @invalid_attrs %{office_lunch_order_id: nil, menu_id: nil, user_id: nil}
def fixture(:order) do
- {:ok, order} = LunchbotData.create_order(@create_attrs)
+ {:ok, order} = LunchbotDataFixtures.order_fixture()
order
end
@@ -32,7 +32,17 @@ defmodule LunchbotWeb.Admin.OrderControllerTest do
describe "create order" do
test "redirects to show when data is valid", %{conn: conn} do
- conn = post conn, Routes.admin_order_path(conn, :create), order: @create_attrs
+ user = LunchbotDataFixtures.user_fixture()
+ menu = LunchbotDataFixtures.menu_fixture()
+ office_lunch_order = LunchbotDataFixtures.office_lunch_order_fixture(%{menu_id: menu.id})
+
+ params = %{
+ office_lunch_order_id: office_lunch_order.id,
+ menu_id: menu.id,
+ user_id: user.id
+ }
+
+ conn = post conn, Routes.admin_order_path(conn, :create), order: params
assert %{id: id} = redirected_params(conn)
assert redirected_to(conn) == Routes.admin_order_path(conn, :show, id)
@@ -60,7 +70,17 @@ defmodule LunchbotWeb.Admin.OrderControllerTest do
setup [:create_order]
test "redirects when data is valid", %{conn: conn, order: order} do
- conn = put conn, Routes.admin_order_path(conn, :update, order), order: @update_attrs
+ user = LunchbotDataFixtures.user_fixture()
+ menu = LunchbotDataFixtures.menu_fixture()
+ office_lunch_order = LunchbotDataFixtures.office_lunch_order_fixture(%{menu_id: menu.id})
+
+ params = %{
+ office_lunch_order_id: office_lunch_order.id,
+ menu_id: menu.id,
+ user_id: user.id
+ }
+
+ conn = put conn, Routes.admin_order_path(conn, :update, order), order: params
assert redirected_to(conn) == Routes.admin_order_path(conn, :show, order)
conn = get(conn, Routes.admin_order_path(conn, :show, order))
@@ -87,7 +107,7 @@ defmodule LunchbotWeb.Admin.OrderControllerTest do
end
defp create_order(_) do
- order = fixture(:order)
+ order = LunchbotDataFixtures.order_fixture()
{:ok, order: order}
end
end
diff --git a/test/lunchbot_web/controllers/admin/order_item_controller_test.exs b/test/lunchbot_web/controllers/admin/order_item_controller_test.exs
index 886c30b..7c2963c 100644
--- a/test/lunchbot_web/controllers/admin/order_item_controller_test.exs
+++ b/test/lunchbot_web/controllers/admin/order_item_controller_test.exs
@@ -1,17 +1,10 @@
defmodule LunchbotWeb.Admin.OrderItemControllerTest do
use LunchbotWeb.ConnCase
- alias Lunchbot.LunchbotData
+ alias Lunchbot.LunchbotDataFixtures
- @create_attrs %{item_id: 42, order_id: 42}
- @update_attrs %{item_id: 43, order_id: 43}
@invalid_attrs %{item_id: nil, order_id: nil}
- def fixture(:order_item) do
- {:ok, order_item} = LunchbotData.create_order_item(@create_attrs)
- order_item
- end
-
setup do
initialize_admin_user()
end
@@ -32,7 +25,11 @@ defmodule LunchbotWeb.Admin.OrderItemControllerTest do
describe "create order_item" do
test "redirects to show when data is valid", %{conn: conn} do
- conn = post conn, Routes.admin_order_item_path(conn, :create), order_item: @create_attrs
+ item = LunchbotDataFixtures.item_fixture()
+ order = LunchbotDataFixtures.order_fixture()
+ params = %{item_id: item.id, order_id: order.id}
+
+ conn = post conn, Routes.admin_order_item_path(conn, :create), order_item: params
assert %{id: id} = redirected_params(conn)
assert redirected_to(conn) == Routes.admin_order_item_path(conn, :show, id)
@@ -56,29 +53,6 @@ defmodule LunchbotWeb.Admin.OrderItemControllerTest do
end
end
- describe "update order_item" do
- setup [:create_order_item]
-
- test "redirects when data is valid", %{conn: conn, order_item: order_item} do
- conn =
- put conn, Routes.admin_order_item_path(conn, :update, order_item),
- order_item: @update_attrs
-
- assert redirected_to(conn) == Routes.admin_order_item_path(conn, :show, order_item)
-
- conn = get(conn, Routes.admin_order_item_path(conn, :show, order_item))
- assert html_response(conn, 200)
- end
-
- test "renders errors when data is invalid", %{conn: conn, order_item: order_item} do
- conn =
- put conn, Routes.admin_order_item_path(conn, :update, order_item),
- order_item: @invalid_attrs
-
- assert html_response(conn, 200) =~ "Edit Order item"
- end
- end
-
describe "delete order_item" do
setup [:create_order_item]
@@ -93,7 +67,6 @@ defmodule LunchbotWeb.Admin.OrderItemControllerTest do
end
defp create_order_item(_) do
- order_item = fixture(:order_item)
- {:ok, order_item: order_item}
+ {:ok, order_item: LunchbotDataFixtures.order_item_fixture()}
end
end
diff --git a/test/lunchbot_web/controllers/admin/order_item_options_controller_test.exs b/test/lunchbot_web/controllers/admin/order_item_options_controller_test.exs
index bfeb200..8efe34a 100644
--- a/test/lunchbot_web/controllers/admin/order_item_options_controller_test.exs
+++ b/test/lunchbot_web/controllers/admin/order_item_options_controller_test.exs
@@ -1,17 +1,10 @@
defmodule LunchbotWeb.Admin.OrderItemOptionsControllerTest do
use LunchbotWeb.ConnCase
- alias Lunchbot.LunchbotData
+ alias Lunchbot.LunchbotDataFixtures
- @create_attrs %{option_id: 42, order_item_id: 42}
- @update_attrs %{option_id: 43, order_item_id: 43}
@invalid_attrs %{option_id: nil, order_item_id: nil}
- def fixture(:order_item_options) do
- {:ok, order_item_options} = LunchbotData.create_order_item_options(@create_attrs)
- order_item_options
- end
-
setup do
initialize_admin_user()
end
@@ -32,9 +25,17 @@ defmodule LunchbotWeb.Admin.OrderItemOptionsControllerTest do
describe "create order_item_options" do
test "redirects to show when data is valid", %{conn: conn} do
+ # @create_attrs %{option_id: 42, order_item_id: 42}
+ option = LunchbotDataFixtures.options_fixture()
+ order_item = LunchbotDataFixtures.order_item_fixture()
+
+ params = %{
+ option_id: option.id,
+ order_item_id: order_item.id
+ }
+
conn =
- post conn, Routes.admin_order_item_options_path(conn, :create),
- order_item_options: @create_attrs
+ post conn, Routes.admin_order_item_options_path(conn, :create), order_item_options: params
assert %{id: id} = redirected_params(conn)
assert redirected_to(conn) == Routes.admin_order_item_options_path(conn, :show, id)
@@ -68,9 +69,17 @@ defmodule LunchbotWeb.Admin.OrderItemOptionsControllerTest do
setup [:create_order_item_options]
test "redirects when data is valid", %{conn: conn, order_item_options: order_item_options} do
+ option = LunchbotDataFixtures.options_fixture()
+ order_item = LunchbotDataFixtures.order_item_fixture()
+
+ params = %{
+ option_id: option.id,
+ order_item_id: order_item.id
+ }
+
conn =
put conn, Routes.admin_order_item_options_path(conn, :update, order_item_options),
- order_item_options: @update_attrs
+ order_item_options: params
assert redirected_to(conn) ==
Routes.admin_order_item_options_path(conn, :show, order_item_options)
@@ -108,7 +117,7 @@ defmodule LunchbotWeb.Admin.OrderItemOptionsControllerTest do
end
defp create_order_item_options(_) do
- order_item_options = fixture(:order_item_options)
+ order_item_options = LunchbotDataFixtures.order_item_options_fixture()
{:ok, order_item_options: order_item_options}
end
end
diff --git a/test/support/fixtures/lunchbot_data_fixtures.ex b/test/support/fixtures/lunchbot_data_fixtures.ex
index 02054b1..e5bdab1 100644
--- a/test/support/fixtures/lunchbot_data_fixtures.ex
+++ b/test/support/fixtures/lunchbot_data_fixtures.ex
@@ -11,8 +11,8 @@ defmodule Lunchbot.LunchbotDataFixtures do
{:ok, user} =
attrs
|> Enum.into(%{
- name: "some name",
- email: "some_email@mojotech.com",
+ name: "#{Faker.Person.first_name()} #{Faker.Person.last_name()}",
+ email: Faker.Internet.email(),
password: "some_password",
role: "admin",
confirmed_at: ~N[2001-01-01 23:00:07]
@@ -41,11 +41,13 @@ defmodule Lunchbot.LunchbotDataFixtures do
Generate a menu.
"""
def menu_fixture(attrs \\ %{}) do
+ office = office_fixture()
+
{:ok, menu} =
attrs
|> Enum.into(%{
name: "some name",
- office_id: 42
+ office_id: office.id
})
|> Lunchbot.LunchbotData.create_menu()
@@ -56,12 +58,15 @@ defmodule Lunchbot.LunchbotDataFixtures do
Generate a office_lunch_order.
"""
def office_lunch_order_fixture(attrs \\ %{}) do
+ office = office_fixture()
+ menu = menu_fixture()
+
{:ok, office_lunch_order} =
attrs
|> Enum.into(%{
day: ~D[2022-07-07],
- office_id: 42,
- menu_id: 42
+ office_id: office.id,
+ menu_id: menu.id
})
|> Lunchbot.LunchbotData.create_office_lunch_order()
@@ -72,13 +77,24 @@ defmodule Lunchbot.LunchbotDataFixtures do
Generate a order.
"""
def order_fixture(attrs \\ %{}) do
+ # create user
+ # create office lunch order
+ # create menu
+ # pass params to order_fixture
+ user = user_fixture()
+ office = office_fixture()
+ menu = menu_fixture(%{office_id: office.id})
+
+ office_lunch_order = office_lunch_order_fixture(%{office_id: office.id, menu_id: menu.id})
+
+ fixtures = %{
+ office_lunch_order_id: office_lunch_order.id,
+ menu_id: menu.id,
+ user_id: user.id
+ }
+
{:ok, order} =
- attrs
- |> Enum.into(%{
- lunch_order_id: 42,
- menu_id: 42,
- user_id: 42
- })
+ Enum.into(fixtures, attrs)
|> Lunchbot.LunchbotData.create_order()
order
@@ -102,11 +118,16 @@ defmodule Lunchbot.LunchbotDataFixtures do
Generate a order_item.
"""
def order_item_fixture(attrs \\ %{}) do
+ # create item
+ # create order
+ item = item_fixture()
+ order = order_fixture()
+
{:ok, order_item} =
attrs
|> Enum.into(%{
- item_id: 42,
- order_id: 42
+ item_id: item.id,
+ order_id: order.id
})
|> Lunchbot.LunchbotData.create_order_item()
@@ -117,10 +138,13 @@ defmodule Lunchbot.LunchbotDataFixtures do
Generate a item.
"""
def item_fixture(attrs \\ %{}) do
+ # create category
+ category = category_fixture()
+
{:ok, item} =
attrs
|> Enum.into(%{
- category_id: 42,
+ category_id: category.id,
deleted: true,
description: "some description",
image_url: "some image_url",
@@ -166,11 +190,14 @@ defmodule Lunchbot.LunchbotDataFixtures do
Generate a order_item_options.
"""
def order_item_options_fixture(attrs \\ %{}) do
+ option = options_fixture()
+ order_item = order_item_fixture()
+
{:ok, order_item_options} =
attrs
|> Enum.into(%{
- option_id: 42,
- order_item_id: 42
+ option_id: option.id,
+ order_item_id: order_item.id
})
|> Lunchbot.LunchbotData.create_order_item_options()
@@ -181,6 +208,9 @@ defmodule Lunchbot.LunchbotDataFixtures do
Generate a options.
"""
def options_fixture(attrs \\ %{}) do
+ # create option_heading
+ option_heading = option_headings_fixture()
+
{:ok, options} =
attrs
|> Enum.into(%{
@@ -188,7 +218,7 @@ defmodule Lunchbot.LunchbotDataFixtures do
extras: true,
is_required: true,
name: "some name",
- option_heading_id: 42,
+ option_heading_id: option_heading.id,
preselected: true,
price: 42
})
diff --git a/test/test_helper.exs b/test/test_helper.exs
index 1a82f95..524a9f6 100644
--- a/test/test_helper.exs
+++ b/test/test_helper.exs
@@ -1,3 +1,4 @@
ExUnit.start()
+Faker.start()
Ecto.Adapters.SQL.Sandbox.mode(Lunchbot.Repo, :manual)
Mox.defmock(Lunchbot.HTTPClientMock, for: HTTPoison.Base)
|