From b4a584ce6f68a5ceaedf474724344047029a25ae Mon Sep 17 00:00:00 2001 From: Mia Bennett Date: Tue, 18 Jan 2022 11:23:08 +0930 Subject: [PATCH] test(bookings): returns query for current user when no user or zone is specified (#144) --- spec/controllers/bookings_spec.cr | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/spec/controllers/bookings_spec.cr b/spec/controllers/bookings_spec.cr index f2c55b16..802c1722 100644 --- a/spec/controllers/bookings_spec.cr +++ b/spec/controllers/bookings_spec.cr @@ -80,6 +80,20 @@ describe Bookings do booking_user_ids = body.map { |r| r["user_id"] } booking_user_ids.should eq(["jon@example.com"]) end + + it "should return a list of bookings filtered current user when no zones or user is specified" do + tenant = Tenant.query.find! { domain == "toby.staff-api.dev" } + BookingsHelper.create_booking(tenant_id: tenant.id, user_id: "toby@redant.com.au") + BookingsHelper.create_booking(tenant.id) + + starting = 5.minutes.from_now.to_unix + ending = 40.minutes.from_now.to_unix + # Since we are using Toby's token to login, user=current means Toby + route = "#{BOOKINGS_BASE}?period_start=#{starting}&period_end=#{ending}&type=desk" + body = Context(Bookings, JSON::Any).response("GET", route, headers: Mock::Headers.office365_guest, &.index)[1].as_a + booking_user_ids = body.map { |r| r["user_id"] } + booking_user_ids.should eq(["toby@redant.com.au"]) + end end it "#show should find booking" do