This commit is contained in:
Bilal
2020-07-20 14:45:11 +02:00
parent 2568383352
commit 48a25e266d

View File

@@ -4,27 +4,45 @@ RSpec.describe StreamNotificationsController, type: :controller do
render_views render_views
let!(:broadcast) { create(:broadcast, :with_stream, skip_create_callback: true, name: "Live Stream") } 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(:active_status) { { type: "video.live_stream.active", object: { id: "mux_stream" } } }
let(:disconnected_status) { {type: "video.live_stream.disconnected", 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) { { 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(:idle_status_for_unknown_broadcast) { { type: "video.live_stream.idle", object: { id: "unknown-id" } } }
let(:asset_ready) { { let(:asset_ready) do
type: "video.asset.static_renditions.ready", {
object: { id: "asset_uid" }, type: "video.asset.static_renditions.ready",
data: { object: { id: "asset_uid" },
playback_ids: [
{id: "playback_uid"}
],
static_renditions: {
files: [{name: "high.mp4"}]
}
},
stream_notification: {
data: { 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 describe "#create" do
before do before do
@@ -54,13 +72,20 @@ RSpec.describe StreamNotificationsController, type: :controller do
end end
it "creates a broadcast recording when static_renditions.ready is received in notification" do it "creates a broadcast recording when static_renditions.ready is received in notification" do
expect { expect do
post :create, params: asset_ready 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) expect(BroadcastsChannel).to have_received(:stream_recording_ready)
end 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 it "returns OK response even for non-existing broadcast" do
post :create, params: idle_status_for_unknown_broadcast post :create, params: idle_status_for_unknown_broadcast