forked from External/greenlight
		
	Merge pull request #142 from zach-chai/more_testing
more testing and code cleanup
This commit is contained in:
		@@ -153,7 +153,7 @@ class BbbController < ApplicationController
 | 
				
			|||||||
    metadata = params.select{ |k, v| k.match(/^meta_/) }
 | 
					    metadata = params.select{ |k, v| k.match(/^meta_/) }
 | 
				
			||||||
    bbb_res = bbb_update_recordings(params[:record_id], published, metadata)
 | 
					    bbb_res = bbb_update_recordings(params[:record_id], published, metadata)
 | 
				
			||||||
    if bbb_res[:returncode]
 | 
					    if bbb_res[:returncode]
 | 
				
			||||||
      RecordingUpdatesJob.perform_later(@user.encrypted_id, params[:record_id], params[:id])
 | 
					      RecordingUpdatesJob.perform_later(@user.encrypted_id, params[:record_id])
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
    render_bbb_response bbb_res
 | 
					    render_bbb_response bbb_res
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -15,27 +15,10 @@
 | 
				
			|||||||
# with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
 | 
					# with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class EndMeetingJob < ApplicationJob
 | 
					class EndMeetingJob < ApplicationJob
 | 
				
			||||||
  include BbbApi
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  queue_as :default
 | 
					  queue_as :default
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  def perform(room, meeting)
 | 
					  def perform(room, meeting)
 | 
				
			||||||
    tries = 0
 | 
					    ActionCable.server.broadcast "#{room}-#{meeting}_meeting_updates_channel",
 | 
				
			||||||
    sleep_time = 2
 | 
					      action: 'meeting_ended'
 | 
				
			||||||
 | 
					 | 
				
			||||||
    while tries < 4
 | 
					 | 
				
			||||||
      bbb_res = bbb_get_meeting_info("#{room}-#{meeting}")
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      if !bbb_res[:returncode]
 | 
					 | 
				
			||||||
        ActionCable.server.broadcast "#{room}-#{meeting}_meeting_updates_channel",
 | 
					 | 
				
			||||||
          action: 'meeting_ended'
 | 
					 | 
				
			||||||
        break
 | 
					 | 
				
			||||||
      end
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      sleep sleep_time
 | 
					 | 
				
			||||||
      sleep_time = sleep_time * 2
 | 
					 | 
				
			||||||
      tries += 1
 | 
					 | 
				
			||||||
    end
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -15,12 +15,10 @@
 | 
				
			|||||||
# with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
 | 
					# with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class RecordingDeletesJob < ApplicationJob
 | 
					class RecordingDeletesJob < ApplicationJob
 | 
				
			||||||
  include BbbApi
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  queue_as :default
 | 
					  queue_as :default
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  def perform(room, record_id, meeting=nil)
 | 
					  def perform(room, record_id, meeting_name)
 | 
				
			||||||
    full_id = "#{room}-#{meeting}"
 | 
					    full_id = "#{room}-#{meeting_name}"
 | 
				
			||||||
    ActionCable.server.broadcast "#{room}_recording_updates_channel",
 | 
					    ActionCable.server.broadcast "#{room}_recording_updates_channel",
 | 
				
			||||||
      action: 'delete',
 | 
					      action: 'delete',
 | 
				
			||||||
      id: record_id
 | 
					      id: record_id
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -19,11 +19,9 @@ class RecordingUpdatesJob < ApplicationJob
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  queue_as :default
 | 
					  queue_as :default
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  def perform(room, record_id, meeting=nil)
 | 
					  def perform(room, record_id)
 | 
				
			||||||
    bbb_res = bbb_get_recordings({recordID: record_id})
 | 
					    recording = bbb_get_recordings({recordID: record_id})[:recordings].first
 | 
				
			||||||
    recording = bbb_res[:recordings].first
 | 
					    full_id = "#{room}-#{recording[:metadata][:"meeting-name"]}"
 | 
				
			||||||
    full_id = room
 | 
					 | 
				
			||||||
    full_id += "-#{recording[:metadata][:"meeting-name"]}"
 | 
					 | 
				
			||||||
    ActionCable.server.broadcast "#{room}_recording_updates_channel",
 | 
					    ActionCable.server.broadcast "#{room}_recording_updates_channel",
 | 
				
			||||||
      action: 'update',
 | 
					      action: 'update',
 | 
				
			||||||
      id: record_id,
 | 
					      id: record_id,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -11,3 +11,7 @@ deployment:
 | 
				
			|||||||
    branch: master
 | 
					    branch: master
 | 
				
			||||||
    commands:
 | 
					    commands:
 | 
				
			||||||
      - ./scripts/build_image_master.sh
 | 
					      - ./scripts/build_image_master.sh
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					test:
 | 
				
			||||||
 | 
					  pre:
 | 
				
			||||||
 | 
					    - cp env .env
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -37,8 +37,6 @@ Rails.application.configure do
 | 
				
			|||||||
  # Print deprecation notices to the stderr.
 | 
					  # Print deprecation notices to the stderr.
 | 
				
			||||||
  config.active_support.deprecation = :stderr
 | 
					  config.active_support.deprecation = :stderr
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  config.mail_notifications = true
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  # Raises error for missing translations
 | 
					  # Raises error for missing translations
 | 
				
			||||||
  # config.action_view.raise_on_missing_translations = true
 | 
					  # config.action_view.raise_on_missing_translations = true
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -19,6 +19,8 @@ require 'test_helper'
 | 
				
			|||||||
