mirror of
https://codeberg.org/JasterV/spazio-solazzo.git
synced 2026-04-26 18:20:03 +00:00
This pull request makes phone numbers optional for both user registrations and bookings, and updates validation, database schema, and UI to reflect this change. The main focus is to ensure that users are no longer required to provide a phone number, and that the application gracefully handles cases where a phone number is absent. **Database & Resource Model Updates** * Made the `phone_number` attribute in the `users` table and the `customer_phone` attribute in the `bookings` table nullable, including migration and resource snapshot updates. [[1]](diffhunk://#diff-baa6aed3674c4d6cbbebeafb076662df02dc4c25231dbd9dc9c8f0534ed1a1bfR1-R29) [[2]](diffhunk://#diff-a401f66b2ae5bfb798eb1bc2221bfeeac943e258950c90d59570b0bae05d3664R1-R244) [[3]](diffhunk://#diff-0c1180d6f6abc19b5987c8703bdee9ef67905535202f950e8327c32bd5b89d8aR1-R82) * Updated Ash resource definitions in `user.ex` and `booking.ex` to allow `phone_number` and `customer_phone` to be `nil`. [[1]](diffhunk://#diff-9194b9d80dce091f6dcb56f784217272ae160e35454c4b4ccc8850ad5ee06e38L152-R152) [[2]](diffhunk://#diff-4b1ddd6d86899f2144c69d142883b8719c755e32c03dbda5da2188208a5ad503L55-R55) [[3]](diffhunk://#diff-4b1ddd6d86899f2144c69d142883b8719c755e32c03dbda5da2188208a5ad503L170-R170) **Validation & Parsing Logic** * Renamed and refactored user registration field validation to `ParseRegistrationFields`, allowing phone numbers to be omitted and trimming input values. Empty phone numbers are now treated as absent rather than as errors. [[1]](diffhunk://#diff-8ffdd76e260e3cda6f0816c8e585ae76b993a90d2519c38185a5fe22b4b49e47L1-R1) [[2]](diffhunk://#diff-8ffdd76e260e3cda6f0816c8e585ae76b993a90d2519c38185a5fe22b4b49e47R14-R60) * Updated the authentication callback logic to trim input values and omit the phone number parameter if it is blank. **User Interface Improvements** * Updated registration and booking forms to indicate that phone numbers are optional, removed the required attribute, and improved placeholder text. [[1]](diffhunk://#diff-f356eb84970d8c9ee6ff1992c297b0cae07bade37ff967c1e6e0de6f8b67081cL101-R115) [[2]](diffhunk://#diff-43c0e1f7a869ee5c43a911bc10dc80cbb265a8672340ef0fa7c1d3009c047f02L92-R92) * Updated email templates and confirmation screens to display "N/A" or "-" when phone numbers are missing. [[1]](diffhunk://#diff-48468ef2d1bb2c33b5ffb40457b77532815c7faf1830932661f665bff58b2177R6-R11) [[2]](diffhunk://#diff-3f33187b4021450b481ce53fe13166addea582c627f2cfbc99c75c7ce5c34857L10-R10) [[3]](diffhunk://#diff-43c0e1f7a869ee5c43a911bc10dc80cbb265a8672340ef0fa7c1d3009c047f02L92-R92) **Profile Management** * Improved profile update flow to ensure the form reflects the latest user data after saving changes. * Made the "Full Name" field explicitly required in the profile form UI.
82 lines
2.3 KiB
Elixir
82 lines
2.3 KiB
Elixir
defmodule SpazioSolazzo.DataCase do
|
|
@moduledoc """
|
|
This module defines the setup for tests requiring
|
|
access to the application's data layer.
|
|
|
|
You may define functions here to be used as helpers in
|
|
your tests.
|
|
|
|
Finally, if the test case interacts with the database,
|
|
we enable the SQL sandbox, so changes done to the database
|
|
are reverted at the end of every test. If you are using
|
|
PostgreSQL, you can even run database tests asynchronously
|
|
by setting `use SpazioSolazzo.DataCase, async: true`, although
|
|
this option is not recommended for other databases.
|
|
"""
|
|
|
|
use ExUnit.CaseTemplate
|
|
|
|
using do
|
|
quote do
|
|
alias SpazioSolazzo.Repo
|
|
|
|
use Oban.Testing, repo: SpazioSolazzo.Repo
|
|
|
|
import Ecto
|
|
import Ecto.Changeset
|
|
import Ecto.Query
|
|
import SpazioSolazzo.DataCase
|
|
import SpazioSolazzo.AuthHelpers
|
|
end
|
|
end
|
|
|
|
setup tags do
|
|
SpazioSolazzo.DataCase.setup_sandbox(tags)
|
|
SpazioSolazzo.DataCase.init_mailbox()
|
|
:ok
|
|
end
|
|
|
|
@doc """
|
|
Sets up the sandbox based on the test tags.
|
|
"""
|
|
def setup_sandbox(tags) do
|
|
pid = Ecto.Adapters.SQL.Sandbox.start_owner!(SpazioSolazzo.Repo, shared: not tags[:async])
|
|
on_exit(fn -> Ecto.Adapters.SQL.Sandbox.stop_owner(pid) end)
|
|
end
|
|
|
|
@doc """
|
|
Initialize the local Swoosh mailbox. Ensure the in-memory storage process is started
|
|
so tests can safely call into it.
|
|
"""
|
|
def init_mailbox() do
|
|
case Swoosh.Adapters.Local.Storage.Memory.start() do
|
|
{:ok, _pid} -> :ok
|
|
{:error, {:already_started, _pid}} -> :ok
|
|
{:error, _} -> :ok
|
|
end
|
|
|
|
Swoosh.Adapters.Local.Storage.Memory.delete_all()
|
|
on_exit(fn -> Swoosh.Adapters.Local.Storage.Memory.delete_all() end)
|
|
end
|
|
|
|
@doc """
|
|
Safely pop an email from the Swoosh mailbox with retry logic.
|
|
|
|
This is necessary because `Oban.drain_queue/1` doesn't guarantee that
|
|
jobs have finished executing by the time it returns. This helper will
|
|
retry a few times with small delays to handle the race condition.
|
|
"""
|
|
def pop_email(retry_count \\ 10, delay_ms \\ 10) do
|
|
case Swoosh.Adapters.Local.Storage.Memory.all() do
|
|
[] when retry_count > 0 ->
|
|
Process.sleep(delay_ms)
|
|
pop_email(retry_count - 1, delay_ms)
|
|
|
|
[] ->
|
|
raise "No emails found in mailbox after retries"
|
|
|
|
_emails ->
|
|
Swoosh.Adapters.Local.Storage.Memory.pop()
|
|
end
|
|
end
|
|
end
|