diff --git a/app/Services/Meet/EventMeetSyncService.php b/app/Services/Meet/EventMeetSyncService.php index e7b8004..9e9f0fe 100644 --- a/app/Services/Meet/EventMeetSyncService.php +++ b/app/Services/Meet/EventMeetSyncService.php @@ -78,23 +78,29 @@ class EventMeetSyncService $settings['panel_discussions'] = true; } + $roomPayload = [ + 'title' => $title, + 'description' => trim((string) ($content['description'] ?? '')) ?: null, + 'type' => $roomType, + 'scheduled_at' => $scheduledAt, + 'duration_minutes' => max(15, (int) ($session['duration_minutes'] ?? 60)), + 'timezone' => config('app.timezone', 'UTC'), + 'settings' => $settings, + 'invite_emails' => $inviteEmails, + 'source' => [ + 'app' => 'events', + 'entity_type' => 'virtual_session', + 'entity_id' => $sessionId, + 'event_id' => (string) $event->id, + ], + ]; + + $existingRoomUuid = trim((string) ($session['meet_room_uuid'] ?? '')); + try { - $result = $client->upsertRoom([ - 'title' => $title, - 'description' => trim((string) ($content['description'] ?? '')) ?: null, - 'type' => $roomType, - 'scheduled_at' => $scheduledAt, - 'duration_minutes' => max(15, (int) ($session['duration_minutes'] ?? 60)), - 'timezone' => config('app.timezone', 'UTC'), - 'settings' => $settings, - 'invite_emails' => $inviteEmails, - 'source' => [ - 'app' => 'events', - 'entity_type' => 'virtual_session', - 'entity_id' => $sessionId, - 'event_id' => (string) $event->id, - ], - ]); + $result = $existingRoomUuid !== '' + ? $client->updateRoom($existingRoomUuid, $roomPayload) + : $client->upsertRoom($roomPayload); } catch (\Throwable $e) { Log::warning('Events Meet sync failed', [ 'event_id' => $event->id, diff --git a/tests/Feature/ServiceMeetLinkTest.php b/tests/Feature/ServiceMeetLinkTest.php index 95b4824..5460a0f 100644 --- a/tests/Feature/ServiceMeetLinkTest.php +++ b/tests/Feature/ServiceMeetLinkTest.php @@ -26,6 +26,10 @@ class ServiceMeetLinkTest extends TestCase 'room' => ['uuid' => 'room-uuid-123'], 'join_url' => 'https://meet.ladill.com/r/room-uuid-123', ], 201), + config('meet.url').'/rooms/*' => Http::response([ + 'room' => ['uuid' => 'room-uuid-123'], + 'join_url' => 'https://meet.ladill.com/r/room-uuid-123', + ], 200), ]); $this->owner = User::factory()->create(['public_id' => 'usr_meet_link']); @@ -87,4 +91,71 @@ class ServiceMeetLinkTest extends TestCase $sessions = $event->fresh()->content()['virtual_sessions']; $this->assertSame('room-uuid-123', $sessions[0]['meet_room_uuid'] ?? null); } + + public function test_link_room_patches_existing_meet_room_with_programme_snapshot(): void + { + $programme = QrCode::create([ + 'user_id' => $this->owner->id, + 'short_code' => 'prog-link-1', + 'type' => QrCode::TYPE_ITINERARY, + 'label' => 'Summit programme', + 'payload' => [ + 'content' => [ + 'title' => 'Summit programme', + 'days' => [ + [ + 'label' => 'Day 1', + 'items' => [ + ['ref' => 'item-1', 'time' => '09:00', 'title' => 'Opening keynote', 'host' => 'Alex'], + ], + ], + ], + ], + 'style' => [], + ], + 'is_active' => true, + ]); + + $event = QrCode::create([ + 'user_id' => $this->owner->id, + 'short_code' => 'evt-prog-link', + 'type' => QrCode::TYPE_EVENT, + 'label' => 'Summit', + 'payload' => [ + 'content' => [ + 'title' => 'Summit', + 'format' => 'virtual', + 'programme_qr_id' => $programme->id, + 'virtual_sessions' => [], + ], + 'style' => [], + ], + 'is_active' => true, + ]); + + Http::fake([ + config('meet.url').'/rooms/existing-room-uuid' => Http::response([ + 'room' => ['uuid' => 'existing-room-uuid'], + 'join_url' => 'https://meet.ladill.com/r/existing-room-uuid', + ], 200), + ]); + + $this->withToken('test-meet-key') + ->postJson('/api/service/v1/events/'.$event->id.'/link-room', [ + 'owner_ref' => $this->owner->public_id, + 'meet_room_uuid' => 'existing-room-uuid', + 'meet_room_type' => 'town_hall', + 'join_url' => 'https://meet.ladill.com/r/existing-room-uuid', + 'title' => 'Opening keynote', + ]) + ->assertOk() + ->assertJsonPath('event.meet_room_uuid', 'existing-room-uuid'); + + Http::assertSent(function ($request) { + return $request->method() === 'PATCH' + && str_ends_with($request->url(), '/rooms/existing-room-uuid') + && ($request['settings']['programme_snapshot']['title'] ?? '') === 'Summit programme' + && ($request['settings']['programme_snapshot']['days'][0]['items'][0]['title'] ?? '') === 'Opening keynote'; + }); + } }