MembersPDF test: async false and try/after to avoid flakiness
Tests that remove the template file run sequentially; restore template in after block so it is restored even when assertion fails.
This commit is contained in:
parent
1ce9915c7d
commit
6987733707
1 changed files with 14 additions and 12 deletions
|
|
@ -8,7 +8,9 @@ defmodule Mv.Membership.MembersPDFTest do
|
||||||
- Generates valid PDF binary (starts with "%PDF")
|
- Generates valid PDF binary (starts with "%PDF")
|
||||||
- Handles errors gracefully
|
- Handles errors gracefully
|
||||||
"""
|
"""
|
||||||
use ExUnit.Case, async: true
|
# async: false so tests that manipulate the template file (e.g. "returns error when template file is missing")
|
||||||
|
# do not run in parallel and cannot leave the template removed on failure
|
||||||
|
use ExUnit.Case, async: false
|
||||||
|
|
||||||
alias Mv.Config
|
alias Mv.Config
|
||||||
alias Mv.Membership.MembersPDF
|
alias Mv.Membership.MembersPDF
|
||||||
|
|
@ -162,25 +164,25 @@ defmodule Mv.Membership.MembersPDFTest do
|
||||||
end
|
end
|
||||||
|
|
||||||
test "returns error when template file is missing" do
|
test "returns error when template file is missing" do
|
||||||
# Temporarily rename template to simulate missing file
|
|
||||||
template_path =
|
template_path =
|
||||||
Path.join(Application.app_dir(:mv, "priv"), "pdf_templates/members_export.typ")
|
Path.join(Application.app_dir(:mv, "priv"), "pdf_templates/members_export.typ")
|
||||||
|
|
||||||
original_content = File.read!(template_path)
|
original_content = File.read!(template_path)
|
||||||
File.rm(template_path)
|
File.rm(template_path)
|
||||||
|
|
||||||
export_data = %{
|
try do
|
||||||
columns: [%{key: "first_name", kind: :member_field, label: "Vorname"}],
|
export_data = %{
|
||||||
rows: [["Max"]],
|
columns: [%{key: "first_name", kind: :member_field, label: "Vorname"}],
|
||||||
meta: %{generated_at: "2024-01-15T14:30:00Z", member_count: 1}
|
rows: [["Max"]],
|
||||||
}
|
meta: %{generated_at: "2024-01-15T14:30:00Z", member_count: 1}
|
||||||
|
}
|
||||||
|
|
||||||
result = MembersPDF.render(export_data)
|
result = MembersPDF.render(export_data)
|
||||||
|
|
||||||
assert {:error, {:template_not_found, _reason}} = result
|
assert {:error, {:template_not_found, _reason}} = result
|
||||||
|
after
|
||||||
# Restore template
|
File.write!(template_path, original_content)
|
||||||
File.write!(template_path, original_content)
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
test "handles empty rows gracefully" do
|
test "handles empty rows gracefully" do
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue