mirror of
https://codeberg.org/JasterV/spazio-solazzo.git
synced 2026-04-26 18:20:03 +00:00
update tests to make credo pass
This commit is contained in:
parent
78de759d96
commit
0d1343f828
9 changed files with 56 additions and 114 deletions
|
|
@ -20,6 +20,7 @@ defmodule SpazioSolazzo.Accounts do
|
|||
define :get_user_by_email, action: :read, get_by: [:email]
|
||||
define :terminate_account, action: :terminate_account, args: [:delete_history]
|
||||
define :update_profile, action: :update_profile, args: [:name, :phone_number]
|
||||
define :make_admin, action: :make_admin, args: []
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -104,6 +104,11 @@ defmodule SpazioSolazzo.Accounts.User do
|
|||
require_atomic? false
|
||||
end
|
||||
|
||||
update :make_admin do
|
||||
accept []
|
||||
change set_attribute(:role, :admin)
|
||||
end
|
||||
|
||||
destroy :terminate_account do
|
||||
description "Delete user account with optional booking data removal"
|
||||
require_atomic? false
|
||||
|
|
@ -122,6 +127,10 @@ defmodule SpazioSolazzo.Accounts.User do
|
|||
authorize_if always()
|
||||
end
|
||||
|
||||
policy action(:make_admin) do
|
||||
authorize_if never()
|
||||
end
|
||||
|
||||
policy action_type(:read) do
|
||||
authorize_if always()
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
<Layouts.app flash={@flash} current_user={@current_user}>
|
||||
<section class="mx-auto max-w-[1200px] px-6 py-10">
|
||||
<.back_to_link
|
||||
navigate={~p"/#{@space.slug}"}
|
||||
navigate={"/#{@space.slug}"}
|
||||
value={"Back to #{@space.name}"}
|
||||
/>
|
||||
|
||||
|
|
|
|||
|
|
@ -1,36 +1,9 @@
|
|||
defmodule SpazioSolazzo.BookingSystem.BookingTest do
|
||||
use ExUnit.Case, async: true
|
||||
|
||||
use SpazioSolazzo.DataCase
|
||||
|
||||
import SpazioSolazzo.AuthHelpers
|
||||
|
||||
alias SpazioSolazzo.BookingSystem
|
||||
|
||||
# Helper for creating booking requests
|
||||
defp request_booking(
|
||||
space_id,
|
||||
user_id,
|
||||
date,
|
||||
start_time,
|
||||
end_time,
|
||||
customer_name,
|
||||
customer_email,
|
||||
customer_phone,
|
||||
customer_comment
|
||||
) do
|
||||
BookingSystem.create_booking(
|
||||
space_id,
|
||||
user_id,
|
||||
date,
|
||||
start_time,
|
||||
end_time,
|
||||
customer_name,
|
||||
customer_email,
|
||||
customer_phone,
|
||||
customer_comment
|
||||
)
|
||||
end
|
||||
|
||||
setup do
|
||||
{:ok, space} =
|
||||
BookingSystem.create_space(
|
||||
|
|
@ -50,7 +23,7 @@ defmodule SpazioSolazzo.BookingSystem.BookingTest do
|
|||
describe "create_booking" do
|
||||
test "creates a booking request successfully", %{space: space, date: date} do
|
||||
assert {:ok, booking} =
|
||||
request_booking(
|
||||
BookingSystem.create_booking(
|
||||
space.id,
|
||||
nil,
|
||||
date,
|
||||
|
|
@ -76,7 +49,7 @@ defmodule SpazioSolazzo.BookingSystem.BookingTest do
|
|||
|
||||
test "creates booking with authenticated user", %{space: space, user: user, date: date} do
|
||||
assert {:ok, booking} =
|
||||
request_booking(
|
||||
BookingSystem.create_booking(
|
||||
space.id,
|
||||
user.id,
|
||||
date,
|
||||
|
|
@ -94,7 +67,7 @@ defmodule SpazioSolazzo.BookingSystem.BookingTest do
|
|||
|
||||
test "rejects booking with end time before start time", %{space: space, date: date} do
|
||||
assert {:error, error} =
|
||||
request_booking(
|
||||
BookingSystem.create_booking(
|
||||
space.id,
|
||||
nil,
|
||||
date,
|
||||
|
|
@ -114,7 +87,7 @@ defmodule SpazioSolazzo.BookingSystem.BookingTest do
|
|||
past_date = Date.add(Date.utc_today(), -1)
|
||||
|
||||
assert {:error, error} =
|
||||
request_booking(
|
||||
BookingSystem.create_booking(
|
||||
space.id,
|
||||
nil,
|
||||
past_date,
|
||||
|
|
@ -134,7 +107,7 @@ defmodule SpazioSolazzo.BookingSystem.BookingTest do
|
|||
today = Date.utc_today()
|
||||
|
||||
assert {:ok, booking} =
|
||||
request_booking(
|
||||
BookingSystem.create_booking(
|
||||
space.id,
|
||||
nil,
|
||||
today,
|
||||
|
|
@ -151,7 +124,7 @@ defmodule SpazioSolazzo.BookingSystem.BookingTest do
|
|||
|
||||
test "requires customer name and email", %{space: space, date: date} do
|
||||
assert {:error, _error} =
|
||||
request_booking(
|
||||
BookingSystem.create_booking(
|
||||
space.id,
|
||||
nil,
|
||||
date,
|
||||
|
|
@ -166,7 +139,7 @@ defmodule SpazioSolazzo.BookingSystem.BookingTest do
|
|||
|
||||
test "phone number is optional", %{space: space, date: date} do
|
||||
assert {:ok, booking} =
|
||||
request_booking(
|
||||
BookingSystem.create_booking(
|
||||
space.id,
|
||||
nil,
|
||||
date,
|
||||
|
|
@ -185,7 +158,7 @@ defmodule SpazioSolazzo.BookingSystem.BookingTest do
|
|||
describe "approve_booking/1" do
|
||||
test "approves a pending booking", %{space: space, date: date} do
|
||||
{:ok, booking} =
|
||||
request_booking(
|
||||
BookingSystem.create_booking(
|
||||
space.id,
|
||||
nil,
|
||||
date,
|
||||
|
|
@ -207,7 +180,7 @@ defmodule SpazioSolazzo.BookingSystem.BookingTest do
|
|||
|
||||
test "cannot approve already approved booking", %{space: space, date: date} do
|
||||
{:ok, booking} =
|
||||
request_booking(
|
||||
BookingSystem.create_booking(
|
||||
space.id,
|
||||
nil,
|
||||
date,
|
||||
|
|
@ -228,7 +201,7 @@ defmodule SpazioSolazzo.BookingSystem.BookingTest do
|
|||
|
||||
test "cannot approve cancelled booking", %{space: space, date: date} do
|
||||
{:ok, booking} =
|
||||
request_booking(
|
||||
BookingSystem.create_booking(
|
||||
space.id,
|
||||
nil,
|
||||
date,
|
||||
|
|
@ -251,7 +224,7 @@ defmodule SpazioSolazzo.BookingSystem.BookingTest do
|
|||
describe "cancel_booking/1" do
|
||||
test "cancels a pending booking", %{space: space, date: date} do
|
||||
{:ok, booking} =
|
||||
request_booking(
|
||||
BookingSystem.create_booking(
|
||||
space.id,
|
||||
nil,
|
||||
date,
|
||||
|
|
@ -271,7 +244,7 @@ defmodule SpazioSolazzo.BookingSystem.BookingTest do
|
|||
|
||||
test "cancels an approved booking", %{space: space, date: date} do
|
||||
{:ok, booking} =
|
||||
request_booking(
|
||||
BookingSystem.create_booking(
|
||||
space.id,
|
||||
nil,
|
||||
date,
|
||||
|
|
@ -291,7 +264,7 @@ defmodule SpazioSolazzo.BookingSystem.BookingTest do
|
|||
|
||||
test "cannot cancel already cancelled booking", %{space: space, date: date} do
|
||||
{:ok, booking} =
|
||||
request_booking(
|
||||
BookingSystem.create_booking(
|
||||
space.id,
|
||||
nil,
|
||||
date,
|
||||
|
|
@ -314,7 +287,7 @@ defmodule SpazioSolazzo.BookingSystem.BookingTest do
|
|||
describe "search_bookings/5 for accepted bookings" do
|
||||
test "returns only approved bookings for specific date", %{space: space, date: date} do
|
||||
{:ok, approved1} =
|
||||
request_booking(
|
||||
BookingSystem.create_booking(
|
||||
space.id,
|
||||
nil,
|
||||
date,
|
||||
|
|
@ -329,7 +302,7 @@ defmodule SpazioSolazzo.BookingSystem.BookingTest do
|
|||
{:ok, _} = BookingSystem.approve_booking(approved1.id)
|
||||
|
||||
{:ok, approved2} =
|
||||
request_booking(
|
||||
BookingSystem.create_booking(
|
||||
space.id,
|
||||
nil,
|
||||
date,
|
||||
|
|
@ -344,7 +317,7 @@ defmodule SpazioSolazzo.BookingSystem.BookingTest do
|
|||
{:ok, _} = BookingSystem.approve_booking(approved2.id)
|
||||
|
||||
{:ok, _pending} =
|
||||
request_booking(
|
||||
BookingSystem.create_booking(
|
||||
space.id,
|
||||
nil,
|
||||
date,
|
||||
|
|
@ -374,7 +347,7 @@ defmodule SpazioSolazzo.BookingSystem.BookingTest do
|
|||
|
||||
test "does not return cancelled bookings", %{space: space, date: date} do
|
||||
{:ok, booking} =
|
||||
request_booking(
|
||||
BookingSystem.create_booking(
|
||||
space.id,
|
||||
nil,
|
||||
date,
|
||||
|
|
@ -408,7 +381,7 @@ defmodule SpazioSolazzo.BookingSystem.BookingTest do
|
|||
other_date = Date.add(date, 1)
|
||||
|
||||
{:ok, booking1} =
|
||||
request_booking(
|
||||
BookingSystem.create_booking(
|
||||
space.id,
|
||||
nil,
|
||||
date,
|
||||
|
|
@ -423,7 +396,7 @@ defmodule SpazioSolazzo.BookingSystem.BookingTest do
|
|||
{:ok, _} = BookingSystem.approve_booking(booking1.id)
|
||||
|
||||
{:ok, booking2} =
|
||||
request_booking(
|
||||
BookingSystem.create_booking(
|
||||
space.id,
|
||||
nil,
|
||||
other_date,
|
||||
|
|
@ -463,7 +436,7 @@ defmodule SpazioSolazzo.BookingSystem.BookingTest do
|
|||
)
|
||||
|
||||
{:ok, booking} =
|
||||
request_booking(
|
||||
BookingSystem.create_booking(
|
||||
other_space.id,
|
||||
nil,
|
||||
date,
|
||||
|
|
@ -496,7 +469,7 @@ defmodule SpazioSolazzo.BookingSystem.BookingTest do
|
|||
describe "count pending requests" do
|
||||
test "returns only pending bookings", %{space: space, date: date} do
|
||||
{:ok, _pending1} =
|
||||
request_booking(
|
||||
BookingSystem.create_booking(
|
||||
space.id,
|
||||
nil,
|
||||
date,
|
||||
|
|
@ -509,7 +482,7 @@ defmodule SpazioSolazzo.BookingSystem.BookingTest do
|
|||
)
|
||||
|
||||
{:ok, approved} =
|
||||
request_booking(
|
||||
BookingSystem.create_booking(
|
||||
space.id,
|
||||
nil,
|
||||
date,
|
||||
|
|
@ -524,7 +497,7 @@ defmodule SpazioSolazzo.BookingSystem.BookingTest do
|
|||
{:ok, _} = BookingSystem.approve_booking(approved.id)
|
||||
|
||||
{:ok, cancelled} =
|
||||
request_booking(
|
||||
BookingSystem.create_booking(
|
||||
space.id,
|
||||
nil,
|
||||
date,
|
||||
|
|
@ -548,7 +521,7 @@ defmodule SpazioSolazzo.BookingSystem.BookingTest do
|
|||
|
||||
test "returns zero when no pending requests", %{space: space, date: date} do
|
||||
{:ok, booking} =
|
||||
request_booking(
|
||||
BookingSystem.create_booking(
|
||||
space.id,
|
||||
nil,
|
||||
date,
|
||||
|
|
@ -580,7 +553,7 @@ defmodule SpazioSolazzo.BookingSystem.BookingTest do
|
|||
)
|
||||
|
||||
{:ok, _pending1} =
|
||||
request_booking(
|
||||
BookingSystem.create_booking(
|
||||
space.id,
|
||||
nil,
|
||||
date,
|
||||
|
|
@ -593,7 +566,7 @@ defmodule SpazioSolazzo.BookingSystem.BookingTest do
|
|||
)
|
||||
|
||||
{:ok, _pending2} =
|
||||
request_booking(
|
||||
BookingSystem.create_booking(
|
||||
other_space.id,
|
||||
nil,
|
||||
date,
|
||||
|
|
|
|||
|
|
@ -2,21 +2,8 @@ defmodule SpazioSolazzoWeb.Admin.BookingManagementPaginationTest do
|
|||
use SpazioSolazzoWeb.ConnCase, async: false
|
||||
|
||||
import Phoenix.LiveViewTest
|
||||
import SpazioSolazzo.AuthHelpers
|
||||
import Ecto.Query
|
||||
|
||||
alias SpazioSolazzo.BookingSystem
|
||||
|
||||
defp create_admin_user do
|
||||
user = register_user("admin@example.com", "Admin User")
|
||||
{:ok, uuid} = Ecto.UUID.dump(user.id)
|
||||
|
||||
from(u in "users", where: u.id == ^uuid)
|
||||
|> SpazioSolazzo.Repo.update_all(set: [role: "admin"])
|
||||
|
||||
user
|
||||
end
|
||||
|
||||
setup do
|
||||
{:ok, space} =
|
||||
BookingSystem.create_space(
|
||||
|
|
@ -26,7 +13,11 @@ defmodule SpazioSolazzoWeb.Admin.BookingManagementPaginationTest do
|
|||
10
|
||||
)
|
||||
|
||||
admin_user = create_admin_user()
|
||||
admin_user =
|
||||
"admin@example.com"
|
||||
|> register_user("Admin User")
|
||||
|> SpazioSolazzo.Accounts.make_admin!(authorize?: false)
|
||||
|
||||
tomorrow = Date.add(Date.utc_today(), 1)
|
||||
|
||||
%{space: space, admin_user: admin_user, tomorrow: tomorrow}
|
||||
|
|
|
|||
|
|
@ -2,21 +2,8 @@ defmodule SpazioSolazzoWeb.Admin.BookingManagementRejectionTest do
|
|||
use SpazioSolazzoWeb.ConnCase, async: true
|
||||
|
||||
import Phoenix.LiveViewTest
|
||||
import SpazioSolazzo.AuthHelpers
|
||||
import Ecto.Query
|
||||
|
||||
alias SpazioSolazzo.BookingSystem
|
||||
|
||||
defp create_admin_user do
|
||||
user = register_user("admin@example.com", "Admin User")
|
||||
{:ok, uuid} = Ecto.UUID.dump(user.id)
|
||||
|
||||
from(u in "users", where: u.id == ^uuid)
|
||||
|> SpazioSolazzo.Repo.update_all(set: [role: "admin"])
|
||||
|
||||
user
|
||||
end
|
||||
|
||||
defp create_booking(space, user) do
|
||||
tomorrow = Date.add(Date.utc_today(), 1)
|
||||
start_time = ~T[10:00:00]
|
||||
|
|
@ -47,7 +34,11 @@ defmodule SpazioSolazzoWeb.Admin.BookingManagementRejectionTest do
|
|||
5
|
||||
)
|
||||
|
||||
admin_user = create_admin_user()
|
||||
admin_user =
|
||||
"admin@example.com"
|
||||
|> register_user("Admin User")
|
||||
|> SpazioSolazzo.Accounts.make_admin!(authorize?: false)
|
||||
|
||||
regular_user = register_user("user@example.com", "Regular User")
|
||||
|
||||
%{space: space, admin_user: admin_user, regular_user: regular_user}
|
||||
|
|
|
|||
|
|
@ -2,22 +2,8 @@ defmodule SpazioSolazzoWeb.Admin.WalkInLiveSimpleTest do
|
|||
use SpazioSolazzoWeb.ConnCase, async: true
|
||||
|
||||
import Phoenix.LiveViewTest
|
||||
import SpazioSolazzo.AuthHelpers
|
||||
import Ecto.Query
|
||||
|
||||
alias SpazioSolazzo.BookingSystem
|
||||
|
||||
defp create_admin_user do
|
||||
user = register_user("admin@example.com", "Admin User")
|
||||
# Directly update role to admin using Ecto
|
||||
{:ok, uuid} = Ecto.UUID.dump(user.id)
|
||||
|
||||
from(u in "users", where: u.id == ^uuid)
|
||||
|> SpazioSolazzo.Repo.update_all(set: [role: "admin"])
|
||||
|
||||
user
|
||||
end
|
||||
|
||||
setup do
|
||||
{:ok, space} =
|
||||
BookingSystem.create_space(
|
||||
|
|
@ -27,7 +13,10 @@ defmodule SpazioSolazzoWeb.Admin.WalkInLiveSimpleTest do
|
|||
5
|
||||
)
|
||||
|
||||
user = create_admin_user()
|
||||
user =
|
||||
"admin@example.com"
|
||||
|> register_user("Admin User")
|
||||
|> SpazioSolazzo.Accounts.make_admin!(authorize?: false)
|
||||
|
||||
%{space: space, user: user}
|
||||
end
|
||||
|
|
|
|||
|
|
@ -2,21 +2,8 @@ defmodule SpazioSolazzoWeb.Admin.WalkInLiveTest do
|
|||
use SpazioSolazzoWeb.ConnCase, async: true
|
||||
|
||||
import Phoenix.LiveViewTest
|
||||
import SpazioSolazzo.AuthHelpers
|
||||
import Ecto.Query
|
||||
|
||||
alias SpazioSolazzo.BookingSystem
|
||||
|
||||
defp create_admin_user do
|
||||
user = register_user("admin@example.com", "Admin User")
|
||||
{:ok, uuid} = Ecto.UUID.dump(user.id)
|
||||
|
||||
from(u in "users", where: u.id == ^uuid)
|
||||
|> SpazioSolazzo.Repo.update_all(set: [role: "admin"])
|
||||
|
||||
user
|
||||
end
|
||||
|
||||
setup do
|
||||
{:ok, space} =
|
||||
BookingSystem.create_space(
|
||||
|
|
@ -26,7 +13,10 @@ defmodule SpazioSolazzoWeb.Admin.WalkInLiveTest do
|
|||
5
|
||||
)
|
||||
|
||||
user = create_admin_user()
|
||||
user =
|
||||
"admin@example.com"
|
||||
|> register_user("Admin User")
|
||||
|> SpazioSolazzo.Accounts.make_admin!(authorize?: false)
|
||||
|
||||
%{space: space, user: user}
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
defmodule SpazioSolazzoWeb.BookingLive.SpaceBookingTest do
|
||||
use SpazioSolazzoWeb.ConnCase
|
||||
import Phoenix.LiveViewTest
|
||||
import SpazioSolazzo.AuthHelpers
|
||||
|
||||
alias SpazioSolazzo.BookingSystem
|
||||
|
||||
# Helper to convert old map-based call to new signature
|
||||
|
|
|
|||
Loading…
Reference in a new issue