class BbbControllerTest < ActionController::TestCase
 | 
					class BbbControllerTest < ActionController::TestCase
 | 
				
			||||||
  include BbbApi
 | 
					  include BbbApi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  RETURNCODE_SUCCESS = 'SUCCESS'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  setup do
 | 
					  setup do
 | 
				
			||||||
    @meeting_id = 'test_id'
 | 
					    @meeting_id = 'test_id'
 | 
				
			||||||
    @user = users :user1
 | 
					    @user = users :user1
 | 
				
			||||||
@@ -51,7 +53,7 @@ class BbbControllerTest < ActionController::TestCase
 | 
				
			|||||||
    assert_response :success
 | 
					    assert_response :success
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  test "should wati for moderator on join for authenticated meeting when not room owner" do
 | 
					  test "should wait for moderator on join for authenticated meeting when not room owner" do
 | 
				
			||||||
    BbbController.any_instance.expects(:bbb_join_url)
 | 
					    BbbController.any_instance.expects(:bbb_join_url)
 | 
				
			||||||
      .with() do |token, full_name, opts|
 | 
					      .with() do |token, full_name, opts|
 | 
				
			||||||
        opts[:wait_for_moderator] && !opts[:user_is_moderator]
 | 
					        opts[:wait_for_moderator] && !opts[:user_is_moderator]
 | 
				
			||||||
@@ -67,7 +69,7 @@ class BbbControllerTest < ActionController::TestCase
 | 
				
			|||||||
    BbbController.any_instance.expects(:bbb_end_meeting)
 | 
					    BbbController.any_instance.expects(:bbb_end_meeting)
 | 
				
			||||||
      .with() do |token|
 | 
					      .with() do |token|
 | 
				
			||||||
        token == meeting_token(@user, @meeting_id)
 | 
					        token == meeting_token(@user, @meeting_id)
 | 
				
			||||||
      end.returns({status: :ok}).once
 | 
					      end.returns({status: :ok, returncode: RETURNCODE_SUCCESS}).once
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    get :end, params: { room_id: @user.encrypted_id, id: @meeting_id, resource: 'rooms' }
 | 
					    get :end, params: { room_id: @user.encrypted_id, id: @meeting_id, resource: 'rooms' }
 | 
				
			||||||
    assert_response :success
 | 
					    assert_response :success
 | 
				
			||||||
@@ -84,7 +86,7 @@ class BbbControllerTest < ActionController::TestCase
 | 
				
			|||||||
    BbbController.any_instance.expects(:bbb_get_recordings)
 | 
					    BbbController.any_instance.expects(:bbb_get_recordings)
 | 
				
			||||||
      .returns({status: :ok, recordings: []}).once
 | 
					      .returns({status: :ok, recordings: []}).once
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    get :recordings, params: { room_id: @user.encrypted_id, resource: 'rooms' }
 | 
					    get :recordings, params: { room_id: @user.encrypted_id, resource: 'rooms', id: @meeting_id }
 | 
				
			||||||
    assert_response :success
 | 
					    assert_response :success
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -94,7 +96,7 @@ class BbbControllerTest < ActionController::TestCase
 | 
				
			|||||||
    BbbController.any_instance.expects(:bbb_get_recordings)
 | 
					    BbbController.any_instance.expects(:bbb_get_recordings)
 | 
				
			||||||
      .returns({status: :ok, recordings: [{recordID: @recording}]}).once
 | 
					      .returns({status: :ok, recordings: [{recordID: @recording}]}).once
 | 
				
			||||||
    BbbController.any_instance.expects(:bbb_update_recordings)
 | 
					    BbbController.any_instance.expects(:bbb_update_recordings)
 | 
				
			||||||
      .returns({status: :ok}).once
 | 
					      .returns({status: :ok, returncode: RETURNCODE_SUCCESS}).once
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    patch :update_recordings, params: { room_id: @user.encrypted_id, resource: 'rooms', record_id: @recording }
 | 
					    patch :update_recordings, params: { room_id: @user.encrypted_id, resource: 'rooms', record_id: @recording }
 | 
				
			||||||
    assert_response :success
 | 
					    assert_response :success
 | 
				
			||||||
