require 'rails_helper' RSpec.describe ConferenceMeetingsController, type: :controller do let(:user) { create(:user) } let(:account) { user.primary_account } let(:project) { create(:project, account: user.primary_account) } let(:broadcast) { create(:broadcast, name: "Broadcast", project: project) } let(:ms_teams_broadcast) { create(:broadcast, :ms_teams_conference, project: project) } let(:unknown_option_broadcast) { create(:broadcast, project: project, conference_option: 'google') } let(:meeting_start_url) { "http://meeting_start_url" } let(:meeting_hash) { HashWithIndifferentAccess.new(start_url: meeting_start_url) } let(:user_create_response) { {"id" => "new_host_id"} } let(:roles_assign_response) { {"ids" => ["new_host_id"]} } let(:roles_list_response) { {"roles" => [{"name" => "directme-host"}]} } before :each do allow_any_instance_of(ZoomGateway).to receive(:find_meeting).and_return(meeting_hash) allow_any_instance_of(ZoomGateway).to receive(:create_meeting).and_return("meeting_id") allow_any_instance_of(ZoomGateway).to receive(:create_host).and_return("host_id") stub_mux_live_stream end describe "#show" do before { sign_in user } it "redirects to meeting start url with Zoom conference option" do get :show, params: { project_id: project.id, broadcast_id: broadcast.id } expect(response).to redirect_to(meeting_start_url) end it "redirects to the broadcast show page with alert if user is not authenticated via microsoft and tries to create MS Teams meeting" do get :show, params: { project_id: project.id, broadcast_id: ms_teams_broadcast.id } expect(response).to redirect_to project_broadcast_path(project, ms_teams_broadcast) expect(flash.alert).to eq not_authenticated_alert end it "redirects to the broadcast show page with alert if user is authenticated via microsoft and tries to create MS Teams meeting but Graph API fails to create meeting" do allow_any_instance_of(MicrosoftGraph).to receive(:create_teams_meeting).and_return(nil) get :show, params: { project_id: project.id, broadcast_id: ms_teams_broadcast.id } expect(response).to redirect_to project_broadcast_path(project, ms_teams_broadcast) expect(flash.alert).to eq failed_to_join_alert end it "redirects to the broadcast show page with alert if conference option is not reckognized" do get :show, params: { project_id: project.id, broadcast_id: unknown_option_broadcast.id } expect(response).to redirect_to project_broadcast_path(project, unknown_option_broadcast) expect(flash.alert).to eq unknown_conference_option_alert end it "redirects to meeting start url with MS Teams conference option" do new_ms_teams_meeting = JSON.parse({ joinUrl: meeting_start_url }.to_json) allow_any_instance_of(MicrosoftGraph).to receive(:create_teams_meeting).and_return(new_ms_teams_meeting) get :show, params: { project_id: project.id, broadcast_id: ms_teams_broadcast.id } expect(response).to redirect_to(meeting_start_url) end end private def not_authenticated_alert t 'conference_meetings.show.alerts.not_authenticated' end def failed_to_join_alert t 'conference_meetings.show.alerts.failed_to_join' end def unknown_conference_option_alert t 'conference_meetings.show.alerts.unknown_conference_option' end end