From f5068a3a7ea03431b9e1d6523f9107d476ddd3ec Mon Sep 17 00:00:00 2001 From: bilal Date: Fri, 19 Jun 2020 12:14:22 +0200 Subject: [PATCH] update zoom user settings after creating zoom user --- lib/zoom_gateway.rb | 19 +++++++ lib/zoom_wrapper_monkeypatch.rb | 25 ++++++++++ spec/lib/zoom_gateway_spec.rb | 3 ++ spec/lib/zoom_wrapper_monkeypatch_spec.rb | 60 +++++++++++++++++++++++ 4 files changed, 107 insertions(+) create mode 100644 lib/zoom_wrapper_monkeypatch.rb create mode 100644 spec/lib/zoom_wrapper_monkeypatch_spec.rb diff --git a/lib/zoom_gateway.rb b/lib/zoom_gateway.rb index 764c2f9..2225908 100644 --- a/lib/zoom_gateway.rb +++ b/lib/zoom_gateway.rb @@ -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"]}] diff --git a/lib/zoom_wrapper_monkeypatch.rb b/lib/zoom_wrapper_monkeypatch.rb new file mode 100644 index 0000000..bb9e0dc --- /dev/null +++ b/lib/zoom_wrapper_monkeypatch.rb @@ -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 \ No newline at end of file diff --git a/spec/lib/zoom_gateway_spec.rb b/spec/lib/zoom_gateway_spec.rb index 0b48a24..dc41514 100644 --- a/spec/lib/zoom_gateway_spec.rb +++ b/spec/lib/zoom_gateway_spec.rb @@ -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 diff --git a/spec/lib/zoom_wrapper_monkeypatch_spec.rb b/spec/lib/zoom_wrapper_monkeypatch_spec.rb new file mode 100644 index 0000000..7f653e6 --- /dev/null +++ b/spec/lib/zoom_wrapper_monkeypatch_spec.rb @@ -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