@@ -104,9 +106,9 @@ class BbbControllerTest < ActionController::TestCase
 | 
				
			|||||||
    login @user
 | 
					    login @user
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    BbbController.any_instance.expects(:bbb_get_recordings)
 | 
					    BbbController.any_instance.expects(:bbb_get_recordings)
 | 
				
			||||||
      .returns({status: :ok, recordings: [{recordID: @recording}]}).at_least_once
 | 
					      .returns({status: :ok, recordings: [{recordID: @recording, metadata: {'meeting-name': @meeting_id}}]}).twice
 | 
				
			||||||
    BbbController.any_instance.expects(:bbb_delete_recordings)
 | 
					    BbbController.any_instance.expects(:bbb_delete_recordings)
 | 
				
			||||||
      .returns({status: :ok}).once
 | 
					      .returns({status: :ok, returncode: RETURNCODE_SUCCESS}).once
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    delete :delete_recordings, params: { room_id: @user.encrypted_id, resource: 'rooms', record_id: @recording }
 | 
					    delete :delete_recordings, params: { room_id: @user.encrypted_id, resource: 'rooms', record_id: @recording }
 | 
				
			||||||
    assert_response :success
 | 
					    assert_response :success
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -43,6 +43,11 @@ class LandingControllerTest < ActionController::TestCase
 | 
				
			|||||||
    assert_response :success
 | 
					    assert_response :success
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  test "should not get room for invalid user" do
 | 
				
			||||||
 | 
					    get :resource, params: { room_id: 'invalid id', id: @meeting_id, resource: 'rooms' }
 | 
				
			||||||
 | 
					    assert_response :redirect
 | 
				
			||||||
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  test "should get wait for moderator" do
 | 
					  test "should get wait for moderator" do
 | 
				
			||||||
    get :wait_for_moderator, params: { room_id: @user.encrypted_id, id: @meeting_id, resource: 'rooms' }
 | 
					    get :wait_for_moderator, params: { room_id: @user.encrypted_id, id: @meeting_id, resource: 'rooms' }
 | 
				
			||||||
    assert_response :success
 | 
					    assert_response :success
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -17,13 +17,18 @@
 | 
				
			|||||||
ENV['RAILS_ENV'] ||= 'test'
 | 
					ENV['RAILS_ENV'] ||= 'test'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
require 'simplecov'
 | 
					require 'simplecov'
 | 
				
			||||||
 | 
					if ENV['CIRCLE_ARTIFACTS']
 | 
				
			||||||
 | 
					  dir = File.join(ENV['CIRCLE_ARTIFACTS'], "coverage")
 | 
				
			||||||
 | 
					  SimpleCov.coverage_dir(dir)
 | 
				
			||||||
 | 
					end
 | 
				
			||||||
SimpleCov.start do
 | 
					SimpleCov.start do
 | 
				
			||||||
  add_group 'Models', 'app/models'
 | 
					  add_group 'Models', 'app/models/'
 | 
				
			||||||
  add_group 'Controllers', 'app/controllers'
 | 
					  add_group 'Controllers', 'app/controllers/'
 | 
				
			||||||
  add_group 'Helpers', 'app/helpers'
 | 
					  add_group 'Helpers', 'app/helpers/'
 | 
				
			||||||
  add_group 'Config', 'config/'
 | 
					  add_group 'Config', 'config/'
 | 
				
			||||||
  add_group 'Libraries', 'lib/'
 | 
					  add_group 'Libraries', 'lib/'
 | 
				
			||||||
  add_group 'Tests', 'test/'
 | 
					  add_group 'Tests', 'test/'
 | 
				
			||||||
 | 
					  add_group 'Jobs', 'app/jobs/'
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
require File.expand_path('../../config/environment', __FILE__)
 | 
					require File.expand_path('../../config/environment', __FILE__)
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user