From 486d92e5a28c2ae4bbcb452f3cd50974904290b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20=C5=9Awi=C4=85tkowski?= Date: Fri, 22 Sep 2023 00:25:38 +0200 Subject: [PATCH] Include status in exported CSV --- lib/keila_web/controllers/contact_controller.ex | 4 ++-- test/keila_web/controllers/contact_controller_test.exs | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/keila_web/controllers/contact_controller.ex b/lib/keila_web/controllers/contact_controller.ex index 32afd42c..ffc5609d 100644 --- a/lib/keila_web/controllers/contact_controller.ex +++ b/lib/keila_web/controllers/contact_controller.ex @@ -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() @@ -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) diff --git a/test/keila_web/controllers/contact_controller_test.exs b/test/keila_web/controllers/contact_controller_test.exs index 06c3ee56..3320d335 100644 --- a/test/keila_web/controllers/contact_controller_test.exs +++ b/test/keila_web/controllers/contact_controller_test.exs @@ -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 @@ -183,7 +183,7 @@ 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)) @@ -191,5 +191,6 @@ defmodule KeilaWeb.ContactControllerTest do 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