@@ -572,4 +572,47 @@ module PlaceOS::Model
572572 child_booking.rejected.should eq(true )
573573 child_booking.rejected_at.should eq(rejected_at_time)
574574 end
575+
576+ it " include parent booking in json" do
577+ tenant_id = Generator .tenant.id
578+ user_one_email = " one@example.com"
579+
580+ # parent booking
581+ parent_booking = Booking .new(
582+ booking_type: " room" ,
583+ asset_ids: [" room-1" ],
584+ booking_start: 1 .hour.from_now.to_unix,
585+ booking_end: 2 .hours.from_now.to_unix,
586+ user_email: PlaceOS ::Model ::Email .new(user_one_email),
587+ user_name: " One" ,
588+ booked_by_email: PlaceOS ::Model ::Email .new(user_one_email),
589+ booked_by_name: " One" ,
590+ tenant_id: tenant_id,
591+ booked_by_id: " user-1" ,
592+ history: [] of Booking ::History
593+ ).save!
594+
595+ # child booking
596+ child_booking = Booking .new(
597+ booking_type: " asset" ,
598+ asset_ids: [" laptop-1" ],
599+ booking_start: 1 .hour.from_now.to_unix,
600+ booking_end: 2 .hours.from_now.to_unix,
601+ user_email: PlaceOS ::Model ::Email .new(user_one_email),
602+ user_name: " One" ,
603+ booked_by_email: PlaceOS ::Model ::Email .new(user_one_email),
604+ booked_by_name: " One" ,
605+ tenant_id: tenant_id,
606+ booked_by_id: " user-1" ,
607+ history: [] of Booking ::History ,
608+ parent_id: parent_booking.id
609+ ).save!
610+
611+ child_booking = Booking .find(child_booking.id)
612+ child_booking = Booking .hydrate_parents([child_booking])[0 ]
613+ child_booking_json = JSON .parse(child_booking.to_json).as_h
614+ child_booking_json[" parent_id" ].should eq(parent_booking.id)
615+ child_booking_json[" linked_parent_booking" ].as_h.should_not be_nil
616+ child_booking_json[" linked_parent_booking" ].as_h[" id" ].should eq(parent_booking.id)
617+ end
575618end
0 commit comments