diff --git a/spec/controllers/stream_notifications_controller_spec.rb b/spec/controllers/stream_notifications_controller_spec.rb index 8a9211f..9c57e02 100644 --- a/spec/controllers/stream_notifications_controller_spec.rb +++ b/spec/controllers/stream_notifications_controller_spec.rb @@ -4,27 +4,45 @@ RSpec.describe StreamNotificationsController, type: :controller do render_views let!(:broadcast) { create(:broadcast, :with_stream, skip_create_callback: true, name: "Live Stream") } - let(:active_status) { {type: "video.live_stream.active", object: { id: "mux_stream" }} } - let(:disconnected_status) { {type: "video.live_stream.disconnected", object: { id: "mux_stream" }} } - let(:idle_status) { {type: "video.live_stream.idle", object: { id: "mux_stream" }} } - let(:idle_status_for_unknown_broadcast) { {type: "video.live_stream.idle", object: { id: "unknown-id" }} } - let(:asset_ready) { { - type: "video.asset.static_renditions.ready", - object: { id: "asset_uid" }, - data: { - playback_ids: [ - {id: "playback_uid"} - ], - static_renditions: { - files: [{name: "high.mp4"}] - } - }, - stream_notification: { + let(:active_status) { { type: "video.live_stream.active", object: { id: "mux_stream" } } } + let(:disconnected_status) { { type: "video.live_stream.disconnected", object: { id: "mux_stream" } } } + let(:idle_status) { { type: "video.live_stream.idle", object: { id: "mux_stream" } } } + let(:idle_status_for_unknown_broadcast) { { type: "video.live_stream.idle", object: { id: "unknown-id" } } } + let(:asset_ready) do + { + type: "video.asset.static_renditions.ready", + object: { id: "asset_uid" }, data: { - live_stream_id: "mux_stream" + playback_ids: [ + { id: "playback_uid" } + ], + static_renditions: { + files: [{ name: "high.mp4" }] + } + }, + stream_notification: { + data: { + live_stream_id: "mux_stream" + } } } - } } + end + let(:full_live_stream_ready) do + { + type: "video.asset.ready", + object: { id: "active_asset_uid" }, + data: { + playback_ids: [ + { id: "full_live_stream_playback_uid" } + ] + }, + stream_notification: { + data: { + live_stream_id: "mux_stream" + } + } + } + end describe "#create" do before do @@ -54,13 +72,20 @@ RSpec.describe StreamNotificationsController, type: :controller do end it "creates a broadcast recording when static_renditions.ready is received in notification" do - expect { + expect do post :create, params: asset_ready - }.to change(BroadcastRecording, :count).by(1) + end.to change(BroadcastRecording, :count).by(1) expect(BroadcastsChannel).to have_received(:stream_recording_ready) end + it "stores full livestream playback uid and updates the broadcast" do + post :create, params: full_live_stream_ready + + expect(Broadcast.last.full_live_stream_playback_uid).to eq "full_live_stream_playback_uid" + expect(BroadcastsChannel).to have_received(:broadcast_stream_updates).with(be_kind_of(Broadcast)) + end + it "returns OK response even for non-existing broadcast" do post :create, params: idle_status_for_unknown_broadcast