update zoom user settings after creating zoom user

This commit is contained in:
bilal
2020-06-19 12:14:22 +02:00
parent 6b0ea5b7df
commit f5068a3a7e
4 changed files with 107 additions and 0 deletions

View File

@@ -1,3 +1,7 @@
# frozen_string_literal: true
require './lib/zoom_wrapper_monkeypatch'
class ZoomGateway
class AuthenticationError < StandardError; end
class MeetingExpired < StandardError; end
@@ -82,6 +86,21 @@ class ZoomGateway
type: self.class.USER_TYPE
})
# Update user with custom settings
custom_defaults = {
id: host_user["id"],
in_meeting: {
auto_saving_chat: true,
co_host: true,
non_verbal_feedback: true,
breakout_room: true,
group_hd: true,
far_end_camera_control: true,
allow_live_streaming: true
}
}
@client.user_settings_update custom_defaults
# Assign role to user
@client.roles_assign role_id: host_role["id"], members: [{id: host_user["id"]}]

View File

@@ -0,0 +1,25 @@
# frozen_string_literal: true
module Zoom
module Actions
module User
def user_settings_update(*args)
params = Zoom::Params.new(Utils.extract_options!(args))
permitted_in_meeting_params = %i[
auto_saving_chat
co_host
non_verbal_feedback
breakout_room
group_hd
far_end_camera_control
allow_live_streaming
]
permitted_params = { in_meeting: permitted_in_meeting_params }
params.require(:id).permit permitted_params
request_body = params.except(:id).to_json
resp = self.class.patch("/users/#{params[:id]}/settings", body: request_body, headers: request_headers)
Utils.parse_response resp
end
end
end
end

View File

@@ -5,6 +5,7 @@ RSpec.describe ZoomGateway do
let(:host_user_hash) { {"email" => "user1@directme", "id" => "host_user_id"} }
let(:roles_members_response) { {"members" => [host_user_hash]} }
let(:user_create_response) { {"id" => "new_host_id"} }
let(:user_settings_update_response) { "User settings updated" }
let(:roles_assign_response) { {"ids" => ["new_host_id"]} }
let(:meeting_hash) { {"id" => "meeting_id", "start_url" => "https://start_url", "join_url" => "https://join_url"} }
let(:gateway) { ZoomGateway.new }
@@ -121,7 +122,9 @@ RSpec.describe ZoomGateway do
it "returns new host id" do
allow_any_instance_of(Zoom.new.class).to receive(:user_create).and_return(user_create_response)
allow_any_instance_of(Zoom.new.class).to receive(:roles_assign).and_return(roles_assign_response)
allow_any_instance_of(Zoom.new.class).to receive(:user_settings_update).and_return(user_settings_update_response)
expect_any_instance_of(Zoom.new.class).to receive(:user_settings_update)
expect(gateway.create_host("host-email@address")).to eq("new_host_id")
end

View File

@@ -0,0 +1,60 @@
require 'rails_helper'
RSpec.describe Zoom::Actions::User do
let(:wrapper) { Zoom.new }
describe '.update_user_settings' do
it 'raises exception if id param is missing' do
params = {
in_meeting: {
not_allowed_param: 1
}
}
expect do
wrapper.user_settings_update(params)
end.to raise_exception(Zoom::ParameterMissing)
end
it 'raises exception if not allowed param is present' do
params = {
id: 'dw3-3sd33',
in_meeting: {
not_allowed_param: 1
}
}
expect do
wrapper.user_settings_update(params)
end.to raise_exception(Zoom::ParameterNotPermitted)
end
it 'sends PATCH request to the Zoom API endpoint' do
params = {
id: 'zoom-120-id',
in_meeting: {
auto_saving_chat: true,
co_host: true,
non_verbal_feedback: true,
breakout_room: true,
group_hd: true,
far_end_camera_control: true,
allow_live_streaming: true
}
}
allow(Zoom::Utils).to receive(:parse_response).and_return 'Success!'
path = "/users/#{params[:id]}/settings"
body_params = { body: params.except(:id).to_json }
allow(wrapper.class)
.to receive(:patch)
.with(path, hash_including(body_params))
.and_return({})
mock_response = wrapper.user_settings_update params
expect(mock_response).to eq 'Success!'
end
end
end