forked from External/greenlight
add more model tests
This commit is contained in:
parent
5d5cfd1b7d
commit
d1b81a385f
1
Gemfile
1
Gemfile
|
@ -75,6 +75,7 @@ end
|
||||||
group :test do
|
group :test do
|
||||||
# Include Rspec and other testing utilities.
|
# Include Rspec and other testing utilities.
|
||||||
gem 'rspec-rails', '~> 3.7'
|
gem 'rspec-rails', '~> 3.7'
|
||||||
|
gem 'action-cable-testing'
|
||||||
gem 'shoulda-matchers', '~> 3.1'
|
gem 'shoulda-matchers', '~> 3.1'
|
||||||
gem 'faker'
|
gem 'faker'
|
||||||
gem "factory_bot_rails"
|
gem "factory_bot_rails"
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
GEM
|
GEM
|
||||||
remote: https://rubygems.org/
|
remote: https://rubygems.org/
|
||||||
specs:
|
specs:
|
||||||
|
action-cable-testing (0.3.1)
|
||||||
|
actioncable (~> 5.0)
|
||||||
actioncable (5.0.7)
|
actioncable (5.0.7)
|
||||||
actionpack (= 5.0.7)
|
actionpack (= 5.0.7)
|
||||||
nio4r (>= 1.2, < 3.0)
|
nio4r (>= 1.2, < 3.0)
|
||||||
|
@ -240,6 +242,7 @@ PLATFORMS
|
||||||
ruby
|
ruby
|
||||||
|
|
||||||
DEPENDENCIES
|
DEPENDENCIES
|
||||||
|
action-cable-testing
|
||||||
bcrypt (~> 3.1.7)
|
bcrypt (~> 3.1.7)
|
||||||
bigbluebutton-api-ruby
|
bigbluebutton-api-ruby
|
||||||
bootstrap (~> 4.1.1)
|
bootstrap (~> 4.1.1)
|
||||||
|
|
|
@ -135,21 +135,12 @@ class Room < ApplicationRecord
|
||||||
|
|
||||||
def update_recording(record_id, meta)
|
def update_recording(record_id, meta)
|
||||||
meta.merge!({recordID: record_id})
|
meta.merge!({recordID: record_id})
|
||||||
|
|
||||||
bbb.send_api_request("updateRecordings", meta)
|
bbb.send_api_request("updateRecordings", meta)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Deletes a recording from a room.
|
# Deletes a recording from a room.
|
||||||
def delete_recording(record_id)
|
def delete_recording(record_id)
|
||||||
res = bbb.delete_recordings(record_id)
|
bbb.delete_recordings(record_id)
|
||||||
|
|
||||||
if res[:returncode]
|
|
||||||
# Handle successful deletion.
|
|
||||||
|
|
||||||
else
|
|
||||||
# Handle unsuccessful deletion.
|
|
||||||
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
@ -2,7 +2,7 @@ development:
|
||||||
adapter: async
|
adapter: async
|
||||||
|
|
||||||
test:
|
test:
|
||||||
adapter: async
|
adapter: test
|
||||||
|
|
||||||
production:
|
production:
|
||||||
adapter: redis
|
adapter: redis
|
||||||
|
|
|
@ -10,7 +10,6 @@
|
||||||
#
|
#
|
||||||
SECRET_KEY_BASE=
|
SECRET_KEY_BASE=
|
||||||
|
|
||||||
|
|
||||||
# The endpoint and secret for your BigBlueButton server.
|
# The endpoint and secret for your BigBlueButton server.
|
||||||
# Set these if you are running GreenLight on a single BigBlueButton server.
|
# Set these if you are running GreenLight on a single BigBlueButton server.
|
||||||
# You can retrive these by running the following command on your BigBlueButton server:
|
# You can retrive these by running the following command on your BigBlueButton server:
|
||||||
|
|
|
@ -1,14 +1,19 @@
|
||||||
require "rails_helper"
|
require "rails_helper"
|
||||||
|
require 'bigbluebutton_api'
|
||||||
|
|
||||||
describe Room, type: :model do
|
describe Room, type: :model do
|
||||||
before { @room = create(:room) }
|
|
||||||
|
before {
|
||||||
|
@user = create(:user)
|
||||||
|
@room = @user.main_room
|
||||||
|
}
|
||||||
|
|
||||||
context 'validations' do
|
context 'validations' do
|
||||||
it { should validate_presence_of :name }
|
it { should validate_presence_of(:name) }
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'associations' do
|
context 'associations' do
|
||||||
it { should belong_to(:owner).class_name("User") }
|
it { should belong_to(:owner).class_name("User").with_foreign_key("user_id") }
|
||||||
end
|
end
|
||||||
|
|
||||||
context '#setup' do
|
context '#setup' do
|
||||||
|
@ -24,4 +29,113 @@ describe Room, type: :model do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
context "#is_running?" do
|
||||||
|
it "should return false when not running" do
|
||||||
|
expect(@room.is_running?).to be false
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should return true when running" do
|
||||||
|
allow_any_instance_of(BigBlueButton::BigBlueButtonApi).to receive(:is_meeting_running?).and_return(true)
|
||||||
|
expect(@room.is_running?).to be true
|
||||||
|
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)
|
||||||
|
|
||||||
|
expect{
|
||||||
|
@room.start_session
|
||||||
|
}.to change {
|
||||||
|
@room.sessions
|
||||||
|
}.by(1)
|
||||||
|
|
||||||
|
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
|
||||||
|
allow_any_instance_of(BigBlueButton::BigBlueButtonApi).to receive(:get_meeting_info).and_return({
|
||||||
|
attendeePW: "testpass"
|
||||||
|
})
|
||||||
|
|
||||||
|
endpoint = Rails.configuration.bigbluebutton_endpoint
|
||||||
|
secret = Rails.configuration.bigbluebutton_secret
|
||||||
|
fullname = "fullName=Example"
|
||||||
|
html = if Rails.configuration.html5_enabled then "&joinViaHtml5=true" else "" end
|
||||||
|
meetingID = "&meetingID=#{@room.bbb_id}"
|
||||||
|
password = "&password=testpass"
|
||||||
|
|
||||||
|
query = fullname + html + meetingID + password
|
||||||
|
checksum_string = "join#{query + secret}"
|
||||||
|
|
||||||
|
checksum = OpenSSL::Digest.digest('sha1', checksum_string).unpack("H*").first
|
||||||
|
|
||||||
|
expect(@room.join_path("Example")).to eql(
|
||||||
|
"#{endpoint}join?#{query}&checksum=#{checksum}"
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "#notify_waiting" do
|
||||||
|
it "should broadcast to waiting channel with started action" do
|
||||||
|
expect{
|
||||||
|
@room.notify_waiting
|
||||||
|
}.to have_broadcasted_to("#{@room.uid}_waiting_channel").with(a_hash_including(action: "started"))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "#participants" do
|
||||||
|
it "should link participants to accounts" do
|
||||||
|
user1 = create(:user)
|
||||||
|
user2 = create(:user)
|
||||||
|
|
||||||
|
allow_any_instance_of(BigBlueButton::BigBlueButtonApi).to receive(:get_meeting_info).and_return({
|
||||||
|
attendees: [
|
||||||
|
{userID: user1.uid, fullName: user1.name},
|
||||||
|
{userID: "non-matching-uid", fullName: "Guest User"},
|
||||||
|
{userID: user2.uid, fullName: user2.name}
|
||||||
|
]
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(@room.participants).to contain_exactly(user1, nil, user2)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "#recordings" do
|
||||||
|
it "should properly find meeting recordings" do
|
||||||
|
allow_any_instance_of(BigBlueButton::BigBlueButtonApi).to receive(:get_recordings).and_return({
|
||||||
|
recordings: [
|
||||||
|
{
|
||||||
|
name: "Example",
|
||||||
|
playback: {
|
||||||
|
format: "presentation"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
]
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(@room.recordings).to contain_exactly({
|
||||||
|
name: "Example",
|
||||||
|
playbacks: ["presentation"]
|
||||||
|
})
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -20,9 +20,13 @@ describe User, type: :model do
|
||||||
it { should_not allow_value("invalid.txt").for(:image) }
|
it { should_not allow_value("invalid.txt").for(:image) }
|
||||||
it { should allow_value("", nil).for(:image) }
|
it { should allow_value("", nil).for(:image) }
|
||||||
|
|
||||||
|
it "should convert email to downcase on save" do
|
||||||
|
user = create(:user, email: "EXAMPLE@EXAMPLE.COM")
|
||||||
|
expect(user.email).to eq("example@example.com")
|
||||||
|
end
|
||||||
|
|
||||||
context 'is greenlight account' do
|
context 'is greenlight account' do
|
||||||
before { allow(subject).to receive(:greenlight_account?).and_return(true) }
|
before { allow(subject).to receive(:greenlight_account?).and_return(true) }
|
||||||
it { should validate_presence_of(:password) }
|
|
||||||
it { should validate_length_of(:password).is_at_least(6) }
|
it { should validate_length_of(:password).is_at_least(6) }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -50,6 +54,33 @@ describe User, type: :model do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context '#from_omniauth' do
|
||||||
|
it "should create user from omniauth" do
|
||||||
|
auth = {
|
||||||
|
"uid" => "123456789",
|
||||||
|
"provider" => "twitter",
|
||||||
|
"info" => {
|
||||||
|
"name" => "Test Name",
|
||||||
|
"nickname" => "username",
|
||||||
|
"email" => "test@example.com",
|
||||||
|
"image" => "example.png"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
expect {
|
||||||
|
user = User.from_omniauth(auth)
|
||||||
|
|
||||||
|
expect(user.name).to eq("Test Name")
|
||||||
|
expect(user.email).to eq("test@example.com")
|
||||||
|
expect(user.image).to eq("example.png")
|
||||||
|
expect(user.provider).to eq("twitter")
|
||||||
|
expect(user.social_uid).to eq("123456789")
|
||||||
|
}.to change {
|
||||||
|
User.count
|
||||||
|
}.by(1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context '#first_name' do
|
context '#first_name' do
|
||||||
it 'properly finds the users first name' do
|
it 'properly finds the users first name' do
|
||||||
user = create(:user, name: "Example User")
|
user = create(:user, name: "Example User")
|
||||||
|
|
|
@ -8,6 +8,8 @@ abort("The Rails environment is running in production mode!") if Rails.env.produ
|
||||||
require 'rspec/rails'
|
require 'rspec/rails'
|
||||||
# Add additional requires below this line. Rails is not loaded until this point!
|
# Add additional requires below this line. Rails is not loaded until this point!
|
||||||
|
|
||||||
|
require "action_cable/testing/rspec"
|
||||||
|
|
||||||
# Requires supporting ruby files with custom matchers and macros, etc, in
|
# Requires supporting ruby files with custom matchers and macros, etc, in
|
||||||
# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
|
# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
|
||||||
# run as spec files by default. This means that files in spec/support that end
|
# run as spec files by default. This means that files in spec/support that end
|
||||||
|
|
Loading…
Reference in New Issue