diff --git a/spec/booking_spec.cr b/spec/booking_spec.cr index 09917c7d..566d443b 100644 --- a/spec/booking_spec.cr +++ b/spec/booking_spec.cr @@ -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 = "steve@place.tech" + 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 diff --git a/src/placeos-models/booking.cr b/src/placeos-models/booking.cr index b6383d3f..a7f4e686 100644 --- a/src/placeos-models/booking.cr +++ b/src/placeos-models/booking.cr @@ -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