This repository has been archived on 2021-10-24. You can view files and clone it, but cannot push or open issues or pull requests.
greenlight/spec/models/room_spec.rb

139 lines
3.8 KiB
Ruby
Raw Normal View History

2018-06-26 10:29:46 -04:00
# frozen_string_literal: true
2018-05-18 11:51:03 -04:00
require "rails_helper"
2018-06-18 14:55:01 -04:00
require 'bigbluebutton_api'
2018-05-18 11:51:03 -04:00
describe Room, type: :model do
2018-06-26 10:29:46 -04:00
before do
2018-06-18 14:55:01 -04:00
@user = create(:user)
@room = @user.main_room
2018-06-26 10:29:46 -04:00
end
2018-05-18 11:51:03 -04:00
2018-06-15 14:41:07 -04:00
context 'validations' do
2018-06-18 14:55:01 -04:00
it { should validate_presence_of(:name) }
2018-06-15 14:41:07 -04:00
end
context 'associations' do
2018-06-18 14:55:01 -04:00
it { should belong_to(:owner).class_name("User").with_foreign_key("user_id") }
2018-06-15 14:41:07 -04:00
end
2018-05-18 11:51:03 -04:00
2018-06-15 14:41:07 -04:00
context '#setup' do
it 'creates random uid and bbb_id' do
expect(@room.uid).to_not be_nil
expect(@room.bbb_id).to_not be_nil
2018-05-18 11:51:03 -04:00
end
2018-06-15 14:41:07 -04:00
end
2018-05-18 11:51:03 -04:00
2018-06-15 14:41:07 -04:00
context "#to_param" do
it "uses uid as the default identifier for routes" do
expect(@room.to_param).to eq(@room.uid)
2018-05-18 11:51:03 -04:00
end
end
2018-06-15 14:41:07 -04:00
2018-06-18 14:55:01 -04:00
context "#invite_path" do
it "should have correct invite path" do
expect(@room.invite_path).to eq("/#{@room.uid}")
end
end
context "#owned_by?" do
it "should return true for correct owner" do
expect(@room.owned_by?(@user)).to be true
end
it "should return false for incorrect owner" do
expect(@room.owned_by?(create(:user))).to be false
end
end
2018-06-26 10:29:46 -04:00
context "#running?" do
2018-06-18 14:55:01 -04:00
it "should return false when not running" do
2018-06-26 10:29:46 -04:00
expect(@room.running?).to be false
2018-06-18 14:55:01 -04:00
end
it "should return true when running" do
allow_any_instance_of(BigBlueButton::BigBlueButtonApi).to receive(:is_meeting_running?).and_return(true)
2018-06-26 10:29:46 -04:00
expect(@room.running?).to be true
2018-06-18 14:55:01 -04:00
end
end
context "#start_session" do
it "should update latest session info" do
allow_any_instance_of(BigBlueButton::BigBlueButtonApi).to receive(:create_meeting).and_return(true)
2018-06-26 10:29:46 -04:00
expect do
2018-06-18 14:55:01 -04:00
@room.start_session
2018-06-26 10:29:46 -04:00
end.to change { @room.sessions }.by(1)
2018-06-18 14:55:01 -04:00
expect(@room.last_session.utc.to_i).to eq(Time.now.to_i)
end
end
context "#join_path" do
it "should return correct join URL for user" do
2018-06-26 10:29:46 -04:00
allow_any_instance_of(BigBlueButton::BigBlueButtonApi).to receive(:get_meeting_info).and_return(
2018-06-18 14:55:01 -04:00
attendeePW: "testpass"
2018-06-26 10:29:46 -04:00
)
2018-06-18 14:55:01 -04:00
endpoint = Rails.configuration.bigbluebutton_endpoint
secret = Rails.configuration.bigbluebutton_secret
fullname = "fullName=Example"
2018-06-26 10:29:46 -04:00
html = Rails.configuration.html5_enabled ? "&joinViaHtml5=true" : ""
meeting_id = "&meetingID=#{@room.bbb_id}"
2018-06-18 14:55:01 -04:00
password = "&password=testpass"
2018-06-26 10:29:46 -04:00
query = fullname + html + meeting_id + password
2018-06-18 14:55:01 -04:00
checksum_string = "join#{query + secret}"
checksum = OpenSSL::Digest.digest('sha1', checksum_string).unpack("H*").first
2018-06-26 10:29:46 -04:00
expect(@room.join_path("Example")).to eql("#{endpoint}join?#{query}&checksum=#{checksum}")
2018-06-18 14:55:01 -04:00
end
end
context "#notify_waiting" do
it "should broadcast to waiting channel with started action" do
2018-06-26 10:29:46 -04:00
expect do
2018-06-18 14:55:01 -04:00
@room.notify_waiting
2018-06-26 10:29:46 -04:00
end.to have_broadcasted_to("#{@room.uid}_waiting_channel").with(a_hash_including(action: "started"))
2018-06-18 14:55:01 -04:00
end
end
context "#participants" do
it "should link participants to accounts" do
user1 = create(:user)
user2 = create(:user)
2018-06-26 10:29:46 -04:00
allow_any_instance_of(BigBlueButton::BigBlueButtonApi).to receive(:get_meeting_info).and_return(
2018-06-18 14:55:01 -04:00
attendees: [
2018-06-26 10:29:46 -04:00
{ userID: user1.uid, fullName: user1.name },
{ userID: "non-matching-uid", fullName: "Guest User" },
{ userID: user2.uid, fullName: user2.name },
],
)
2018-06-18 14:55:01 -04:00
expect(@room.participants).to contain_exactly(user1, nil, user2)
end
end
context "#recordings" do
it "should properly find meeting recordings" do
2018-06-26 10:29:46 -04:00
allow_any_instance_of(BigBlueButton::BigBlueButtonApi).to receive(:get_recordings).and_return(
2018-06-18 14:55:01 -04:00
recordings: [
{
name: "Example",
playback: {
2018-06-26 10:29:46 -04:00
format: "presentation",
},
2018-06-18 14:55:01 -04:00
},
2018-06-26 10:29:46 -04:00
],
)
2018-06-18 14:55:01 -04:00
2018-06-26 10:29:46 -04:00
expect(@room.recordings).to contain_exactly(
2018-06-18 14:55:01 -04:00
name: "Example",
2018-06-26 10:29:46 -04:00
playbacks: %w(presentation),
)
2018-06-18 14:55:01 -04:00
end
end
2018-06-15 14:41:07 -04:00
end