refactor: add test to seperate async false module
This commit is contained in:
parent
e74154581c
commit
b6d53d2826
2 changed files with 73 additions and 37 deletions
73
test/mv_web/live/global_settings_live_config_test.exs
Normal file
73
test/mv_web/live/global_settings_live_config_test.exs
Normal file
|
|
@ -0,0 +1,73 @@
|
||||||
|
defmodule MvWeb.GlobalSettingsLiveConfigTest do
|
||||||
|
@moduledoc """
|
||||||
|
Tests for GlobalSettingsLive that modify global Application configuration.
|
||||||
|
|
||||||
|
These tests run with `async: false` to prevent race conditions when
|
||||||
|
modifying global Application environment variables (Application.put_env).
|
||||||
|
This follows the same pattern as Mv.ConfigTest.
|
||||||
|
"""
|
||||||
|
use MvWeb.ConnCase, async: false
|
||||||
|
import Phoenix.LiveViewTest
|
||||||
|
|
||||||
|
# Helper function to upload CSV file in tests
|
||||||
|
defp upload_csv_file(view, csv_content, filename \\ "test_import.csv") do
|
||||||
|
view
|
||||||
|
|> file_input("#csv-upload-form", :csv_file, [
|
||||||
|
%{
|
||||||
|
last_modified: System.system_time(:second),
|
||||||
|
name: filename,
|
||||||
|
content: csv_content,
|
||||||
|
size: byte_size(csv_content),
|
||||||
|
type: "text/csv"
|
||||||
|
}
|
||||||
|
])
|
||||||
|
|> render_upload(filename)
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "CSV Import - Configuration Tests" do
|
||||||
|
setup %{conn: conn} do
|
||||||
|
# Ensure admin user
|
||||||
|
admin_user = Mv.Fixtures.user_with_role_fixture("admin")
|
||||||
|
conn = MvWeb.ConnCase.conn_with_password_user(conn, admin_user)
|
||||||
|
|
||||||
|
{:ok, conn: conn, admin_user: admin_user}
|
||||||
|
end
|
||||||
|
|
||||||
|
test "configured row limit is enforced", %{conn: conn} do
|
||||||
|
# Business rule: CSV import respects configured row limits
|
||||||
|
# Test that a custom limit (500) is enforced, not just the default (1000)
|
||||||
|
original_config = Application.get_env(:mv, :csv_import, [])
|
||||||
|
|
||||||
|
try do
|
||||||
|
Application.put_env(:mv, :csv_import, max_rows: 500)
|
||||||
|
|
||||||
|
{:ok, view, _html} = live(conn, ~p"/settings")
|
||||||
|
|
||||||
|
# Generate CSV with 501 rows (exceeding custom limit of 500)
|
||||||
|
header = "first_name;last_name;email;street;postal_code;city\n"
|
||||||
|
|
||||||
|
rows =
|
||||||
|
for i <- 1..501 do
|
||||||
|
"Row#{i};Last#{i};email#{i}@example.com;Street#{i};12345;City#{i}\n"
|
||||||
|
end
|
||||||
|
|
||||||
|
large_csv = header <> Enum.join(rows)
|
||||||
|
|
||||||
|
# Simulate file upload using helper function
|
||||||
|
upload_csv_file(view, large_csv, "too_many_rows_custom.csv")
|
||||||
|
|
||||||
|
view
|
||||||
|
|> form("#csv-upload-form", %{})
|
||||||
|
|> render_submit()
|
||||||
|
|
||||||
|
html = render(view)
|
||||||
|
# Business rule: import should be rejected when exceeding configured limit
|
||||||
|
assert html =~ "exceeds" or html =~ "maximum" or html =~ "limit" or
|
||||||
|
html =~ "Failed to prepare"
|
||||||
|
after
|
||||||
|
# Restore original config
|
||||||
|
Application.put_env(:mv, :csv_import, original_config)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -687,42 +687,5 @@ defmodule MvWeb.GlobalSettingsLiveTest do
|
||||||
# Check that file input has accept attribute for CSV
|
# Check that file input has accept attribute for CSV
|
||||||
assert html =~ ~r/accept=["'][^"']*csv["']/i or html =~ "CSV files only"
|
assert html =~ ~r/accept=["'][^"']*csv["']/i or html =~ "CSV files only"
|
||||||
end
|
end
|
||||||
|
|
||||||
test "configured row limit is enforced", %{conn: conn} do
|
|
||||||
# Business rule: CSV import respects configured row limits
|
|
||||||
# Test that a custom limit (500) is enforced, not just the default (1000)
|
|
||||||
original_config = Application.get_env(:mv, :csv_import, [])
|
|
||||||
|
|
||||||
try do
|
|
||||||
Application.put_env(:mv, :csv_import, max_rows: 500)
|
|
||||||
|
|
||||||
{:ok, view, _html} = live(conn, ~p"/settings")
|
|
||||||
|
|
||||||
# Generate CSV with 501 rows (exceeding custom limit of 500)
|
|
||||||
header = "first_name;last_name;email;street;postal_code;city\n"
|
|
||||||
|
|
||||||
rows =
|
|
||||||
for i <- 1..501 do
|
|
||||||
"Row#{i};Last#{i};email#{i}@example.com;Street#{i};12345;City#{i}\n"
|
|
||||||
end
|
|
||||||
|
|
||||||
large_csv = header <> Enum.join(rows)
|
|
||||||
|
|
||||||
# Simulate file upload using helper function
|
|
||||||
upload_csv_file(view, large_csv, "too_many_rows_custom.csv")
|
|
||||||
|
|
||||||
view
|
|
||||||
|> form("#csv-upload-form", %{})
|
|
||||||
|> render_submit()
|
|
||||||
|
|
||||||
html = render(view)
|
|
||||||
# Business rule: import should be rejected when exceeding configured limit
|
|
||||||
assert html =~ "exceeds" or html =~ "maximum" or html =~ "limit" or
|
|
||||||
html =~ "Failed to prepare"
|
|
||||||
after
|
|
||||||
# Restore original config
|
|
||||||
Application.put_env(:mv, :csv_import, original_config)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue