Skip to content

Commit

Permalink
Include status in exported CSV
Browse files Browse the repository at this point in the history
  • Loading branch information
katafrakt committed Sep 21, 2023
1 parent 205778a commit 486d92e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
4 changes: 2 additions & 2 deletions lib/keila_web/controllers/contact_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ defmodule KeilaWeb.ContactController do
|> send_chunked(200)

header =
[["Email", "First name", "Last name", "Data"]]
[["Email", "First name", "Last name", "Data", "Status"]]
|> NimbleCSV.RFC4180.dump_to_iodata()
|> IO.iodata_to_binary()

Expand All @@ -178,7 +178,7 @@ defmodule KeilaWeb.ContactController do
Contacts.stream_project_contacts(project_id, max_rows: @csv_export_chunk_size)
|> Stream.map(fn contact ->
data = if is_nil(contact.data), do: nil, else: Jason.encode!(contact.data)
[[contact.email, contact.first_name, contact.last_name, data]]
[[contact.email, contact.first_name, contact.last_name, data, contact.status]]
|> NimbleCSV.RFC4180.dump_to_iodata()
|> IO.iodata_to_binary()
end)
Expand Down
7 changes: 4 additions & 3 deletions test/keila_web/controllers/contact_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ defmodule KeilaWeb.ContactControllerTest do
assert disposition == "attachment; filename=\"contacts_#{project.id}.csv\""

assert rows == [
"Email,First name,Last name,Data",
"#{contact.email},#{contact.first_name},#{contact.last_name},\"{\"\"age\"\":42}\"",
"Email,First name,Last name,Data,Status",
"#{contact.email},#{contact.first_name},#{contact.last_name},\"{\"\"age\"\":42}\",active",
""
]
end
Expand All @@ -183,13 +183,14 @@ defmodule KeilaWeb.ContactControllerTest do
test "GET /projects/:p_id/export CSV export contacts in multiple chunks", %{conn: conn} do
{conn, project} = with_login_and_project(conn)
insert!(:contact, project_id: project.id)
insert!(:contact, project_id: project.id)
insert!(:contact, project_id: project.id, status: :unreachable)
insert!(:contact, project_id: project.id)
insert!(:contact, project_id: project.id)
conn = get(conn, Routes.contact_path(conn, :export, project.id))

assert conn.state == :chunked
rows = String.split(response(conn, 200), "\r\n")
assert length(rows) == 6
assert Enum.at(rows, 2) =~ ~r/,unreachable/
end
end

0 comments on commit 486d92e

Please sign in to comment.