Test a chunked file download in Phoenix

Hi there!

I have a working controller action returning a CSV file in chunks (being streamed from the DB). I’m having trouble testing it because I only get the first chunk of the CSV (in my case the CSV headers) when I do get(conn, path):

  test "downloads the csv with the expected rows", %{conn: conn} do
    {:ok, _check} = Domain.create_check(attrs)

    today = Date.utc_today()
            |> Date.to_iso8601()

    conn = get(conn, check_path(conn, :details, %{"start_date" => today, "end_date" => today}))

    data = response(conn, 200)

I’ve read the documentation about the Conn.Test, Plug.Conn.Test but I’m still unable to overcome this. How do you test streamed file downloads in Phoenix?

Thanks in advance!

That should not be the case. Are you sure you have the data properly generated in CSV during the test? Maybe the issue here is that the generated CSV is in fact empty.

1 Like

You’re right @hubertlepicki, double-checked my query and it wasn’t returning the rows in the first place :man_facepalming:. Many thanks for the quick reply! I was already going down the rabbit hole :sweat_smile:.


Been there done that :wink:

1 Like