Files
Claper/test/claper_web/controllers/stat_controller_test.exs
Alex Lion dd5dd82daa Squashed commit of the following:
commit 7db48f592f
Author: Alex Lion <dev@alexandrelion.com>
Date:   Fri Jun 5 10:16:10 2026 +0200

    Update changelog

commit 3039b70edc
Author: Peter Rundqvist <47314226+pete1854@users.noreply.github.com>
Date:   Fri Jun 5 10:11:07 2026 +0200

    Add swedish translation (#228)

    * Initial translation

    * Initial error msg translation

    * Fixes suggested by Copilot.

    * Fixed spacing before ! and ?

    * Added missing provider translation.

    * Upddated translation for "Unpin"

    * Added missing Content-Type header.

commit d18e5d7c32
Author: fgallarday <fgallarday@users.noreply.github.com>
Date:   Fri Jun 5 03:07:25 2026 -0500

    Add PageUp and PageDown slide navigation support (#227)

commit 24e18c2764
Author: Alex Lion <dev@alexandrelion.com>
Date:   Fri Jun 5 10:06:54 2026 +0200

    Bump version to 2.5.2

commit d5df9a73f8
Author: Alex Lion <dev@alexandrelion.com>
Date:   Fri May 8 22:42:04 2026 +0200

    Fix form submissions losing values when field names contain spaces or non-word characters

commit 57596952d4
Author: Alex Lion <dev@alexandrelion.com>
Date:   Fri May 8 14:50:33 2026 +0200

    Update package-lock.json: add asset name, upgrade dependencies, and remove unused packages

commit e246530c23
Author: Alex Lion <dev@alexandrelion.com>
Date:   Fri May 8 14:34:53 2026 +0200

    Bump version to 2.5.1

commit 534d915782
Author: Alex Lion <dev@alexandrelion.com>
Date:   Fri May 8 10:55:38 2026 +0200

    Handle Ecto.NoResultsError in event retrieval and redirect with error message

commit b762e21325
Author: Alex Lion <dev@alexandrelion.com>
Date:   Fri May 8 10:47:01 2026 +0200

    Fix crash on event manager pages when an event has multiple activity leaders

commit 153cadb42b
Author: alxlion <dev@alexandrelion.com>
Date:   Wed Apr 29 13:42:05 2026 +0000

    Fix presentation views without slide count

commit 3cfb3cab7f
Author: alxlion <dev@alexandrelion.com>
Date:   Wed Apr 29 13:16:48 2026 +0000

    Fix event code normalization validation
2026-06-05 10:24:46 +02:00

95 lines
3.0 KiB
Elixir

defmodule ClaperWeb.StatControllerTest do
use ClaperWeb.ConnCase, async: true
import Claper.{AccountsFixtures, FormsFixtures, PresentationsFixtures}
describe "export_transcriptions/2" do
test "exports timestamp, language, and text as CSV", %{conn: conn} do
user = confirmed_user_fixture()
presentation_file = presentation_file_fixture(%{user: user}, [:event])
{:ok, transcription} =
Claper.Transcriptions.create_transcription(%{
presentation_file_id: presentation_file.id,
language: "en",
text: "Welcome to the event"
})
conn =
conn
|> log_in_user(user)
|> post(~p"/export/#{presentation_file.event.uuid}/transcriptions")
assert response(conn, 200) =~
"Timestamp (UTC),Language,Text\r\n#{Calendar.strftime(transcription.inserted_at, "%Y-%m-%d %H:%M:%S")},en,Welcome to the event"
end
test "rejects users without access", %{conn: conn} do
owner = confirmed_user_fixture()
unauthorized_user = confirmed_user_fixture()
presentation_file = presentation_file_fixture(%{user: owner}, [:event])
conn =
conn
|> log_in_user(unauthorized_user)
|> post(~p"/export/#{presentation_file.event.uuid}/transcriptions")
assert response(conn, 403) == "Forbidden"
end
end
describe "POST /export/forms/:form_id" do
setup %{conn: conn} do
owner = confirmed_user_fixture()
presentation_file = presentation_file_fixture(%{user: owner}, [:event])
form =
form_fixture(%{
presentation_file_id: presentation_file.id,
title: "My Form",
fields: [
%{name: "First Name", type: "text", required: false},
%{name: "Email Address", type: "email", required: false}
]
})
%{conn: log_in_user(conn, owner), form: form, event: presentation_file.event}
end
test "exports CSV with field names containing spaces as headers and values", %{
conn: conn,
form: form,
event: event
} do
{:ok, _submit} =
Claper.Forms.create_or_update_form_submit(event.uuid, %{
"attendee_identifier" => "attendee-1",
"form_id" => form.id,
"response" => %{"First Name" => "Ada", "Email Address" => "ada@example.com"}
})
conn = post(conn, ~p"/export/forms/#{form.id}")
assert response_content_type(conn, :csv)
body = response(conn, 200)
[header_line, data_line | _] = String.split(body, "\r\n", trim: true)
assert header_line =~ "First Name"
assert header_line =~ "Email Address"
assert data_line =~ "Ada"
assert data_line =~ "ada@example.com"
end
test "returns 403 for users who don't own the event", %{form: form} do
stranger = confirmed_user_fixture()
conn = build_conn() |> log_in_user(stranger)
conn = post(conn, ~p"/export/forms/#{form.id}")
assert response(conn, 403) == "Forbidden"
end
end
end