Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating Tests on Main to Compile #4

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/therons_erp/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ defmodule TheronsErp.Application do
@impl true
def start(_type, _args) do
children = [
TheronsErp.Repo,
{Oban,
AshOban.config(
Application.fetch_env!(:therons_erp, :ash_domains),
Application.fetch_env!(:therons_erp, Oban)
)},
TheronsErpWeb.Telemetry,
TheronsErp.Repo,
{DNSCluster, query: Application.get_env(:therons_erp, :dns_cluster_query) || :ignore},
{Phoenix.PubSub, name: TheronsErp.PubSub},
# Start the Finch HTTP client for sending emails
Expand Down
4 changes: 3 additions & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ defmodule TheronsErp.MixProject do
{:seqfuzz, "~> 0.2.0"},
{:igniter, "~> 0.5", only: [:dev, :test]},
{:petal_components, "~> 2.8"},
{:credo, "~> 1.7"}
{:credo, "~> 1.7"},
{:ex_machina, "~> 2.8.0", only: :test},
{:faker, "~> 0.18.0", only: :test}
]
end

Expand Down
4 changes: 3 additions & 1 deletion mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,17 @@
"ex_cldr_currencies": {:hex, :ex_cldr_currencies, "2.16.3", "1ec6444b5d0c0aabba5a3bc321d73f1c9c751c6add92e7fb7775ccc071d96bd8", [:mix], [{:ex_cldr, "~> 2.38", [hex: :ex_cldr, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm", "4d1b5f8449fdf0ece6a2e5c7401ad8fcfde77ee6ea480bddc16e266dfa2b570c"},
"ex_cldr_numbers": {:hex, :ex_cldr_numbers, "2.33.5", "6cd39c549019562f83349d5aba1dcaa40d8ea36ed0e92b0d03dff65231a2eb40", [:mix], [{:decimal, "~> 1.6 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:digital_token, "~> 0.3 or ~> 1.0", [hex: :digital_token, repo: "hexpm", optional: false]}, {:ex_cldr, "~> 2.38", [hex: :ex_cldr, repo: "hexpm", optional: false]}, {:ex_cldr_currencies, "~> 2.16", [hex: :ex_cldr_currencies, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm", "1f0baf18ebdec2016018544fc92c8280722e7a6c90aad08b047b00d55594c9b4"},
"ex_doc": {:hex, :ex_doc, "0.22.1", "9bb6d51508778193a4ea90fa16eac47f8b67934f33f8271d5e1edec2dc0eee4c", [:mix], [{:earmark, "~> 1.4.0", [hex: :earmark, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}], "hexpm", "d957de1b75cb9f78d3ee17820733dc4460114d8b1e11f7ee4fd6546e69b1db60"},
"ex_machina": {:hex, :ex_machina, "2.8.0", "a0e847b5712065055ec3255840e2c78ef9366634d62390839d4880483be38abe", [:mix], [{:ecto, "~> 2.2 or ~> 3.0", [hex: :ecto, repo: "hexpm", optional: true]}, {:ecto_sql, "~> 3.0", [hex: :ecto_sql, repo: "hexpm", optional: true]}], "hexpm", "79fe1a9c64c0c1c1fab6c4fa5d871682cb90de5885320c187d117004627a7729"},
"ex_money": {:hex, :ex_money, "5.19.1", "1a404ce5d6dd99a4330a8da7c8416dcebd83863130498b5c7594e73300e31074", [:mix], [{:decimal, "~> 1.6 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:ex_cldr_numbers, "~> 2.33", [hex: :ex_cldr_numbers, repo: "hexpm", optional: false]}, {:gringotts, "~> 1.1", [hex: :gringotts, repo: "hexpm", optional: true]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:nimble_parsec, "~> 0.5 or ~> 1.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 2.0 or ~> 3.0 or ~> 4.0", [hex: :phoenix_html, repo: "hexpm", optional: true]}, {:poison, "~> 3.0 or ~> 4.0 or ~> 5.0 or ~> 6.0", [hex: :poison, repo: "hexpm", optional: true]}], "hexpm", "3195892e004cae23b9af1f123bc2c4219ff6f45e19a59cbbfa42d6500742bd1d"},
"ex_money_sql": {:hex, :ex_money_sql, "1.11.0", "1b9b2f920d5d9220fa6dd4d8aae258daf562deaed2fb037b38b1f7ba4d0a344c", [:mix], [{:ecto, "~> 3.5", [hex: :ecto, repo: "hexpm", optional: false]}, {:ecto_sql, "~> 3.0", [hex: :ecto_sql, repo: "hexpm", optional: false]}, {:ex_money, "~> 5.7", [hex: :ex_money, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}, {:postgrex, "~> 0.15", [hex: :postgrex, repo: "hexpm", optional: false]}], "hexpm", "629e0541ae9f87122d34650f8c8febbc7349bbc6f881cf7a51b4d0779886107d"},
"expo": {:hex, :expo, "1.1.0", "f7b9ed7fb5745ebe1eeedf3d6f29226c5dd52897ac67c0f8af62a07e661e5c75", [:mix], [], "hexpm", "fbadf93f4700fb44c331362177bdca9eeb8097e8b0ef525c9cc501cb9917c960"},
"faker": {:hex, :faker, "0.18.0", "943e479319a22ea4e8e39e8e076b81c02827d9302f3d32726c5bf82f430e6e14", [:mix], [], "hexpm", "bfbdd83958d78e2788e99ec9317c4816e651ad05e24cfd1196ce5db5b3e81797"},
"file_system": {:hex, :file_system, "1.1.0", "08d232062284546c6c34426997dd7ef6ec9f8bbd090eb91780283c9016840e8f", [:mix], [], "hexpm", "bfcf81244f416871f2a2e15c1b515287faa5db9c6bcf290222206d120b3d43f6"},
"finch": {:hex, :finch, "0.19.0", "c644641491ea854fc5c1bbaef36bfc764e3f08e7185e1f084e35e0672241b76d", [:mix], [{:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:mint, "~> 1.6.2 or ~> 1.7", [hex: :mint, repo: "hexpm", optional: false]}, {:nimble_options, "~> 0.4 or ~> 1.0", [hex: :nimble_options, repo: "hexpm", optional: false]}, {:nimble_pool, "~> 1.1", [hex: :nimble_pool, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "fc5324ce209125d1e2fa0fcd2634601c52a787aff1cd33ee833664a5af4ea2b6"},
"floki": {:hex, :floki, "0.37.0", "b83e0280bbc6372f2a403b2848013650b16640cd2470aea6701f0632223d719e", [:mix], [], "hexpm", "516a0c15a69f78c47dc8e0b9b3724b29608aa6619379f91b1ffa47109b5d0dd3"},
"gettext": {:hex, :gettext, "0.26.2", "5978aa7b21fada6deabf1f6341ddba50bc69c999e812211903b169799208f2a8", [:mix], [{:expo, "~> 0.5.1 or ~> 1.0", [hex: :expo, repo: "hexpm", optional: false]}], "hexpm", "aa978504bcf76511efdc22d580ba08e2279caab1066b76bb9aa81c4a1e0a32a5"},
"glob_ex": {:hex, :glob_ex, "0.1.11", "cb50d3f1ef53f6ca04d6252c7fde09fd7a1cf63387714fe96f340a1349e62c93", [:mix], [], "hexpm", "342729363056e3145e61766b416769984c329e4378f1d558b63e341020525de4"},
"heroicons": {:git, "https://github.com/tailwindlabs/heroicons.git", "88ab3a0d790e6a47404cba02800a6b25d2afae50", [tag: "v2.1.1", sparse: "optimized"]},
"heroicons": {:git, "https://github.com/tailwindlabs/heroicons.git", "88ab3a0d790e6a47404cba02800a6b25d2afae50", [tag: "v2.1.1", sparse: "optimized", depth: 1]},
"hpax": {:hex, :hpax, "1.0.2", "762df951b0c399ff67cc57c3995ec3cf46d696e41f0bba17da0518d94acd4aac", [:mix], [], "hexpm", "2f09b4c1074e0abd846747329eaa26d535be0eb3d189fa69d812bfb8bfefd32f"},
"igniter": {:hex, :igniter, "0.5.20", "f95227c1cc1e9ee21151d670a3f1bce2151fb2cd7a81fec85a3b832f6ba0d866", [:mix], [{:glob_ex, "~> 0.1.7", [hex: :glob_ex, repo: "hexpm", optional: false]}, {:inflex, "~> 2.0", [hex: :inflex, repo: "hexpm", optional: false]}, {:jason, "~> 1.4", [hex: :jason, repo: "hexpm", optional: false]}, {:owl, "~> 0.11", [hex: :owl, repo: "hexpm", optional: false]}, {:phx_new, "~> 1.7", [hex: :phx_new, repo: "hexpm", optional: true]}, {:req, "~> 0.5", [hex: :req, repo: "hexpm", optional: false]}, {:rewrite, ">= 1.1.1 and < 2.0.0-0", [hex: :rewrite, repo: "hexpm", optional: false]}, {:sourceror, "~> 1.4", [hex: :sourceror, repo: "hexpm", optional: false]}, {:spitfire, ">= 0.1.3 and < 1.0.0-0", [hex: :spitfire, repo: "hexpm", optional: false]}], "hexpm", "fbc48dfb15ce7cf35e2e688d969ebbaad7ca3291a21a297879169370cc8efef4"},
"inflex": {:hex, :inflex, "2.1.0", "a365cf0821a9dacb65067abd95008ca1b0bb7dcdd85ae59965deef2aa062924c", [:mix], [], "hexpm", "14c17d05db4ee9b6d319b0bff1bdf22aa389a25398d1952c7a0b5f3d93162dd8"},
Expand Down
27 changes: 27 additions & 0 deletions test/support/factory.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
defmodule TheronsErp.Factory do
use ExMachina.Ecto, repo: TheronsErp.Repo

def product_factory() do
%TheronsErp.Inventory.Product{
id: Faker.UUID.v4(),
name: Faker.Commerce.En.product_name(),
identifier: Faker.random_between(1, 10_000_000_000),
sales_price: Money.new(500, :USD),
type: TheronsErp.Inventory.Product.Types.values() |> Enum.random(),
inserted_at: Faker.DateTime.backward(7),
updated_at: Faker.DateTime.backward(7)
}
|> AshPostgres.DataLayer.to_ecto()
end

def product_category_factory() do
%TheronsErp.Inventory.ProductCategory{
id: Faker.UUID.v4(),
name: Faker.Commerce.En.product_name(),
product_category_id: Faker.UUID.v4(),
full_name: Faker.Commerce.En.product_name(),
inserted_at: Faker.DateTime.backward(7),
updated_at: Faker.DateTime.backward(7)
}
end
end
2 changes: 2 additions & 0 deletions test/test_helper.exs
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
{:ok, _} = Application.ensure_all_started(:ex_machina)

ExUnit.start()
Ecto.Adapters.SQL.Sandbox.mode(TheronsErp.Repo, :manual)
8 changes: 8 additions & 0 deletions test/therons_erp/inventory/product_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
defmodule TheronsErp.Inventory.ProductTest do
use ExUnit.Case

test "can make a product" do
TheronsErp.Inventory.Product
|> Ash.Changeset.for_create(:create)
end
end
119 changes: 119 additions & 0 deletions test/therons_erp_web/live/product_category_live_test.exs
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe I deleted these from sales_orders bc they were broken.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can take a look into these, including #4

I'm looking at them now and at the moment what they're doing is returning some HTML and I assume it is the product live and product category live pages, but right now it's my first time laying my eyes on it so we'll see.

What they're doing ultimately might need to be rewritten but a lot of it might be similar. This was all pregenerated boilerplate right? Give me a bit to work on this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete them for now. The UI is highly customize. I'll add a comment to the PR with some code you'll need.

Original file line number Diff line number Diff line change
@@ -1,3 +1,122 @@
defmodule TheronsErpWeb.ProductCategoryLiveTest do
use TheronsErpWeb.ConnCase

import Phoenix.LiveViewTest
import TheronsErp.Factory
import TheronsErp.InventoryFixtures

@create_attrs %{name: "some name"}
@update_attrs %{name: "some updated name"}
@invalid_attrs %{name: nil}

defp create_product_category(_) do
product_category = build(:product_category)
%{product_category: product_category}
end

describe "Index" do
setup [:create_product_category]

test "lists all product_categories", %{conn: conn, product_category: product_category} do

Check failure on line 20 in test/therons_erp_web/live/product_category_live_test.exs

View workflow job for this annotation

GitHub Actions / Build and test

test Index lists all product_categories (TheronsErpWeb.ProductCategoryLiveTest)
{:ok, _index_live, html} = live(conn, ~p"/product_categories")

assert html =~ "Listing Product categories"
assert html =~ product_category.name
end

test "saves new product_category", %{conn: conn} do

Check failure on line 27 in test/therons_erp_web/live/product_category_live_test.exs

View workflow job for this annotation

GitHub Actions / Build and test

test Index saves new product_category (TheronsErpWeb.ProductCategoryLiveTest)
{:ok, index_live, _html} = live(conn, ~p"/product_categories")

assert index_live |> element("a", "New Product category") |> render_click() =~
"New Product category"

assert_patch(index_live, ~p"/product_categories/new")

assert index_live
|> form("#product_category-form", product_category: @invalid_attrs)
|> render_change() =~ "can&#39;t be blank"

assert index_live
|> form("#product_category-form", product_category: @create_attrs)
|> render_submit()

assert_patch(index_live, ~p"/product_categories")

html = render(index_live)
assert html =~ "Product category created successfully"
assert html =~ "some name"
end

test "updates product_category in listing", %{conn: conn, product_category: product_category} do

Check failure on line 50 in test/therons_erp_web/live/product_category_live_test.exs

View workflow job for this annotation

GitHub Actions / Build and test

test Index updates product_category in listing (TheronsErpWeb.ProductCategoryLiveTest)
{:ok, index_live, _html} = live(conn, ~p"/product_categories")

assert index_live
|> element("#product_categories-#{product_category.id} a", "Edit")
|> render_click() =~
"Edit Product category"

assert_patch(index_live, ~p"/product_categories/#{product_category}/edit")

assert index_live
|> form("#product_category-form", product_category: @invalid_attrs)
|> render_change() =~ "can&#39;t be blank"

assert index_live
|> form("#product_category-form", product_category: @update_attrs)
|> render_submit()

assert_patch(index_live, ~p"/product_categories")

html = render(index_live)
assert html =~ "Product category updated successfully"
assert html =~ "some updated name"
end

test "deletes product_category in listing", %{conn: conn, product_category: product_category} do

Check failure on line 75 in test/therons_erp_web/live/product_category_live_test.exs

View workflow job for this annotation

GitHub Actions / Build and test

test Index deletes product_category in listing (TheronsErpWeb.ProductCategoryLiveTest)
{:ok, index_live, _html} = live(conn, ~p"/product_categories")

assert index_live
|> element("#product_categories-#{product_category.id} a", "Delete")
|> render_click()

refute has_element?(index_live, "#product_categories-#{product_category.id}")
end
end

describe "Show" do
setup [:create_product_category]

test "displays product_category", %{conn: conn, product_category: product_category} do

Check failure on line 89 in test/therons_erp_web/live/product_category_live_test.exs

View workflow job for this annotation

GitHub Actions / Build and test

test Show displays product_category (TheronsErpWeb.ProductCategoryLiveTest)
{:ok, _show_live, html} = live(conn, ~p"/product_categories/#{product_category}")

assert html =~ "Show Product category"
assert html =~ product_category.name
end

test "updates product_category within modal", %{

Check failure on line 96 in test/therons_erp_web/live/product_category_live_test.exs

View workflow job for this annotation

GitHub Actions / Build and test

test Show updates product_category within modal (TheronsErpWeb.ProductCategoryLiveTest)
conn: conn,
product_category: product_category
} do
{:ok, show_live, _html} = live(conn, ~p"/product_categories/#{product_category}")

assert show_live |> element("a", "Edit") |> render_click() =~
"Edit Product category"

assert_patch(show_live, ~p"/product_categories/#{product_category}/show/edit")

assert show_live
|> form("#product_category-form", product_category: @invalid_attrs)
|> render_change() =~ "can&#39;t be blank"

assert show_live
|> form("#product_category-form", product_category: @update_attrs)
|> render_submit()

assert_patch(show_live, ~p"/product_categories/#{product_category}")

html = render(show_live)
assert html =~ "Product category updated successfully"
assert html =~ "some updated name"
end
end
end
113 changes: 113 additions & 0 deletions test/therons_erp_web/live/product_live_test.exs
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe I deleted these from sales_orders bc they were broken.

Original file line number Diff line number Diff line change
@@ -1,3 +1,116 @@
defmodule TheronsErpWeb.ProductLiveTest do
use TheronsErpWeb.ConnCase

import Phoenix.LiveViewTest
import TheronsErp.Factory
import TheronsErp.InventoryFixtures

@create_attrs %{name: "some name", tags: ["option1", "option2"]}
@update_attrs %{name: "some updated name", tags: ["option1"]}
@invalid_attrs %{name: nil, tags: []}

defp create_product(_) do
product = insert(:product)
%{product: product}
end

describe "Index" do
setup [:create_product]

test "shows product page", %{conn: conn, product: product} do
{:ok, _index_live, html} = live(conn, ~p"/products")

assert html =~ "Listing Products"
assert html =~ product.name
end

test "saves new product", %{conn: conn} do

Check failure on line 27 in test/therons_erp_web/live/product_live_test.exs

View workflow job for this annotation

GitHub Actions / Build and test

test Index saves new product (TheronsErpWeb.ProductLiveTest)
{:ok, index_live, html} = live(conn, ~p"/products")

dbg(html)

assert index_live |> element("a", "New Product") |> render_click() =~
"New Product"

assert_patch(index_live, ~p"/products/new")

assert index_live
|> form("#product-form", product: @invalid_attrs)
|> render_change() =~ "can&#39;t be blank"

assert index_live
|> form("#product-form", product: @create_attrs)
|> render_submit()

assert_patch(index_live, ~p"/products")

html = render(index_live)
assert html =~ "Product created successfully"
assert html =~ "some name"
end

test "updates product in listing", %{conn: conn, product: product} do

Check failure on line 52 in test/therons_erp_web/live/product_live_test.exs

View workflow job for this annotation

GitHub Actions / Build and test

test Index updates product in listing (TheronsErpWeb.ProductLiveTest)
{:ok, index_live, _html} = live(conn, ~p"/products")

assert index_live |> element("#products-#{product.id} a", "Edit") |> render_click() =~
"Edit Product"

assert_patch(index_live, ~p"/products/#{product}/edit")

assert index_live
|> form("#product-form", product: @invalid_attrs)
|> render_change() =~ "can&#39;t be blank"

assert index_live
|> form("#product-form", product: @update_attrs)
|> render_submit()

assert_patch(index_live, ~p"/products")

html = render(index_live)
assert html =~ "Product updated successfully"
assert html =~ "some updated name"
end

test "deletes product in listing", %{conn: conn, product: product} do

Check failure on line 75 in test/therons_erp_web/live/product_live_test.exs

View workflow job for this annotation

GitHub Actions / Build and test

test Index deletes product in listing (TheronsErpWeb.ProductLiveTest)
{:ok, index_live, _html} = live(conn, ~p"/products")

assert index_live |> element("#products-#{product.id} a", "Delete") |> render_click()
refute has_element?(index_live, "#products-#{product.id}")
end
end

describe "Show" do
setup [:create_product]

test "displays product", %{conn: conn, product: product} do
{:ok, _show_live, html} = live(conn, ~p"/products/#{product}")

assert html =~ "Show Product"
assert html =~ product.name
end

test "updates product within modal", %{conn: conn, product: product} do

Check failure on line 93 in test/therons_erp_web/live/product_live_test.exs

View workflow job for this annotation

GitHub Actions / Build and test

test Show updates product within modal (TheronsErpWeb.ProductLiveTest)
{:ok, show_live, _html} = live(conn, ~p"/products/#{product}")

assert show_live |> element("a", "Edit") |> render_click() =~
"Edit Product"

assert_patch(show_live, ~p"/products/#{product}/show/edit")

assert show_live
|> form("#product-form", product: @invalid_attrs)
|> render_change() =~ "can&#39;t be blank"

assert show_live
|> form("#product-form", product: @update_attrs)
|> render_submit()

assert_patch(show_live, ~p"/products/#{product}")

html = render(show_live)
assert html =~ "Product updated successfully"
assert html =~ "some updated name"
end
end
end
Loading