Files
Claper/test/claper/forms_test.exs
Alex Lion 5bd4793b6e Version 2.4.0
## ⚠️ Breaking changes

- S3 variables are now named: S3_ACCESS_KEY_ID, S3_SECRET_ACCESS_KEY, S3_REGION and S3_BUCKET
- Users now have roles. Refer to the `roles` table and assign a role to a user with the `role_id` column in the `users` table.

## Features

- Add Admin Panel to manage users and presentations
- Add user roles: user, admin
- Add `LANGUAGES` setting to configure available languages in the app
- Add hideable presenter attendee count (#183 #155)
- Add Hungarian translation (#161)
- Add Latvian translation (#163)
- Add custom S3 endpoint with `S3_SCHEME`, `S3_HOST`, `S3_PORT` and `S3_PUBLIC_URL`

## Fixes and improvements

- Upgrade JS dependencies
- Upgrade Elixir dependencies, including Phoenix Live View to 1.0.17
- Upgrade to Tailwind 4+
- Refactor view templates to use {} instead of <%= %>
- Fix event name validation to be required
- Docker image is now using Ubuntu instead of Alpine for better dependencies support
- Fix scrollbar not showing in event manager when no presentation file (#164) (@aryel780)
- Fix settings scroll for small screen (#168)
- Fix duplicate key quiz when duplicate (#182)
- Fix email change confirmation (#172)
- Fix italian translation (#179)
- Fix random poll choices (#184)
2025-12-26 14:46:16 +01:00

131 lines
4.5 KiB
Elixir

defmodule Claper.FormsTest do
use Claper.DataCase
alias Claper.Forms
describe "forms" do
alias Claper.Forms.Form
import Claper.{FormsFixtures, PresentationsFixtures}
@invalid_attrs %{title: nil}
test "list_forms/1 returns all forms from a presentation" do
presentation_file = presentation_file_fixture()
form = form_fixture(%{presentation_file_id: presentation_file.id})
forms = Forms.list_forms(presentation_file.id)
assert [%Form{} | _] = forms
assert length(forms) == 1
assert hd(forms).id == form.id
end
test "list_forms_at_position/2 returns all forms from a presentation at a given position" do
presentation_file = presentation_file_fixture()
form = form_fixture(%{presentation_file_id: presentation_file.id, position: 5})
forms = Forms.list_forms_at_position(presentation_file.id, 5)
assert [%Form{} | _] = forms
assert length(forms) == 1
assert hd(forms).id == form.id
assert hd(forms).position == 5
end
test "get_form!/1 returns the form with given id" do
presentation_file = presentation_file_fixture()
form = form_fixture(%{presentation_file_id: presentation_file.id})
fetched_form = Forms.get_form!(form.id)
assert fetched_form.id == form.id
assert fetched_form.position == form.position
assert fetched_form.title == form.title
assert fetched_form.fields == form.fields
end
test "create_form/1 with valid data creates a form" do
presentation_file = presentation_file_fixture()
valid_attrs = %{
title: "some title",
presentation_file_id: presentation_file.id,
position: 0,
fields: [
%{name: "some option 1", type: "text", required: false},
%{name: "some option 2", type: "email"}
]
}
assert {:ok, %Form{} = form} = Forms.create_form(valid_attrs)
assert form.title == "some title"
assert Enum.at(form.fields, 0) |> Map.fetch!(:required) == false
assert Enum.at(form.fields, 1) |> Map.fetch!(:required) == true
end
test "create_form/1 with invalid data returns error changeset" do
assert {:error, %Ecto.Changeset{}} = Forms.create_form(@invalid_attrs)
end
test "update_form/3 with valid data updates the form" do
presentation_file = presentation_file_fixture()
form = form_fixture(%{presentation_file_id: presentation_file.id})
update_attrs = %{title: "some updated title"}
assert {:ok, %Form{} = form} =
Forms.update_form(presentation_file.event_id, form, update_attrs)
assert form.title == "some updated title"
end
test "update_form/3 with invalid data returns error changeset" do
presentation_file = presentation_file_fixture()
form = form_fixture(%{presentation_file_id: presentation_file.id})
assert {:error, %Ecto.Changeset{}} =
Forms.update_form(presentation_file.event_id, form, @invalid_attrs)
fetched_form = Forms.get_form!(form.id)
assert fetched_form.title == form.title
end
test "delete_form/2 deletes the form" do
presentation_file = presentation_file_fixture()
form = form_fixture(%{presentation_file_id: presentation_file.id})
assert {:ok, %Form{}} = Forms.delete_form(presentation_file.event_id, form)
assert_raise Ecto.NoResultsError, fn -> Forms.get_form!(form.id) end
end
test "change_form/1 returns a form changeset" do
presentation_file = presentation_file_fixture()
form = form_fixture(%{presentation_file_id: presentation_file.id})
assert %Ecto.Changeset{} = Forms.change_form(form)
end
end
describe "form_submits" do
import Claper.{FormsFixtures, PresentationsFixtures}
test "get_form_submit/2 returns the form_submit with given id and user id" do
form_submit = form_submit_fixture()
assert Forms.get_form_submit(form_submit.user_id, form_submit.form_id) == form_submit
end
test "create_or_update_form_submit/3 with valid data edit a form_submit" do
presentation_file = presentation_file_fixture(%{}, [:event])
f = form_fixture(%{presentation_file_id: presentation_file.id})
assert {:ok, %Claper.Forms.FormSubmit{}} =
Forms.create_or_update_form_submit(
presentation_file.event_id,
%{
"user_id" => presentation_file.event.user_id,
"form_id" => f.id,
"response" => %{:Test => "some option 1", :"Test 2" => "some option 2"}
}
)
end
end
end