CSV export: apply cycle_status_filter and boolean_filters when exporting all

This commit is contained in:
Moritz 2026-03-04 20:12:45 +01:00
parent d914f5aa22
commit d71d5881cf
Signed by: moritz
GPG key ID: 1020A035E5DD0824
3 changed files with 110 additions and 4 deletions

View file

@ -564,6 +564,49 @@ defmodule MvWeb.MemberExportControllerTest do
assert phone_idx < membership_idx
assert membership_idx < active_idx
end
test "exports only filtered members when selected_ids empty and boolean_filters set (Export all)",
%{
conn: conn,
boolean_field: boolean_field,
member_with_boolean: member_with_boolean,
member_with_string: member_with_string,
member_with_integer: member_with_integer,
member_without_value: member_without_value
} do
# Simulate "filter + Export (all)": no selection, but boolean filter "Active Member = true"
payload = %{
"selected_ids" => [],
"member_fields" => ["first_name", "last_name"],
"custom_field_ids" => [boolean_field.id],
"query" => nil,
"sort_field" => nil,
"sort_order" => nil,
"boolean_filters" => %{to_string(boolean_field.id) => true}
}
conn = get(conn, "/members")
csrf_token = csrf_token_from_conn(conn)
conn =
post(conn, "/members/export.csv", %{
"payload" => Jason.encode!(payload),
"_csrf_token" => csrf_token
})
assert conn.status == 200
body = response(conn, 200)
lines = export_lines(body)
# Header + data rows: only members matching the boolean filter (Active Member = true)
assert length(lines) >= 2
assert body =~ "Boolean"
assert body =~ member_with_boolean.last_name
# Other test members (no value or different value for that custom field) must not appear
refute body =~ member_with_string.last_name
refute body =~ member_with_integer.last_name
refute body =~ member_without_value.last_name
end
end
describe "POST /members/export.pdf" do