Files
old-holivud2/spec/models/zoom_meeting_spec.rb
2020-06-03 07:24:01 +02:00

94 lines
2.7 KiB
Ruby

require 'rails_helper'
require 'zoom_gateway'
RSpec.describe ZoomMeeting, type: :model do
let(:zoom_meeting) { build(:zoom_meeting, api_meeting_id: nil) }
let(:meeting_dictionary) { {"start_url" => "https://start_url", "join_url" => "https://join_url"} }
before :all do
WebMock.disable_net_connect!(allow_localhost: true)
end
before :each do
allow_any_instance_of(ZoomGateway).to receive(:find_meeting).and_return(meeting_dictionary)
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")
end
describe 'associations' do
it { is_expected.to belong_to(:zoom_user) }
it { is_expected.to belong_to(:project).optional(true) }
end
describe 'after_create' do
it 'should assign api meeting id' do
expect {
zoom_meeting.save
}.to change { zoom_meeting.api_meeting_id }
end
end
describe ".meeting" do
it 'returns meeting dictionary' do
expect(zoom_meeting.meeting).to eq(meeting_dictionary)
end
it 'recreates meeting if the current on is expired' do
# set the meeting id
zoom_meeting.save
# simulate expiration
allow_any_instance_of(ZoomGateway).to receive(:find_meeting).with("meeting_id").and_raise(ZoomGateway::MeetingExpired)
allow_any_instance_of(ZoomGateway).to receive(:find_meeting).with("new_meeting_id").and_return(meeting_dictionary)
allow_any_instance_of(ZoomGateway).to receive(:create_meeting).and_return("new_meeting_id")
expect {
zoom_meeting.meeting
}.to change { zoom_meeting.api_meeting_id }
end
end
describe '.meeting_url' do
before do
zoom_meeting.api_meeting_id = "meeting_id"
zoom_meeting.save
end
context 'meeting is already started' do
it 'returns join_url' do
zoom_meeting.started!
expect(zoom_meeting.meeting_url).to eq('https://join_url')
end
end
context 'meeting is not started yet' do
it 'return start_url' do
zoom_meeting.created!
expect(zoom_meeting.meeting_url).to eq('https://start_url')
end
end
context 'meeting is ended' do
it 'returns start_url' do
zoom_meeting.ended!
expect(zoom_meeting.meeting_url).to eq('https://start_url')
end
end
end
describe ".join_url" do
it "delegates to the meeting hash" do
expect(zoom_meeting.meeting).to receive(:[]).with("join_url")
zoom_meeting.join_url
end
end
describe ".start_url" do
it "delegates to the meeting hash" do
expect(zoom_meeting.meeting).to receive(:[]).with("start_url")
zoom_meeting.start_url
end
end
end