Upstream sync master
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
require 'zoom_gateway'
|
||||
FactoryBot.define do
|
||||
factory :zoom_user do
|
||||
account_number ZoomGateway.ACCOUNT_NUMBER
|
||||
trait ZoomGateway.USER_TYPE_NAME
|
||||
|
||||
trait :with_api_id do
|
||||
api_id "api_user_id"
|
||||
end
|
||||
|
||||
@@ -17,6 +17,7 @@ feature "User managing location releases" do
|
||||
fill_in person_phone_field, with: "555-555-5555"
|
||||
fill_in person_email_field, with: "jane.doe@test.com"
|
||||
fill_in person_address_street1_field, with: "100 Broadway"
|
||||
fill_in filming_hours_field, with: "04:00 - 22:00"
|
||||
draw_signature file_fixture("signature.png"), "location_release_signature_base64"
|
||||
end
|
||||
|
||||
@@ -51,6 +52,7 @@ feature "User managing location releases" do
|
||||
|
||||
by "filling out the remaining information" do
|
||||
fill_in_release_fields name: "Test Location Release"
|
||||
fill_in filming_hours_field, with: "04:00 - 22:00"
|
||||
click_button create_release_button
|
||||
expect(page).to have_content(create_release_notice)
|
||||
expect(page).to have_photo("location_photo.png")
|
||||
@@ -136,6 +138,7 @@ feature "User managing location releases" do
|
||||
:native,
|
||||
project: project,
|
||||
name: "Benny's Burritos",
|
||||
filming_hours: "06:00 - 20:00",
|
||||
tag_list: "Restaurant",
|
||||
notes: [
|
||||
build(:note,
|
||||
@@ -172,6 +175,8 @@ feature "User managing location releases" do
|
||||
expect(pdf_body).to have_content("Restaurant")
|
||||
expect(pdf_body).to have_content photos_heading.upcase
|
||||
expect(pdf_body).to have_content("location_photo.png")
|
||||
expect(pdf_body).to have_content("Filming Hours")
|
||||
expect(pdf_body).to have_content("06:00 - 20:00")
|
||||
end
|
||||
|
||||
context "when the user is associate" do
|
||||
@@ -222,6 +227,10 @@ feature "User managing location releases" do
|
||||
"location_release[person_phone]"
|
||||
end
|
||||
|
||||
def filming_hours_field
|
||||
"location_release[filming_hours]"
|
||||
end
|
||||
|
||||
def have_photo(filename, attr: "src")
|
||||
have_selector("img[#{attr}*='#{filename}']")
|
||||
end
|
||||
|
||||
@@ -79,6 +79,13 @@ RSpec.describe ZoomGateway do
|
||||
expect(ZoomGateway.enable_recordings?).to be_falsey
|
||||
end
|
||||
end
|
||||
|
||||
context '.ACCOUNT_NUMBER' do
|
||||
it 'depends on ENV["ZOOM_ACCOUNT_NUMBER"]' do
|
||||
stub_env_variable('ZOOM_ACCOUNT_NUMBER', 'xxx-yyy-zzz')
|
||||
expect(ZoomGateway.ACCOUNT_NUMBER).to eq('xxx-yyy-zzz')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe ".find_meeting" do
|
||||
@@ -117,9 +124,7 @@ RSpec.describe ZoomGateway do
|
||||
end
|
||||
|
||||
it 'raises an exception' do
|
||||
allow(ENV).to receive(:[]).and_call_original
|
||||
allow(ENV).to receive(:[]).with('ZOOM_USER_TYPE').and_return('pro')
|
||||
allow(ENV).to receive(:[]).with('ZOOM_PRO_USERS_LIMIT').and_return('2')
|
||||
stub_env_variables(ZOOM_USER_TYPE: 'pro', ZOOM_PRO_USERS_LIMIT: 2)
|
||||
|
||||
expect { gateway.create_host('host-email@address') }.to raise_error(ZoomGateway::TooManyHosts)
|
||||
end
|
||||
@@ -133,11 +138,4 @@ RSpec.describe ZoomGateway do
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def stub_env_variable(name, value)
|
||||
allow(ENV).to receive(:[]).and_call_original
|
||||
allow(ENV).to receive(:[]).with(name.to_s).and_return(value.to_s)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -147,10 +147,4 @@ describe AppHost do
|
||||
expect(app_domain.protocol).to eq :http
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def stub_env(key, value)
|
||||
allow(ENV).to receive(:fetch).with(key).and_return(value)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -79,7 +79,7 @@ RSpec.describe Project, type: :model do
|
||||
|
||||
context 'there is no meeting' do
|
||||
context 'there is a free user available' do
|
||||
let!(:free_zoom_user) { create(:zoom_user, api_id: 'user_id') }
|
||||
let!(:free_zoom_user) { create(:zoom_user, :with_api_id) }
|
||||
|
||||
before do
|
||||
allow_any_instance_of(ZoomGateway).to receive(:create_meeting).and_return('new-meeting-id')
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
require 'zoom_gateway'
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe ZoomUser, type: :model do
|
||||
@@ -5,6 +6,10 @@ RSpec.describe ZoomUser, type: :model do
|
||||
it { is_expected.to have_many(:zoom_meetings).dependent(:nullify) }
|
||||
end
|
||||
|
||||
describe "enums" do
|
||||
it { is_expected.to define_enum_for(:tier).with_values([:basic, :pro]) }
|
||||
end
|
||||
|
||||
describe 'callbacks' do
|
||||
let(:zoom_user) { build(:zoom_user) }
|
||||
|
||||
@@ -22,10 +27,120 @@ RSpec.describe ZoomUser, type: :model do
|
||||
zoom_user.save
|
||||
expect(zoom_user.api_id).to eq "retrieved_api_id"
|
||||
end
|
||||
|
||||
it 'assigns current account number' do
|
||||
allow_any_instance_of(ZoomGateway).to receive(:create_host).and_return("retrieved_api_id")
|
||||
ENV['ZOOM_ACCOUNT_NUMBER'] = 'xxx-yyy-zzz'
|
||||
|
||||
zoom_user.save
|
||||
expect(zoom_user.account_number).to eq 'xxx-yyy-zzz'
|
||||
end
|
||||
end
|
||||
|
||||
context '#before_destroy' do
|
||||
pending 'aborts if there is api_id assigned'
|
||||
end
|
||||
end
|
||||
|
||||
describe 'scopes' do
|
||||
context '.current_account' do
|
||||
before do
|
||||
create_list(:zoom_user, 10, :with_api_id, account_number: 'first-account-id')
|
||||
create_list(:zoom_user, 25, :with_api_id, account_number: 'second-account-id')
|
||||
end
|
||||
|
||||
it 'only returns users from currently set account' do
|
||||
ENV['ZOOM_ACCOUNT_NUMBER'] = 'first-account-id'
|
||||
expect(ZoomUser.current_account.count).to eq 10
|
||||
expect(ZoomUser.current_account.pluck(:account_number).uniq.count).to eq 1
|
||||
expect(ZoomUser.current_account.pluck(:account_number).uniq.first).to eq 'first-account-id'
|
||||
end
|
||||
end
|
||||
|
||||
context '.free' do
|
||||
let(:free_user) { create(:zoom_user, :with_api_id) }
|
||||
let(:busy_user) { create(:zoom_user, :with_api_id) }
|
||||
let(:second_busy_user) { create(:zoom_user, :with_api_id) }
|
||||
let!(:meeting_started) { create(:zoom_meeting, zoom_user: busy_user, status: :started) }
|
||||
let!(:meeting_created) { create(:zoom_meeting, zoom_user: second_busy_user, status: :created) }
|
||||
|
||||
it 'returns only the users without started / created meetings' do
|
||||
users = ZoomUser.free
|
||||
|
||||
expect(users).to include(free_user)
|
||||
expect(users).not_to include(busy_user)
|
||||
expect(users).not_to include(second_busy_user)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
describe '.current_account?' do
|
||||
let(:zoom_user) { create(:zoom_user, :with_api_id, account_number: 'xxx-xxx-xxx') }
|
||||
|
||||
it 'returns true if it belongs to currently set account' do
|
||||
ENV['ZOOM_ACCOUNT_NUMBER'] = 'xxx-xxx-xxx'
|
||||
expect(zoom_user.current_account?).to be_truthy
|
||||
end
|
||||
|
||||
it 'returns false if it doesn\'t belong to currently set account' do
|
||||
ENV['ZOOM_ACCOUNT_NUMBER'] = 'yyy-yyy-yyy'
|
||||
expect(zoom_user.current_account?).to be_falsey
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
context 'static methods' do
|
||||
describe '.generate_api_email' do
|
||||
it 'contains @' do
|
||||
expect(ZoomUser.generate_api_email).to include('@')
|
||||
end
|
||||
end
|
||||
|
||||
describe '.for_new_meeting' do
|
||||
let(:a_basic) { create(:zoom_user, :with_api_id, account_number: 'aaa', tier: :basic) }
|
||||
let(:b_basic) { create(:zoom_user, :with_api_id, account_number: 'bbb', tier: :basic) }
|
||||
let(:a_pro) { create(:zoom_user, :with_api_id, account_number: 'aaa', tier: :pro) }
|
||||
let(:b_pro) { create(:zoom_user, :with_api_id, account_number: 'bbb', tier: :pro) }
|
||||
|
||||
it 'picks free user of requested type from current account' do
|
||||
[a_basic, a_pro, b_basic, b_pro]
|
||||
|
||||
stub_env_variables(ZOOM_USER_TYPE: 'basic', ZOOM_ACCOUNT_NUMBER: 'aaa')
|
||||
expect(ZoomUser.for_new_meeting).to eq(a_basic)
|
||||
|
||||
stub_env_variables(ZOOM_USER_TYPE: 'pro', ZOOM_ACCOUNT_NUMBER: 'aaa')
|
||||
expect(ZoomUser.for_new_meeting).to eq(a_pro)
|
||||
|
||||
stub_env_variables(ZOOM_USER_TYPE: 'basic', ZOOM_ACCOUNT_NUMBER: 'bbb')
|
||||
expect(ZoomUser.for_new_meeting).to eq(b_basic)
|
||||
|
||||
stub_env_variables(ZOOM_USER_TYPE: 'pro', ZOOM_ACCOUNT_NUMBER: 'bbb')
|
||||
expect(ZoomUser.for_new_meeting).to eq(b_pro)
|
||||
end
|
||||
|
||||
context 'no free user' do
|
||||
before do
|
||||
allow_any_instance_of(ZoomGateway).to receive(:create_host).and_return('host-id')
|
||||
end
|
||||
|
||||
it 'creates new user if there is no requested user free available under account' do
|
||||
[a_basic, a_pro, b_basic]
|
||||
stub_env_variables(ZOOM_USER_TYPE: 'pro', ZOOM_ACCOUNT_NUMBER: 'bbb')
|
||||
|
||||
expect_any_instance_of(ZoomGateway).to receive(:create_host)
|
||||
ZoomUser.for_new_meeting
|
||||
end
|
||||
|
||||
it 'creates new user if requested user is busy' do
|
||||
[a_basic, a_pro, b_basic, b_pro]
|
||||
stub_env_variables(ZOOM_USER_TYPE: 'pro', ZOOM_ACCOUNT_NUMBER: 'aaa')
|
||||
create(:zoom_meeting, zoom_user: a_pro, status: :started)
|
||||
|
||||
expect_any_instance_of(ZoomGateway).to receive(:create_host)
|
||||
ZoomUser.for_new_meeting
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
16
spec/support/env_helper.rb
Normal file
16
spec/support/env_helper.rb
Normal file
@@ -0,0 +1,16 @@
|
||||
module EnvHelper
|
||||
def stub_env_variables(vars)
|
||||
allow(ENV).to receive(:[]).and_call_original
|
||||
vars.each do |variable, value|
|
||||
allow(ENV).to receive(:[]).with(variable.to_s).and_return(value)
|
||||
end
|
||||
end
|
||||
|
||||
def stub_env_variable(key, value)
|
||||
stub_env_variables({key => value})
|
||||
end
|
||||
end
|
||||
|
||||
RSpec.configure do |config|
|
||||
config.include EnvHelper
|
||||
end
|
||||
Reference in New Issue
Block a user