diff --git a/app/Http/Controllers/Api/V1/ServiceRoomController.php b/app/Http/Controllers/Api/V1/ServiceRoomController.php index b71095c..b63f4ec 100644 --- a/app/Http/Controllers/Api/V1/ServiceRoomController.php +++ b/app/Http/Controllers/Api/V1/ServiceRoomController.php @@ -214,7 +214,10 @@ class ServiceRoomController extends Controller if (isset($validated['settings'])) { $type = $this->resolveType(array_merge(['type' => $room->type], $validated)); - $update['settings'] = $this->mergeSettingsForType($type, $validated['settings']); + $update['settings'] = $this->mergeSettingsForType( + $type, + array_merge($room->settings ?? [], $validated['settings']), + ); } $room = $this->rooms->update($room, $update, $host); diff --git a/app/Services/Integrations/EventsLinkService.php b/app/Services/Integrations/EventsLinkService.php index 938492a..b0a240b 100644 --- a/app/Services/Integrations/EventsLinkService.php +++ b/app/Services/Integrations/EventsLinkService.php @@ -37,7 +37,7 @@ class EventsLinkService 'virtual_session_id' => $virtualSessionId, ]); - $room->update([ + $updates = [ 'source' => [ 'app' => 'events', 'entity_type' => 'virtual_session', @@ -47,7 +47,17 @@ class EventsLinkService 'registration_url' => (string) ($result['registration_url'] ?? ''), 'short_code' => (string) ($result['short_code'] ?? ''), ], - ]); + ]; + + $programme = $result['programme_snapshot'] ?? null; + if (is_array($programme) && ! empty($programme['days'])) { + $updates['settings'] = array_merge($room->settings ?? [], [ + 'programme_snapshot' => $programme, + 'linked_programme_items' => (array) ($result['linked_programme_items'] ?? []), + ]); + } + + $room->update($updates); return $room->fresh(); } diff --git a/tests/Feature/EventsLinkServiceTest.php b/tests/Feature/EventsLinkServiceTest.php new file mode 100644 index 0000000..85c7954 --- /dev/null +++ b/tests/Feature/EventsLinkServiceTest.php @@ -0,0 +1,101 @@ +user = User::create([ + 'public_id' => 'test-user-events-link', + 'name' => 'Test User', + 'email' => 'events-link@example.com', + ]); + + $this->organization = Organization::create([ + 'owner_ref' => $this->user->public_id, + 'name' => 'Test Org', + 'slug' => 'test-org', + 'timezone' => 'UTC', + 'settings' => ['onboarded' => true], + ]); + + Member::create([ + 'owner_ref' => $this->user->public_id, + 'organization_id' => $this->organization->id, + 'user_ref' => $this->user->public_id, + 'role' => 'owner', + ]); + + config([ + 'meet.events_api_url' => 'https://events.test/api/service/v1', + 'meet.events_api_key' => 'test-events-key', + ]); + } + + public function test_link_stores_programme_snapshot_on_room_from_events_response(): void + { + Http::fake([ + 'https://events.test/api/service/v1/events/42/link-room' => Http::response([ + 'event' => [ + 'id' => 42, + 'title' => 'Summit', + 'entity_id' => 'vs-abc', + 'registration_url' => 'https://events.test/e/summit', + 'short_code' => 'summit', + 'programme_snapshot' => [ + 'title' => 'Summit programme', + 'days' => [ + [ + 'label' => 'Day 1', + 'items' => [ + ['time' => '09:00', 'title' => 'Opening keynote', 'host' => 'Alex'], + ], + ], + ], + ], + 'linked_programme_items' => [ + ['time' => '09:00', 'title' => 'Opening keynote', 'host' => 'Alex'], + ], + ], + ], 200), + ]); + + $room = Room::create([ + 'owner_ref' => $this->user->public_id, + 'organization_id' => $this->organization->id, + 'host_user_ref' => $this->user->public_id, + 'title' => 'Summit keynote', + 'type' => 'town_hall', + 'status' => 'scheduled', + 'scheduled_at' => now()->addDay(), + 'timezone' => 'UTC', + 'settings' => config('meet.default_settings'), + ]); + + app(EventsLinkService::class)->link($room, $this->user, 42); + + $room->refresh(); + + $this->assertSame('events', $room->source['app'] ?? null); + $this->assertSame('Summit programme', $room->setting('programme_snapshot')['title'] ?? null); + $this->assertSame('Opening keynote', $room->setting('linked_programme_items')[0]['title'] ?? null); + } +}