-
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): [PPT-1835] booked desks showing up as available (#340)
- Loading branch information
Showing
2 changed files
with
87 additions
and
29 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 |
---|---|---|
|
@@ -39,34 +39,6 @@ describe Bookings do | |
body.size.should eq(1) | ||
end | ||
|
||
it "should return a list of asset ids" do | ||
tenant = get_tenant | ||
|
||
booking1 = BookingsHelper.create_booking(tenant.id.not_nil!) | ||
sleep 1 | ||
booking2 = BookingsHelper.create_booking(tenant.id.not_nil!) | ||
|
||
starting = 5.minutes.from_now.to_unix | ||
ending = 90.minutes.from_now.to_unix | ||
route = "#{BOOKINGS_BASE}/booked?period_start=#{starting}&period_end=#{ending}&user=#{booking1.user_email}&type=desk" | ||
body = JSON.parse(client.get(route, headers: headers).body).as_a | ||
|
||
body.first.should eq(booking1.asset_ids.first) | ||
|
||
# filter by zones | ||
zones1 = booking1.zones.not_nil! | ||
zones_string = "#{zones1.first},#{booking2.zones.not_nil!.last}" | ||
route = "#{BOOKINGS_BASE}/booked?period_start=#{starting}&period_end=#{ending}&type=desk&zones=#{zones_string}" | ||
|
||
body = JSON.parse(client.get(route, headers: headers).body).as_a | ||
body.map(&.as_s).should eq booking1.asset_ids.concat(booking2.asset_ids).uniq! | ||
|
||
# More filters by zones | ||
route = "#{BOOKINGS_BASE}/booked?period_start=#{starting}&period_end=#{ending}&type=desk&zones=#{zones1.first}" | ||
body = JSON.parse(client.get(route, headers: headers).body).as_a | ||
body.first.in?(booking1.asset_ids.concat(booking2.asset_ids).uniq!).should be_true | ||
end | ||
|
||
it "should supports pagination on list of bookings request" do | ||
tenant = get_tenant | ||
|
||
|
@@ -542,6 +514,92 @@ describe Bookings do | |
end | ||
end | ||
|
||
describe "#booked" do | ||
it "should return a list of asset ids" do | ||
tenant = get_tenant | ||
|
||
booking1 = BookingsHelper.create_booking(tenant.id.not_nil!) | ||
sleep 1 | ||
booking2 = BookingsHelper.create_booking(tenant.id.not_nil!) | ||
|
||
starting = 5.minutes.from_now.to_unix | ||
ending = 90.minutes.from_now.to_unix | ||
route = "#{BOOKINGS_BASE}/booked?period_start=#{starting}&period_end=#{ending}&user=#{booking1.user_email}&type=desk" | ||
body = JSON.parse(client.get(route, headers: headers).body).as_a | ||
|
||
body.first.should eq(booking1.asset_ids.first) | ||
|
||
# filter by zones | ||
zones1 = booking1.zones.not_nil! | ||
zones_string = "#{zones1.first},#{booking2.zones.not_nil!.last}" | ||
route = "#{BOOKINGS_BASE}/booked?period_start=#{starting}&period_end=#{ending}&type=desk&zones=#{zones_string}" | ||
|
||
body = JSON.parse(client.get(route, headers: headers).body).as_a | ||
body.map(&.as_s).should eq booking1.asset_ids.concat(booking2.asset_ids).uniq! | ||
|
||
# More filters by zones | ||
route = "#{BOOKINGS_BASE}/booked?period_start=#{starting}&period_end=#{ending}&type=desk&zones=#{zones1.first}" | ||
body = JSON.parse(client.get(route, headers: headers).body).as_a | ||
body.first.in?(booking1.asset_ids.concat(booking2.asset_ids).uniq!).should be_true | ||
end | ||
|
||
it "should return a list of asset ids (including checked in)" do | ||
tenant_id = get_tenant.id.not_nil! | ||
|
||
starting = Time.utc.to_unix | ||
ending = 90.minutes.from_now.to_unix | ||
|
||
booking1 = BookingsHelper.create_booking( | ||
tenant_id: tenant_id, | ||
booking_start: 1.minutes.from_now.to_unix, | ||
booking_end: 30.minutes.from_now.to_unix, asset_id: "desk-1") | ||
|
||
client.post("#{BOOKINGS_BASE}/#{booking1.id}/check_in", headers: headers) | ||
|
||
booking2 = BookingsHelper.create_booking( | ||
tenant_id: tenant_id, | ||
booking_start: 5.minutes.from_now.to_unix, | ||
booking_end: 35.minutes.from_now.to_unix, asset_id: "desk-2") | ||
|
||
sleep 1 | ||
|
||
zones_string = "#{booking1.zones.not_nil!.first},#{booking2.zones.not_nil!.first}" | ||
route = "#{BOOKINGS_BASE}/booked?period_start=#{starting}&period_end=#{ending}&type=desk&zones=#{zones_string}" | ||
asset_ids = Array(String).from_json client.get(route, headers: headers).body | ||
asset_ids.should contain("desk-1") | ||
asset_ids.should contain("desk-2") | ||
end | ||
|
||
it "should return a list of asset ids (excluding checked out and deleted)", focus: true do | ||
tenant_id = get_tenant.id.not_nil! | ||
|
||
starting = Time.utc.to_unix | ||
ending = 90.minutes.from_now.to_unix | ||
|
||
booking1 = BookingsHelper.create_booking( | ||
tenant_id: tenant_id, | ||
booking_start: 1.minutes.from_now.to_unix, | ||
booking_end: 30.minutes.from_now.to_unix, asset_id: "desk-1") | ||
|
||
client.post("#{BOOKINGS_BASE}/#{booking1.id}/check_in", headers: headers) | ||
client.post("#{BOOKINGS_BASE}/#{booking1.id}/check_in?state=false", headers: headers) | ||
|
||
booking2 = BookingsHelper.create_booking( | ||
tenant_id: tenant_id, | ||
booking_start: 5.minutes.from_now.to_unix, | ||
booking_end: 35.minutes.from_now.to_unix, asset_id: "desk-2") | ||
client.delete("#{BOOKINGS_BASE}/#{booking2.id}", headers: headers) | ||
|
||
sleep 1 | ||
|
||
zones_string = "#{booking1.zones.not_nil!.first},#{booking2.zones.not_nil!.first}" | ||
route = "#{BOOKINGS_BASE}/booked?period_start=#{starting}&period_end=#{ending}&type=desk&zones=#{zones_string}" | ||
asset_ids = Array(String).from_json client.get(route, headers: headers).body | ||
asset_ids.should_not contain("desk-1") | ||
asset_ids.should_not contain("desk-2") | ||
end | ||
end | ||
|
||
it "should include bookins made on behalf of other users when include_booked_by=true" do | ||
tenant = get_tenant | ||
booking1 = BookingsHelper.create_booking(tenant_id: tenant.id.not_nil!, user_email: "[email protected]") | ||
|
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