-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(bookings): details specs for desired behaviour [PROJ-636] (#252)
- Loading branch information
Showing
2 changed files
with
218 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,4 +32,216 @@ module PlaceOS::Model | |
query_check.attendees.to_a.size.should eq 0 | ||
end | ||
end | ||
|
||
it "successfully saves a booking" do | ||
user_email = "[email protected]" | ||
tenant_id = Generator.tenant.id | ||
|
||
# classic | ||
booking = Booking.new( | ||
booking_type: "desk", | ||
asset_id: "desk1", | ||
booking_start: 1.hour.from_now.to_unix, | ||
booking_end: 2.hours.from_now.to_unix, | ||
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 | ||
).save! | ||
booking.asset_ids.should eq ["desk1"] | ||
booking.persisted?.should be_true | ||
|
||
# new | ||
booking = Booking.new( | ||
booking_type: "desk", | ||
asset_ids: ["desk2"], | ||
booking_start: 1.hour.from_now.to_unix, | ||
booking_end: 2.hours.from_now.to_unix, | ||
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 | ||
).save! | ||
booking.asset_id.should eq "desk2" | ||
booking.persisted?.should be_true | ||
|
||
# combined | ||
booking = Booking.new( | ||
booking_type: "desk", | ||
asset_id: "desk3", | ||
asset_ids: ["desk3", "desk4"], | ||
booking_start: 1.hour.from_now.to_unix, | ||
booking_end: 2.hours.from_now.to_unix, | ||
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 | ||
).save! | ||
booking.asset_ids.should eq ["desk3", "desk4"] | ||
booking.persisted?.should be_true | ||
|
||
# mismatch 1 | ||
booking = Booking.new( | ||
booking_type: "desk", | ||
asset_id: "desk5", | ||
asset_ids: ["desk6", "desk7"], | ||
booking_start: 1.hour.from_now.to_unix, | ||
booking_end: 2.hours.from_now.to_unix, | ||
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 | ||
).save! | ||
booking.asset_ids.should eq ["desk6", "desk7"] | ||
booking.asset_id.should eq "desk6" | ||
booking.persisted?.should be_true | ||
|
||
# mismatch 2 | ||
booking = Booking.new( | ||
booking_type: "desk", | ||
asset_ids: ["desk8"], | ||
booking_start: 1.hour.from_now.to_unix, | ||
booking_end: 2.hours.from_now.to_unix, | ||
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 | ||
).save! | ||
booking.asset_ids.should eq ["desk8"] | ||
booking.asset_id.should eq "desk8" | ||
booking.persisted?.should be_true | ||
|
||
booking.asset_id = "desk9" | ||
booking.save! | ||
booking.asset_ids.should eq ["desk9"] | ||
booking.asset_id.should eq "desk9" | ||
booking.persisted?.should be_true | ||
|
||
booking.asset_id = "desk10" | ||
booking.asset_ids = ["desk11"] | ||
booking.save! | ||
booking.asset_ids.should eq ["desk11"] | ||
booking.asset_id.should eq "desk11" | ||
booking.persisted?.should be_true | ||
end | ||
|
||
it "rejects a booking that clashes" do | ||
user_email = "[email protected]" | ||
tenant_id = Generator.tenant.id | ||
|
||
saved = Booking.new( | ||
booking_type: "desk", | ||
asset_id: "desk1", | ||
booking_start: 1.hour.from_now.to_unix, | ||
booking_end: 2.hours.from_now.to_unix, | ||
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 | ||
).save! | ||
|
||
# new | ||
not_saved = Booking.new( | ||
booking_type: "desk", | ||
asset_ids: ["desk1"], | ||
booking_start: 1.hour.from_now.to_unix, | ||
booking_end: 2.hours.from_now.to_unix, | ||
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 | ||
) | ||
not_saved.save | ||
|
||
saved.persisted?.should be_true | ||
not_saved.persisted?.should be_false | ||
end | ||
|
||
it "rejects a concurrent booking that clashes" do | ||
user_email = "[email protected]" | ||
tenant_id = Generator.tenant.id | ||
|
||
wait = Channel(Booking).new | ||
spawn do | ||
booking = Booking.new( | ||
booking_type: "desk", | ||
asset_id: "desk1", | ||
booking_start: 1.hour.from_now.to_unix, | ||
booking_end: 2.hours.from_now.to_unix, | ||
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 | ||
wait.send booking | ||
end | ||
|
||
local = Booking.new( | ||
booking_type: "desk", | ||
asset_ids: ["desk1"], | ||
booking_start: 1.hour.from_now.to_unix, | ||
booking_end: 2.hours.from_now.to_unix, | ||
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 | ||
) | ||
local.save | ||
|
||
spawned = wait.receive | ||
saved = 0 | ||
saved += 1 if local.persisted? | ||
saved += 1 if spawned.persisted? | ||
|
||
saved.should eq 1 | ||
end | ||
|
||
it "rejects a booking with multiple same asset ids" do | ||
user_email = "[email protected]" | ||
tenant_id = Generator.tenant.id | ||
|
||
local = Booking.new( | ||
booking_type: "desk", | ||
asset_ids: ["desk1", "desk2", "desk1"], | ||
booking_start: 1.hour.from_now.to_unix, | ||
booking_end: 2.hours.from_now.to_unix, | ||
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 | ||
) | ||
local.save.should be_false | ||
local.persisted?.should be_false | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters