Skip to content

Commit

Permalink
fix(bookings): prevent start and end times being the same
Browse files Browse the repository at this point in the history
  • Loading branch information
stakach committed Feb 29, 2024
1 parent 59c72a1 commit 5b0ec00
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
22 changes: 22 additions & 0 deletions spec/booking_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -269,4 +269,26 @@ module PlaceOS::Model
local.save.should be_false
local.persisted?.should be_false
end

it "rejects a booking with the same start and end times" do
user_email = "[email protected]"
tenant_id = Generator.tenant.id
start_time = 1.hour.from_now.to_unix

booking = Booking.new(
booking_type: "desk",
asset_ids: ["desk2"],
booking_start: start_time,
booking_end: start_time,
user_email: PlaceOS::Model::Email.new(user_email),
user_name: "Steve",
booked_by_email: PlaceOS::Model::Email.new(user_email),
booked_by_name: "Steve",
tenant_id: tenant_id,
booked_by_id: "user-1234",
history: [] of Booking::History
)
booking.save.should be_false
booking.persisted?.should be_false
end
end
2 changes: 1 addition & 1 deletion src/placeos-models/booking.cr
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ module PlaceOS::Model

validate :booking_start, "must not clash with an existing booking", ->(this : self) { !this.clashing? }
validate :asset_ids, "must be unique", ->(this : self) { this.unique_ids? }
validate :booking_end, "must be after booking_start", ->(this : self) { this.booking_end >= this.booking_start }
validate :booking_end, "must be after booking_start", ->(this : self) { this.booking_end > this.booking_start }

before_save do
@user_id ||= booked_by_id
Expand Down

0 comments on commit 5b0ec00

Please sign in to comment.