Files
old-holivud2/spec/controllers/stream_notifications_controller_spec.rb

101 lines
3.3 KiB
Ruby
Raw Normal View History

2020-05-31 22:38:19 +02:00
require "rails_helper"
RSpec.describe StreamNotificationsController, type: :controller do
render_views
let!(:broadcast) { create(:broadcast, :with_stream, skip_create_callback: true, name: "Live Stream") }
2020-07-22 19:14:34 +00:00
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: {
playback_ids: [
{ id: "playback_uid" }
],
static_renditions: {
files: [{ name: "high.mp4" }]
}
},
stream_notification: {
data: {
live_stream_id: "mux_stream"
}
2020-05-31 22:38:19 +02:00
}
2020-07-22 19:14:34 +00:00
}
end
let(:full_live_stream_ready) do
{
type: "video.asset.ready",
object: { id: "active_asset_uid" },
2020-05-31 22:38:19 +02:00
data: {
2020-07-22 19:14:34 +00:00
playback_ids: [
{ id: "full_live_stream_playback_uid" }
]
},
stream_notification: {
data: {
live_stream_id: "mux_stream"
}
2020-05-31 22:38:19 +02:00
}
}
2020-07-22 19:14:34 +00:00
end
2020-05-31 22:38:19 +02:00
describe "#create" do
before do
allow(BroadcastsChannel).to receive(:broadcast_stream_updates).with(be_kind_of(Broadcast))
allow(BroadcastsChannel).to receive(:stream_recording_ready)
end
it "updates the broadcast when active status is received in notification" do
post :create, params: active_status
expect(broadcast.reload).to be_active
expect(BroadcastsChannel).to have_received(:broadcast_stream_updates).with(be_kind_of(Broadcast))
end
it "updates the broadcast when disconnected status is received in notification" do
post :create, params: disconnected_status
expect(broadcast.reload).to be_streamer_disconnected
expect(BroadcastsChannel).to have_received(:broadcast_stream_updates).with(be_kind_of(Broadcast))
end
it "updates the broadcast when idle status is received in notification" do
post :create, params: idle_status
expect(broadcast.reload).to be_idle
expect(BroadcastsChannel).to have_received(:broadcast_stream_updates).with(be_kind_of(Broadcast))
end
it "creates a broadcast recording when static_renditions.ready is received in notification" do
2020-07-22 19:14:34 +00:00
expect do
2020-05-31 22:38:19 +02:00
post :create, params: asset_ready
2020-07-22 19:14:34 +00:00
end.to change(BroadcastRecording, :count).by(1)
2020-05-31 22:38:19 +02:00
expect(BroadcastsChannel).to have_received(:stream_recording_ready)
end
2020-07-01 06:39:02 +02:00
2020-07-22 19:14:34 +00:00
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
2020-07-01 06:39:02 +02:00
it "returns OK response even for non-existing broadcast" do
post :create, params: idle_status_for_unknown_broadcast
expect(response).to be_successful
end
2020-05-31 22:38:19 +02:00
end
after do
# Set the callback again or it will affect other test cases where the callback is required
Broadcast.set_callback(:create, :after, :create_mux_live_stream)
end
end