mirror of
https://codeberg.org/JasterV/spazio-solazzo.git
synced 2026-04-26 18:20:03 +00:00
refactor: spaces only need a capacity field
This commit is contained in:
parent
5afff793dc
commit
b9c5fb6a13
34 changed files with 85 additions and 233 deletions
|
|
@ -12,7 +12,7 @@ defmodule SpazioSolazzo.BookingSystem do
|
|||
|
||||
define :create_space,
|
||||
action: :create,
|
||||
args: [:name, :slug, :description, :public_capacity, :real_capacity]
|
||||
args: [:name, :slug, :description, :capacity]
|
||||
|
||||
define :check_availability,
|
||||
action: :check_availability,
|
||||
|
|
|
|||
|
|
@ -18,25 +18,15 @@ defmodule SpazioSolazzo.BookingSystem.Space do
|
|||
defaults [:read]
|
||||
|
||||
create :create do
|
||||
accept [:name, :description, :slug, :public_capacity, :real_capacity]
|
||||
accept [:name, :description, :slug, :capacity]
|
||||
|
||||
validate fn changeset, _ctx ->
|
||||
real_capacity = Ash.Changeset.get_attribute(changeset, :real_capacity)
|
||||
public_capacity = Ash.Changeset.get_attribute(changeset, :public_capacity)
|
||||
capacity = Ash.Changeset.get_attribute(changeset, :capacity)
|
||||
|
||||
cond do
|
||||
real_capacity && real_capacity <= 0 ->
|
||||
{:error, field: :real_capacity, message: "must be greater than 0"}
|
||||
|
||||
public_capacity && public_capacity <= 0 ->
|
||||
{:error, field: :public_capacity, message: "must be greater than 0"}
|
||||
|
||||
real_capacity && public_capacity && public_capacity > real_capacity ->
|
||||
{:error,
|
||||
field: :public_capacity, message: "must be less than or equal to real_capacity"}
|
||||
|
||||
true ->
|
||||
:ok
|
||||
if capacity && capacity <= 0 do
|
||||
{:error, field: :capacity, message: "must be greater than 0"}
|
||||
else
|
||||
:ok
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -76,10 +66,10 @@ defmodule SpazioSolazzo.BookingSystem.Space do
|
|||
current_count = length(overlapping_bookings)
|
||||
|
||||
availability =
|
||||
cond do
|
||||
current_count >= space.real_capacity -> :over_real_capacity
|
||||
current_count >= space.public_capacity -> :over_public_capacity
|
||||
true -> :available
|
||||
if current_count >= space.capacity do
|
||||
:over_capacity
|
||||
else
|
||||
:available
|
||||
end
|
||||
|
||||
{:ok, availability}
|
||||
|
|
@ -114,8 +104,7 @@ defmodule SpazioSolazzo.BookingSystem.Space do
|
|||
attribute :name, :string, allow_nil?: false, public?: true
|
||||
attribute :description, :string, allow_nil?: false, public?: true
|
||||
attribute :slug, :string, allow_nil?: false, public?: true
|
||||
attribute :public_capacity, :integer, allow_nil?: false, public?: true
|
||||
attribute :real_capacity, :integer, allow_nil?: false, public?: true
|
||||
attribute :capacity, :integer, allow_nil?: false, public?: true
|
||||
end
|
||||
|
||||
identities do
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ defmodule SpazioSolazzoWeb.Admin.AdminCalendarComponent do
|
|||
# Check capacity
|
||||
capacity_status = Map.get(socket.assigns.day_capacities, date, :available)
|
||||
|
||||
if capacity_status == :over_real_capacity do
|
||||
if capacity_status == :over_capacity do
|
||||
{:noreply, socket}
|
||||
else
|
||||
socket =
|
||||
|
|
@ -181,10 +181,10 @@ defmodule SpazioSolazzoWeb.Admin.AdminCalendarComponent do
|
|||
# Count unique booking slots (simplified - counts all bookings)
|
||||
booking_count = length(bookings)
|
||||
|
||||
cond do
|
||||
booking_count >= space.real_capacity -> :over_real_capacity
|
||||
booking_count >= space.public_capacity -> :over_public_capacity
|
||||
true -> :available
|
||||
if booking_count >= space.capacity do
|
||||
:over_capacity
|
||||
else
|
||||
:available
|
||||
end
|
||||
|
||||
_ ->
|
||||
|
|
@ -257,10 +257,10 @@ defmodule SpazioSolazzoWeb.Admin.AdminCalendarComponent do
|
|||
is_past ->
|
||||
[base, "text-slate-400 dark:text-slate-600 cursor-not-allowed opacity-50"]
|
||||
|
||||
capacity == :over_real_capacity ->
|
||||
capacity == :over_capacity ->
|
||||
[
|
||||
base,
|
||||
"bg-red-50 dark:bg-red-900/20 text-slate-400 dark:text-slate-500 border border-red-300 dark:border-red-800/30 cursor-not-allowed"
|
||||
"bg-orange-100 dark:bg-orange-900/20 text-slate-400 dark:text-slate-500 border border-orange-300 dark:border-orange-800/30 cursor-not-allowed"
|
||||
]
|
||||
|
||||
in_range && assigns.multi_day_mode && assigns.end_date != nil ->
|
||||
|
|
@ -290,12 +290,6 @@ defmodule SpazioSolazzoWeb.Admin.AdminCalendarComponent do
|
|||
"rounded-lg bg-primary text-white shadow-lg shadow-primary/30 relative z-10 hover:scale-105"
|
||||
]
|
||||
|
||||
capacity == :over_public_capacity ->
|
||||
[
|
||||
base,
|
||||
"rounded-lg bg-orange-100 dark:bg-orange-900/20 hover:bg-orange-200 dark:hover:bg-orange-900/40 text-slate-700 dark:text-slate-200 border border-transparent hover:border-orange-500 dark:hover:border-orange-600"
|
||||
]
|
||||
|
||||
true ->
|
||||
[
|
||||
base,
|
||||
|
|
@ -307,8 +301,7 @@ defmodule SpazioSolazzoWeb.Admin.AdminCalendarComponent do
|
|||
defp capacity_indicator_color(capacity) do
|
||||
case capacity do
|
||||
:available -> "bg-green-500"
|
||||
:over_public_capacity -> "bg-orange-500"
|
||||
:over_real_capacity -> "bg-red-500"
|
||||
:over_capacity -> "bg-orange-500"
|
||||
_ -> "bg-slate-300"
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -32,11 +32,7 @@
|
|||
</div>
|
||||
<div class="flex items-center gap-1">
|
||||
<div class="w-2 h-2 rounded-full bg-orange-500"></div>
|
||||
<span class="text-slate-600 dark:text-slate-400">High Demand</span>
|
||||
</div>
|
||||
<div class="flex items-center gap-1">
|
||||
<div class="w-2 h-2 rounded-full bg-red-500"></div>
|
||||
<span class="text-slate-600 dark:text-slate-400">Full</span>
|
||||
<span class="text-slate-600 dark:text-slate-400">Overbooked</span>
|
||||
</div>
|
||||
<%= if @multi_day_mode && @start_date do %>
|
||||
<div class="flex items-center gap-1">
|
||||
|
|
@ -90,7 +86,7 @@
|
|||
<% else %>
|
||||
<% capacity = Map.get(@day_capacities, day, :available) %>
|
||||
<% is_past = Date.compare(day, Date.utc_today()) == :lt %>
|
||||
<% is_disabled = is_past || capacity == :over_real_capacity %>
|
||||
<% is_disabled = is_past || capacity == :over_capacity %>
|
||||
<% is_start = is_start_date?(day, @start_date, @end_date) %>
|
||||
<% is_end = is_end_date?(day, @start_date, @end_date) %>
|
||||
|
||||
|
|
@ -103,7 +99,7 @@
|
|||
title={
|
||||
cond do
|
||||
is_past -> "Past date"
|
||||
capacity == :over_real_capacity -> "Fully Booked"
|
||||
capacity == :over_capacity -> "Overbooked"
|
||||
true -> "Select date"
|
||||
end
|
||||
}
|
||||
|
|
@ -149,7 +145,7 @@
|
|||
@start_date
|
||||
|> Date.range(@end_date)
|
||||
|> Enum.any?(fn date ->
|
||||
Map.get(@day_capacities, date, :available) == :over_real_capacity
|
||||
Map.get(@day_capacities, date, :available) == :over_capacity
|
||||
end) %>
|
||||
|
||||
<%= if has_full_days do %>
|
||||
|
|
@ -162,7 +158,7 @@
|
|||
Attention
|
||||
</h4>
|
||||
<p class="text-xs font-medium text-red-700 dark:text-red-300 mt-1">
|
||||
Some days in your selected range have reached maximum capacity.
|
||||
Some days in your selected range are overbooked.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -160,12 +160,9 @@ defmodule SpazioSolazzoWeb.Admin.WalkInLive do
|
|||
socket.assigns.start_time,
|
||||
socket.assigns.end_time
|
||||
) do
|
||||
{:ok, :over_real_capacity} ->
|
||||
assign(socket, time_slot_warning: "This time slot is currently full.")
|
||||
|
||||
{:ok, :over_public_capacity} ->
|
||||
{:ok, :over_capacity} ->
|
||||
assign(socket,
|
||||
time_slot_warning: "This time slot has high demand but space is still available."
|
||||
time_slot_warning: "This time slot is currently overbooked. Proceed with caution."
|
||||
)
|
||||
|
||||
_ ->
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ defmodule SpazioSolazzoWeb.BookingFormLiveComponent do
|
|||
</:subtitle>
|
||||
|
||||
<div>
|
||||
<%= if @slot_availability == :over_public_capacity do %>
|
||||
<%= if @slot_availability == :over_capacity do %>
|
||||
<div class="mb-6 p-4 bg-yellow-50 dark:bg-yellow-900/20 border-l-4 border-yellow-400 rounded">
|
||||
<div class="flex gap-3">
|
||||
<div class="flex-shrink-0">
|
||||
|
|
|
|||
|
|
@ -49,8 +49,7 @@
|
|||
<% counts =
|
||||
Map.get(@slot_booking_counts, time_slot.id, %{pending: 0, approved: 0}) %>
|
||||
<% user_has_booking = Map.get(@user_booked_slots, time_slot.id, false) %>
|
||||
<%= if availability != :over_real_capacity do %>
|
||||
<button
|
||||
<button
|
||||
phx-click={if user_has_booking, do: nil, else: "select_slot"}
|
||||
phx-value-time_slot_id={time_slot.id}
|
||||
disabled={user_has_booking}
|
||||
|
|
@ -123,7 +122,6 @@
|
|||
/>
|
||||
</div>
|
||||
</button>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
booking_label="Book Space"
|
||||
price="€25"
|
||||
price_unit="day"
|
||||
capacity={@space.public_capacity}
|
||||
capacity={@space.capacity}
|
||||
images={[
|
||||
"https://lh3.googleusercontent.com/aida-public/AB6AXuDmh_AkVuUoICqpHk1NdLuLdi0xQBOC8Hy9PrsSNz956igHFRhbNGsB8k0vSLe2U2NW1sxRVZm_dwR27Q4Db_f21XbYkLtfiRYob-j4ran1rTBB0bQAz4QLFSO1yL_cPhDIpAyvC069mDQ33-ckZgZ_yvFsIK_-_0Jj2NEOnDie684uaR7vKuiBWlsr-JmAsPzUp7Aik7Qbzozune348nBz1bvWkBNMCpMO3JV8hrYBo1i6JlUiGSuP3-5fWXKt8dKhxPUN-amjLFgh",
|
||||
"https://lh3.googleusercontent.com/aida-public/AB6AXuCh5O9cz1ruQFH0Pq3MzC_1HsWrLPHbWlfYEdB2dmPi0YDn2L23R5hseUZmb19XlEju1n4a24oD6pH5qiG4SvIemrD45PfKwvNlckpOG59IYz5WYrHzroq7L4Uq9Hxl0PTzU5m8R5k625w_MrdZKidyfM6OnzNJfM5J3XftFI5A9J7wD_BDHRKxq8gxAukUCesuYX8lGm3AhQAZQTjaUY5yeobjt-NCSrlfTzxmcUmibJSTnKZuwx-li4QtFr0wQrzHVLUZYiAhA251",
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
booking_label="Book Space"
|
||||
price="€35"
|
||||
price_unit="hour"
|
||||
capacity={@space.public_capacity}
|
||||
capacity={@space.capacity}
|
||||
images={[
|
||||
"https://lh3.googleusercontent.com/aida-public/AB6AXuDmh_AkVuUoICqpHk1NdLuLdi0xQBOC8Hy9PrsSNz956igHFRhbNGsB8k0vSLe2U2NW1sxRVZm_dwR27Q4Db_f21XbYkLtfiRYob-j4ran1rTBB0bQAz4QLFSO1yL_cPhDIpAyvC069mDQ33-ckZgZ_yvFsIK_-_0Jj2NEOnDie684uaR7vKuiBWlsr-JmAsPzUp7Aik7Qbzozune348nBz1bvWkBNMCpMO3JV8hrYBo1i6JlUiGSuP3-5fWXKt8dKhxPUN-amjLFgh",
|
||||
"https://lh3.googleusercontent.com/aida-public/AB6AXuCh5O9cz1ruQFH0Pq3MzC_1HsWrLPHbWlfYEdB2dmPi0YDn2L23R5hseUZmb19XlEju1n4a24oD6pH5qiG4SvIemrD45PfKwvNlckpOG59IYz5WYrHzroq7L4Uq9Hxl0PTzU5m8R5k625w_MrdZKidyfM6OnzNJfM5J3XftFI5A9J7wD_BDHRKxq8gxAukUCesuYX8lGm3AhQAZQTjaUY5yeobjt-NCSrlfTzxmcUmibJSTnKZuwx-li4QtFr0wQrzHVLUZYiAhA251",
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
booking_label="Book Space"
|
||||
price="€50"
|
||||
price_unit="hour"
|
||||
capacity={@space.public_capacity}
|
||||
capacity={@space.capacity}
|
||||
images={[
|
||||
"https://lh3.googleusercontent.com/aida-public/AB6AXuD1wkxK48dk7i5XYX6JL-O1egrsdLjcmOg7N4EB76QtUvhzR7lZQadprIT9rLPsroUjazftFRpp_z26wb8lHaUW9XyucGlKG3qG40oT5iaKWwqVI1drNKJDJgVBkmNjw4u_D5vig_C1pf6bgGZnPaOV2tnnmlexxHJIDQYZzfg1GGwgywBvpGLz_u2_jvkbyMo3_m5roM09PjonFEfGIHxjm0vClW1DAOX45IrT87A85OdAXEu2EPyB8oW9WzmolOn4DFj22vKWSbVD",
|
||||
"https://lh3.googleusercontent.com/aida-public/AB6AXuB3fJu4mgZaw8GP1OC2SjquJZJmnRlY_OHD4fO4AAd_KHd5BYnW1i0egrskoEfK_uCdK4pQu5kMf8pF9h_KXE0wYQAROnTBTJ4YmBpHui9nv8wz44VENo2p-lA3rW8xhQhiYzlAhHJlhgOdZluVp9eYvsZxGM76QkDXMcBQz1Ka5ZfRMNgddo1RS76IPaxbQIvpOh_55uW87bAiGAvhcE8GrIi2ugpiJ64Rdou1uZLD1bPWxUvyLtpTFFLr2vfVjq7OpVYiGnLaGstS",
|
||||
|
|
|
|||
|
|
@ -60,8 +60,7 @@ defmodule SpazioSolazzo.Repo.Migrations.CreateBaseResources do
|
|||
add :name, :text, null: false
|
||||
add :description, :text, null: false
|
||||
add :slug, :text, null: false
|
||||
add :public_capacity, :bigint, null: false
|
||||
add :real_capacity, :bigint, null: false
|
||||
add :capacity, :bigint, null: false
|
||||
end
|
||||
|
||||
create unique_index(:spaces, [:name], name: "spaces_unique_name_index")
|
||||
|
|
@ -126,8 +125,7 @@ defmodule SpazioSolazzo.Repo.Migrations.CreateBaseResources do
|
|||
drop_if_exists unique_index(:spaces, [:name], name: "spaces_unique_name_index")
|
||||
|
||||
alter table(:spaces) do
|
||||
remove :real_capacity
|
||||
remove :public_capacity
|
||||
remove :capacity
|
||||
remove :slug
|
||||
remove :description
|
||||
remove :name
|
||||
|
|
@ -17,38 +17,35 @@ case BookingSystem.Space |> Ash.read() do
|
|||
:ok
|
||||
end
|
||||
|
||||
# Create Coworking Space (public_capacity: 10, real_capacity: 12)
|
||||
# Create Coworking Space (capacity: 10)
|
||||
coworking =
|
||||
BookingSystem.create_space!(
|
||||
"Arcipelago",
|
||||
"coworking",
|
||||
"Flexible desk spaces for remote work",
|
||||
10,
|
||||
12
|
||||
10
|
||||
)
|
||||
|
||||
IO.puts("✓ Created Coworking space")
|
||||
|
||||
# Create Meeting Room Space (public_capacity: 1, real_capacity: 1)
|
||||
# Create Meeting Room Space (capacity: 1)
|
||||
meeting =
|
||||
BookingSystem.create_space!(
|
||||
"Media room",
|
||||
"meeting",
|
||||
"Private conference room for your meetings",
|
||||
1,
|
||||
1
|
||||
)
|
||||
|
||||
IO.puts("✓ Created Meeting Room space")
|
||||
|
||||
# Create Music Studio Space (public_capacity: 1, real_capacity: 2)
|
||||
# Create Music Studio Space (capacity: 1)
|
||||
music =
|
||||
BookingSystem.create_space!(
|
||||
"Hall",
|
||||
"music",
|
||||
"Tailored for band rehearsals.",
|
||||
1,
|
||||
2
|
||||
1
|
||||
)
|
||||
|
||||
IO.puts("✓ Created Music Studio space")
|
||||
|
|
|
|||
|
|
@ -57,19 +57,7 @@
|
|||
"references": null,
|
||||
"scale": null,
|
||||
"size": null,
|
||||
"source": "public_capacity",
|
||||
"type": "bigint"
|
||||
},
|
||||
{
|
||||
"allow_nil?": false,
|
||||
"default": "nil",
|
||||
"generated?": false,
|
||||
"precision": null,
|
||||
"primary_key?": false,
|
||||
"references": null,
|
||||
"scale": null,
|
||||
"size": null,
|
||||
"source": "real_capacity",
|
||||
"source": "capacity",
|
||||
"type": "bigint"
|
||||
}
|
||||
],
|
||||
|
|
@ -78,7 +66,7 @@
|
|||
"custom_indexes": [],
|
||||
"custom_statements": [],
|
||||
"has_create_action": true,
|
||||
"hash": "8C04048A6F7E0263FAA5078E0561DF61F4F7858EACAEB62A63F41D3A11DB3317",
|
||||
"hash": "900D00B10E6347AEAB477B96DE6C11FCC9AD623D34E5DB404EA57E89E8A77E5B",
|
||||
"identities": [
|
||||
{
|
||||
"all_tenants?": false,
|
||||
|
|
@ -85,7 +85,7 @@
|
|||
"custom_indexes": [],
|
||||
"custom_statements": [],
|
||||
"has_create_action": true,
|
||||
"hash": "E90087CB07EEC08732A24BCFC5114E66CCF992BDAE093E32565BDB922781F3FF",
|
||||
"hash": "F8562173C786461A330298CE68DE2EC79F3FD8380966F2F9E318E6010DEE466E",
|
||||
"identities": [],
|
||||
"multitenancy": {
|
||||
"attribute": null,
|
||||
|
|
@ -90,7 +90,7 @@
|
|||
"custom_indexes": [],
|
||||
"custom_statements": [],
|
||||
"has_create_action": true,
|
||||
"hash": "A243D17701FAFD73D4B00DECBADC36EDBD6E58479228892FFEC235CA2A1119A4",
|
||||
"hash": "BEBC6DCB3A49C5C7A830CD684C51A1F901F7AB857C72B559F98A6D9ABAB6DB95",
|
||||
"identities": [],
|
||||
"multitenancy": {
|
||||
"attribute": null,
|
||||
|
|
@ -66,7 +66,7 @@
|
|||
"custom_indexes": [],
|
||||
"custom_statements": [],
|
||||
"has_create_action": true,
|
||||
"hash": "C0CABA03FB9BA869F1460B25693E0222AB1CE8B59A15BB0E343DAB3F4F3949E4",
|
||||
"hash": "8150DCC90B96652CEC9629DE7283AED0E40B0E9A860BE5B1F25BC7E6BF8C0570",
|
||||
"identities": [
|
||||
{
|
||||
"all_tenants?": false,
|
||||
|
|
@ -179,8 +179,7 @@ defmodule SpazioSolazzo.Accounts.UserTest do
|
|||
"Test Space #{unique_id}",
|
||||
"test-space-#{unique_id}",
|
||||
"Test description",
|
||||
10,
|
||||
12
|
||||
10
|
||||
)
|
||||
|
||||
{:ok, time_slot} =
|
||||
|
|
|
|||
|
|
@ -37,8 +37,7 @@ defmodule SpazioSolazzo.BookingSystem.BookingTest do
|
|||
"Test Space",
|
||||
"test-space",
|
||||
"Test description",
|
||||
2,
|
||||
3
|
||||
2
|
||||
)
|
||||
|
||||
user = register_user("testuser@example.com", "Test User")
|
||||
|
|
@ -430,7 +429,6 @@ defmodule SpazioSolazzo.BookingSystem.BookingTest do
|
|||
"Other Space",
|
||||
"other-space",
|
||||
"Other description",
|
||||
5,
|
||||
5
|
||||
)
|
||||
|
||||
|
|
@ -606,7 +604,7 @@ defmodule SpazioSolazzo.BookingSystem.BookingTest do
|
|||
assert status == :available
|
||||
end
|
||||
|
||||
test "returns :over_public_capacity when at or over public but under real capacity", %{
|
||||
test "returns :over_capacity when at or over capacity", %{
|
||||
space: space,
|
||||
date: date
|
||||
} do
|
||||
|
|
@ -635,39 +633,7 @@ defmodule SpazioSolazzo.BookingSystem.BookingTest do
|
|||
~T[10:00:00]
|
||||
)
|
||||
|
||||
assert status == :over_public_capacity
|
||||
end
|
||||
|
||||
test "returns :over_real_capacity when at or over real capacity", %{
|
||||
space: space,
|
||||
date: date
|
||||
} do
|
||||
for i <- 1..3 do
|
||||
{:ok, booking} =
|
||||
request_booking(
|
||||
space.id,
|
||||
nil,
|
||||
date,
|
||||
~T[09:00:00],
|
||||
~T[10:00:00],
|
||||
"User #{i}",
|
||||
"user#{i}@example.com",
|
||||
"",
|
||||
""
|
||||
)
|
||||
|
||||
{:ok, _} = BookingSystem.approve_booking(booking.id)
|
||||
end
|
||||
|
||||
{:ok, status} =
|
||||
BookingSystem.check_availability(
|
||||
space.id,
|
||||
date,
|
||||
~T[09:00:00],
|
||||
~T[10:00:00]
|
||||
)
|
||||
|
||||
assert status == :over_real_capacity
|
||||
assert status == :over_capacity
|
||||
end
|
||||
|
||||
test "only counts overlapping bookings", %{space: space, date: date} do
|
||||
|
|
@ -738,7 +704,7 @@ defmodule SpazioSolazzo.BookingSystem.BookingTest do
|
|||
~T[12:00:00]
|
||||
)
|
||||
|
||||
assert status == :over_public_capacity
|
||||
assert status == :over_capacity
|
||||
end
|
||||
|
||||
test "does not count pending bookings", %{space: space, date: date} do
|
||||
|
|
@ -877,7 +843,6 @@ defmodule SpazioSolazzo.BookingSystem.BookingTest do
|
|||
"Other Space",
|
||||
"other-space-pending",
|
||||
"Other description",
|
||||
5,
|
||||
5
|
||||
)
|
||||
|
||||
|
|
@ -1069,7 +1034,7 @@ defmodule SpazioSolazzo.BookingSystem.BookingTest do
|
|||
|
||||
{:ok, status} = BookingSystem.check_availability(space.id, date, start_time, end_time)
|
||||
|
||||
assert status == :over_real_capacity
|
||||
assert status == :over_capacity
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -1270,7 +1235,6 @@ defmodule SpazioSolazzo.BookingSystem.BookingTest do
|
|||
"Other Space",
|
||||
"other-space-counts",
|
||||
"Other description",
|
||||
5,
|
||||
5
|
||||
)
|
||||
|
||||
|
|
@ -1300,7 +1264,6 @@ defmodule SpazioSolazzo.BookingSystem.BookingTest do
|
|||
"Other Space",
|
||||
"other-space-all",
|
||||
"Other description",
|
||||
5,
|
||||
5
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -11,8 +11,7 @@ defmodule SpazioSolazzo.BookingSystem.DuplicateBookingPreventionTest do
|
|||
"Coworking",
|
||||
"coworking",
|
||||
"Coworking space",
|
||||
5,
|
||||
10
|
||||
5
|
||||
)
|
||||
|
||||
user = register_user("user@example.com", "Test User")
|
||||
|
|
|
|||
|
|
@ -15,8 +15,7 @@ defmodule SpazioSolazzo.BookingSystem.MultiDayBookingTest do
|
|||
"Coworking",
|
||||
"coworking",
|
||||
"Coworking space for testing",
|
||||
5,
|
||||
10
|
||||
5
|
||||
)
|
||||
|
||||
%{space: space}
|
||||
|
|
@ -161,7 +160,7 @@ defmodule SpazioSolazzo.BookingSystem.MultiDayBookingTest do
|
|||
{:ok, availability} =
|
||||
BookingSystem.check_availability(space.id, middle_date, ~T[10:00:00], ~T[16:00:00])
|
||||
|
||||
assert availability == :over_public_capacity
|
||||
assert availability == :over_capacity
|
||||
end
|
||||
|
||||
test "can have both single-day and multi-day bookings on the same day", %{space: space} do
|
||||
|
|
|
|||
|
|
@ -4,50 +4,20 @@ defmodule SpazioSolazzo.BookingSystem.SpaceTest do
|
|||
|
||||
alias SpazioSolazzo.BookingSystem
|
||||
|
||||
describe "create_space/5" do
|
||||
describe "create_space/4" do
|
||||
test "creates a space with all attributes" do
|
||||
assert {:ok, space} =
|
||||
BookingSystem.create_space(
|
||||
"Test Space",
|
||||
"test-space",
|
||||
"test description",
|
||||
10,
|
||||
12
|
||||
10
|
||||
)
|
||||
|
||||
assert space.name == "Test Space"
|
||||
assert space.slug == "test-space"
|
||||
assert space.description == "test description"
|
||||
assert space.public_capacity == 10
|
||||
assert space.real_capacity == 12
|
||||
end
|
||||
|
||||
test "requires public_capacity to be less than or equal to real_capacity" do
|
||||
assert {:error, error} =
|
||||
BookingSystem.create_space(
|
||||
"Invalid Space",
|
||||
"invalid",
|
||||
"description",
|
||||
15,
|
||||
10
|
||||
)
|
||||
|
||||
error_messages = Ash.Error.error_descriptions(error)
|
||||
assert String.contains?(error_messages, "must be less than or equal to real_capacity")
|
||||
end
|
||||
|
||||
test "allows public_capacity to equal real_capacity" do
|
||||
assert {:ok, space} =
|
||||
BookingSystem.create_space(
|
||||
"Equal Space",
|
||||
"equal",
|
||||
"description",
|
||||
10,
|
||||
10
|
||||
)
|
||||
|
||||
assert space.public_capacity == 10
|
||||
assert space.real_capacity == 10
|
||||
assert space.capacity == 10
|
||||
end
|
||||
|
||||
test "requires positive capacity values" do
|
||||
|
|
@ -56,8 +26,7 @@ defmodule SpazioSolazzo.BookingSystem.SpaceTest do
|
|||
"Zero Space",
|
||||
"zero",
|
||||
"description",
|
||||
-1,
|
||||
5
|
||||
-1
|
||||
)
|
||||
|
||||
error_messages = Ash.Error.error_descriptions(error)
|
||||
|
|
@ -68,7 +37,7 @@ defmodule SpazioSolazzo.BookingSystem.SpaceTest do
|
|||
describe "get_space_by_slug/1" do
|
||||
test "retrieves space by slug" do
|
||||
{:ok, _} =
|
||||
BookingSystem.create_space("Space", "test-slug", "test description", 5, 5)
|
||||
BookingSystem.create_space("Space", "test-slug", "test description", 5)
|
||||
|
||||
assert {:ok, space} = BookingSystem.get_space_by_slug("test-slug")
|
||||
|
||||
|
|
@ -84,10 +53,10 @@ defmodule SpazioSolazzo.BookingSystem.SpaceTest do
|
|||
describe "space uniqueness" do
|
||||
test "can't create two spaces with same slug" do
|
||||
assert {:ok, _} =
|
||||
BookingSystem.create_space("Space 1", "same-slug", "description 1", 5, 5)
|
||||
BookingSystem.create_space("Space 1", "same-slug", "description 1", 5)
|
||||
|
||||
assert {:error, error} =
|
||||
BookingSystem.create_space("Space 2", "same-slug", "description 2", 10, 10)
|
||||
BookingSystem.create_space("Space 2", "same-slug", "description 2", 10)
|
||||
|
||||
error_messages = Ash.Error.error_descriptions(error)
|
||||
|
||||
|
|
@ -96,10 +65,10 @@ defmodule SpazioSolazzo.BookingSystem.SpaceTest do
|
|||
|
||||
test "can't create two spaces with same name" do
|
||||
assert {:ok, _} =
|
||||
BookingSystem.create_space("Same Name", "slug-1", "description 1", 5, 5)
|
||||
BookingSystem.create_space("Same Name", "slug-1", "description 1", 5)
|
||||
|
||||
assert {:error, error} =
|
||||
BookingSystem.create_space("Same Name", "slug-2", "description 2", 10, 10)
|
||||
BookingSystem.create_space("Same Name", "slug-2", "description 2", 10)
|
||||
|
||||
error_messages = Ash.Error.error_descriptions(error)
|
||||
|
||||
|
|
@ -108,10 +77,10 @@ defmodule SpazioSolazzo.BookingSystem.SpaceTest do
|
|||
|
||||
test "can create spaces with different names and slugs" do
|
||||
assert {:ok, space1} =
|
||||
BookingSystem.create_space("Space 1", "slug-1", "description 1", 5, 5)
|
||||
BookingSystem.create_space("Space 1", "slug-1", "description 1", 5)
|
||||
|
||||
assert {:ok, space2} =
|
||||
BookingSystem.create_space("Space 2", "slug-2", "description 2", 10, 10)
|
||||
BookingSystem.create_space("Space 2", "slug-2", "description 2", 10)
|
||||
|
||||
assert space1.id != space2.id
|
||||
end
|
||||
|
|
@ -124,8 +93,7 @@ defmodule SpazioSolazzo.BookingSystem.SpaceTest do
|
|||
"Availability Test Space",
|
||||
"availability-test",
|
||||
"Test description",
|
||||
2,
|
||||
3
|
||||
2
|
||||
)
|
||||
|
||||
%{space: space}
|
||||
|
|
@ -140,7 +108,7 @@ defmodule SpazioSolazzo.BookingSystem.SpaceTest do
|
|||
BookingSystem.check_availability(space.id, date, start_time, end_time)
|
||||
end
|
||||
|
||||
test "returns :available when under public capacity", %{space: space} do
|
||||
test "returns :available when under capacity", %{space: space} do
|
||||
date = Date.add(Date.utc_today(), 1)
|
||||
start_time = ~T[09:00:00]
|
||||
end_time = ~T[10:00:00]
|
||||
|
|
@ -159,9 +127,7 @@ defmodule SpazioSolazzo.BookingSystem.SpaceTest do
|
|||
BookingSystem.check_availability(space.id, date, start_time, end_time)
|
||||
end
|
||||
|
||||
test "returns :over_public_capacity when at public capacity but under real capacity", %{
|
||||
space: space
|
||||
} do
|
||||
test "returns :over_capacity when at or over capacity", %{space: space} do
|
||||
date = Date.add(Date.utc_today(), 1)
|
||||
start_time = ~T[09:00:00]
|
||||
end_time = ~T[10:00:00]
|
||||
|
|
@ -186,28 +152,7 @@ defmodule SpazioSolazzo.BookingSystem.SpaceTest do
|
|||
nil
|
||||
)
|
||||
|
||||
assert {:ok, :over_public_capacity} =
|
||||
BookingSystem.check_availability(space.id, date, start_time, end_time)
|
||||
end
|
||||
|
||||
test "returns :over_real_capacity when at real capacity", %{space: space} do
|
||||
date = Date.add(Date.utc_today(), 1)
|
||||
start_time = ~T[09:00:00]
|
||||
end_time = ~T[10:00:00]
|
||||
|
||||
for i <- 1..3 do
|
||||
BookingSystem.create_walk_in(
|
||||
space.id,
|
||||
DateTime.new!(date, start_time, "Etc/UTC"),
|
||||
DateTime.new!(date, end_time, "Etc/UTC"),
|
||||
"Customer #{i}",
|
||||
"customer#{i}@example.com",
|
||||
nil,
|
||||
nil
|
||||
)
|
||||
end
|
||||
|
||||
assert {:ok, :over_real_capacity} =
|
||||
assert {:ok, :over_capacity} =
|
||||
BookingSystem.check_availability(space.id, date, start_time, end_time)
|
||||
end
|
||||
|
||||
|
|
@ -265,7 +210,7 @@ defmodule SpazioSolazzo.BookingSystem.SpaceTest do
|
|||
nil
|
||||
)
|
||||
|
||||
assert {:ok, :over_public_capacity} =
|
||||
assert {:ok, :over_capacity} =
|
||||
BookingSystem.check_availability(space.id, date, start_time, end_time)
|
||||
end
|
||||
|
||||
|
|
@ -400,8 +345,7 @@ defmodule SpazioSolazzo.BookingSystem.SpaceTest do
|
|||
"Other Space",
|
||||
"other-space",
|
||||
"Another test space",
|
||||
2,
|
||||
3
|
||||
2
|
||||
)
|
||||
|
||||
date = Date.add(Date.utc_today(), 1)
|
||||
|
|
|
|||
|
|
@ -10,8 +10,7 @@ defmodule SpazioSolazzo.BookingSystem.TimeSlotTemplateTest do
|
|||
"Test Space",
|
||||
"test-space",
|
||||
"Test description",
|
||||
10,
|
||||
12
|
||||
10
|
||||
)
|
||||
|
||||
%{space: space}
|
||||
|
|
@ -243,7 +242,6 @@ defmodule SpazioSolazzo.BookingSystem.TimeSlotTemplateTest do
|
|||
"Other Space",
|
||||
"other-space",
|
||||
"Other description",
|
||||
5,
|
||||
5
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -44,8 +44,7 @@ defmodule SpazioSolazzoWeb.Admin.BookingManagementRejectionTest do
|
|||
"Coworking",
|
||||
"coworking",
|
||||
"Coworking space",
|
||||
5,
|
||||
10
|
||||
5
|
||||
)
|
||||
|
||||
admin_user = create_admin_user()
|
||||
|
|
|
|||
|
|
@ -24,8 +24,7 @@ defmodule SpazioSolazzoWeb.Admin.WalkInLiveSimpleTest do
|
|||
"Coworking",
|
||||
"coworking",
|
||||
"Coworking space",
|
||||
5,
|
||||
10
|
||||
5
|
||||
)
|
||||
|
||||
user = create_admin_user()
|
||||
|
|
|
|||
|
|
@ -23,8 +23,7 @@ defmodule SpazioSolazzoWeb.Admin.WalkInLiveTest do
|
|||
"Coworking",
|
||||
"coworking",
|
||||
"Coworking space",
|
||||
5,
|
||||
10
|
||||
5
|
||||
)
|
||||
|
||||
user = create_admin_user()
|
||||
|
|
|
|||
|
|
@ -26,8 +26,7 @@ defmodule SpazioSolazzoWeb.BookingLive.SpaceBookingTest do
|
|||
"Test Space",
|
||||
"test-space",
|
||||
"Test description",
|
||||
2,
|
||||
3
|
||||
2
|
||||
)
|
||||
|
||||
today = Date.utc_today()
|
||||
|
|
@ -118,7 +117,6 @@ defmodule SpazioSolazzoWeb.BookingLive.SpaceBookingTest do
|
|||
"Empty Space",
|
||||
"empty-space",
|
||||
"No slots",
|
||||
5,
|
||||
5
|
||||
)
|
||||
|
||||
|
|
@ -253,7 +251,7 @@ defmodule SpazioSolazzoWeb.BookingLive.SpaceBookingTest do
|
|||
assert html =~ "High Demand - Join Waitlist"
|
||||
end
|
||||
|
||||
test "hides slots over real capacity", %{conn: conn, space: space, today: today} do
|
||||
test "shows slots over capacity with high demand warning", %{conn: conn, space: space, today: today} do
|
||||
for i <- 1..3 do
|
||||
{:ok, booking} =
|
||||
request_booking(
|
||||
|
|
@ -273,7 +271,8 @@ defmodule SpazioSolazzoWeb.BookingLive.SpaceBookingTest do
|
|||
html = render(view)
|
||||
|
||||
assert html =~ "14:00"
|
||||
refute html =~ "09:00"
|
||||
assert html =~ "09:00"
|
||||
assert html =~ "High Demand"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -594,9 +593,8 @@ defmodule SpazioSolazzoWeb.BookingLive.SpaceBookingTest do
|
|||
BookingSystem.create_space(
|
||||
"Small Space",
|
||||
"small-space",
|
||||
"Limited public capacity",
|
||||
1,
|
||||
2
|
||||
"Limited capacity",
|
||||
1
|
||||
)
|
||||
|
||||
today = Date.utc_today()
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ defmodule SpazioSolazzoWeb.CoworkingLiveTest do
|
|||
alias SpazioSolazzo.BookingSystem
|
||||
|
||||
setup do
|
||||
{:ok, space} = BookingSystem.create_space("CoworkingTest", "coworking", "desc", 10, 12)
|
||||
{:ok, space} = BookingSystem.create_space("CoworkingTest", "coworking", "desc", 10)
|
||||
|
||||
%{space: space}
|
||||
end
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ defmodule SpazioSolazzoWeb.MeetingLiveTest do
|
|||
alias SpazioSolazzo.BookingSystem
|
||||
|
||||
setup do
|
||||
{:ok, space} = BookingSystem.create_space("MeetingTest", "meeting", "desc", 1, 1)
|
||||
{:ok, space} = BookingSystem.create_space("MeetingTest", "meeting", "desc", 1)
|
||||
|
||||
%{space: space}
|
||||
end
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ defmodule SpazioSolazzoWeb.MusicLiveTest do
|
|||
alias SpazioSolazzo.BookingSystem
|
||||
|
||||
setup do
|
||||
{:ok, space} = BookingSystem.create_space("MusicTest", "music", "desc", 1, 2)
|
||||
{:ok, space} = BookingSystem.create_space("MusicTest", "music", "desc", 1)
|
||||
|
||||
%{space: space}
|
||||
end
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ defmodule SpazioSolazzoWeb.PageLiveTest do
|
|||
|
||||
setup do
|
||||
for {name, slug} <- [{"Coworking", "coworking"}, {"Meeting", "meeting"}, {"Music", "music"}] do
|
||||
BookingSystem.create_space!(name, slug, "desc", 10, 12)
|
||||
BookingSystem.create_space!(name, slug, "desc", 10)
|
||||
end
|
||||
|
||||
:ok
|
||||
|
|
|
|||
|
|
@ -202,8 +202,7 @@ defmodule SpazioSolazzoWeb.ProfileLiveTest do
|
|||
"Test Space #{unique_id}",
|
||||
"test-space-#{unique_id}",
|
||||
"Test description",
|
||||
10,
|
||||
12
|
||||
10
|
||||
)
|
||||
|
||||
{:ok, time_slot} =
|
||||
|
|
|
|||
Loading…
Reference in a new issue