Taskme update

This commit is contained in:
Senad Uka
2020-06-30 05:08:23 +02:00
parent 1cd125382f
commit 71ad502cc1
210 changed files with 6316 additions and 766 deletions

View File

@@ -66,14 +66,16 @@ RSpec.describe Account do
end
describe "#storage_total" do
it "sums videos, release photos, contracts, signatures" do
it "sums videos, release photos, contracts, signatures, recordings" do
video_file = Rack::Test::UploadedFile.new(Rails.root.join("spec", "fixtures", "files", "video_file.mp4"), "video/mp4")
recording_file = Rack::Test::UploadedFile.new(Rails.root.join("spec", "fixtures", "files", "video_file.mp4"), "video/mp4")
photo_file = Rack::Test::UploadedFile.new(Rails.root.join("spec", "fixtures", "files", "person_photo.png"), "image/png")
contract_file = Rack::Test::UploadedFile.new(Rails.root.join("spec", "fixtures", "files", "contract.pdf"), "application/pdf")
signature_file = Rack::Test::UploadedFile.new(Rails.root.join("spec", "fixtures", "files", "signature.png"), "image/png")
edl_file = Rack::Test::UploadedFile.new(Rails.root.join("spec", "fixtures", "files", "sample-edl.edl"), "application/octet-stream")
expect(video_file.size).to eq 1_055_736
expect(recording_file.size).to eq 1_055_736
expect(edl_file.size).to eq 440
expect(photo_file.size).to eq 910
expect(contract_file.size).to eq 12
@@ -89,8 +91,9 @@ RSpec.describe Account do
acquired_media_release = create(:acquired_media_release, project: project, contract: contract_file)
import = create(:import, project: project, file: contract_file)
music_release = create(:music_release, project: project, contract: contract_file)
zoom_meeting = create(:zoom_meeting, project: project, recording: recording_file)
expect(account.storage_total).to eq 1_069_936
expect(account.storage_total).to eq 2_125_672
end
it "sums only for projects tied to account" do
@@ -127,7 +130,12 @@ RSpec.describe Account do
User,
Broadcast,
TaskRequest,
Account
Account,
ZoomMeeting,
MedicalRelease,
MiscRelease,
MatchingRequest,
ActionMailbox::InboundEmail # This is Rails model, we are not using it and it is NOT added to the Account#storage_total calculation
]
Rails.application.eager_load!
ActiveRecord::Base.descendants.each do |model|

View File

@@ -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

View File

@@ -42,7 +42,6 @@ describe BlankContract do
material_release = create(:material_release_with_contract_template, project: project, person_name: 'Jane Doe')
result = render_contract_html_for(material_release)
expect(result).to include 'serial-number'
expect(result).to include 'DO NOT COPY'
end
end

View File

@@ -50,11 +50,19 @@ describe ContractTemplatePreview do
'id' => nil,
'person_first_name' => 'Dummy',
'person_last_name' => 'Person',
'person_address' => 'Street 1, Street 2, City, State 12345, Country',
'person_address_street1' => 'Street 1',
'person_address_street2' => 'Street 2',
'person_address_city' => 'City',
'person_address_state' => 'State',
'person_address_zip' => '12345',
'person_phone' => '00 111 222 333 4444',
'updated_at' => nil,
'minor' => true,
'guardian_address' => 'Street 3, Street 4, City-2, State-2 112233, Country-2',
'guardian_address_street1' => 'Street 3',
'guardian_address_street2' => 'Street 4',
'guardian_address_city' => 'City-2',
'guardian_address_state' => 'State-2',
'guardian_address_zip' => '112233',
"guardian_first_name" => nil,
"guardian_last_name" => nil,
"guardian_name_old" => nil,

View File

@@ -13,6 +13,8 @@ describe ContractTemplate do
it { is_expected.to have_many(:appearance_releases).dependent(:restrict_with_error) }
it { is_expected.to have_many(:location_releases).dependent(:restrict_with_error) }
it { is_expected.to have_many(:material_releases).dependent(:restrict_with_error) }
it { is_expected.to have_many(:medical_releases).dependent(:restrict_with_error) }
it { is_expected.to have_many(:misc_releases).dependent(:restrict_with_error) }
end
describe 'validations' do

View File

@@ -29,7 +29,7 @@ module ExcelReports
restriction: Restriction.last,
person_first_name: "John",
person_last_name: "Doe",
person_address: "123 Main Street, New York, NY 10000")
person_address_street1: "123 Main Street, New York, NY 10000")
)
)
allow(sheet).to receive(:add_row)

View File

@@ -6,6 +6,7 @@ describe HeadshotCollection do
project = create(:project,
appearance_releases: create_list(:appearance_release, 1),
talent_releases: create_list(:talent_release, 1),
headshot_collection_uid: "123abc"
)
collection = HeadshotCollection.for_project(project)
@@ -14,7 +15,7 @@ describe HeadshotCollection do
expect(collection).to be_a(HeadshotCollection)
expect(collection.releasables).to include(project.appearance_releases.first)
expect(collection.releasables).to include(project.talent_releases.first)
expect(collection.collection_uid).to eq(project.id)
expect(collection.collection_uid).to eq(project.headshot_collection_uid)
end
context "when a release has no headshot photo attachment" do
@@ -85,6 +86,29 @@ describe HeadshotCollection do
expect(mapping["appearance_release_#{releases.first.id}"]).to include("123")
expect(mapping["talent_release_#{releases.last.id}"]).to include("456")
end
context "when collection uid is blank" do
it "is not included in the hash" do
releases = []
collection = HeadshotCollection.new(nil, releases)
hash = collection.to_hash
expect(hash.keys).not_to include(:collection_uid)
end
end
context "when there are no releasables" do
it "includes a blank hash value for the ids_to_images key" do
releases = []
collection = HeadshotCollection.new(nil, releases)
hash = collection.to_hash
expect(hash.keys).to include(:ids_to_images)
expect(hash[:ids_to_images]).to eq(Hash.new)
end
end
end
private

View File

@@ -0,0 +1,53 @@
require "rails_helper"
RSpec.describe MedicalRelease do
it_behaves_like "a contractable"
it_behaves_like "a notable"
it_behaves_like "a photoable"
it_behaves_like "a releasable"
describe "validations" do
it { is_expected.to validate_presence_of(:person_first_name) }
it { is_expected.to validate_presence_of(:person_last_name) }
context "for #person_email" do
it { is_expected.to allow_value("test@test.com", nil).for(:person_email) }
it { is_expected.not_to allow_values("foo", "test@foo", "N/A").for(:person_email) }
end
context "for native releases" do
it { is_expected.to validate_attachment_of(:signature).on(:native) }
end
context "for non-native releases" do
it { is_expected.to validate_attachment_of(:contract).on(:non_native) }
end
end
describe "attachments" do
it { is_expected.to respond_to(:signature) }
end
describe "#uses_edl?" do
it { is_expected.not_to be_uses_edl }
end
describe "#contract_file_name" do
it "includes project name, signed at date, release type, release number and person name" do
release = create(:medical_release_with_contract_template, id: 100, signed_at: Date.new(2020, 2, 10), person_first_name: "John", person_last_name: "Doe")
expect(release.contract_file_name).to eq("my-video-project_medical_2020.02.10_1_doe-john")
end
context "when signed at is nil" do
it "uses the created at date" do
release = create(:medical_release_with_contract_template,
signed_at: nil,
created_at: DateTime.new(2020, 2, 10, 12, 0, 0),
person_first_name: "John", person_last_name: "Doe")
expect(release.contract_file_name).to eq("my-video-project_medical_2020.02.10_1_doe-john")
end
end
end
end

View File

@@ -0,0 +1,53 @@
require 'rails_helper'
RSpec.describe MiscRelease, type: :model do
it_behaves_like "a contractable"
it_behaves_like "a notable"
it_behaves_like "a photoable"
it_behaves_like "a releasable"
describe "validations" do
it { is_expected.to validate_presence_of(:person_first_name) }
it { is_expected.to validate_presence_of(:person_last_name) }
context "for #person_email" do
it { is_expected.to allow_value("test@test.com", nil).for(:person_email) }
it { is_expected.not_to allow_values("foo", "test@foo", "N/A").for(:person_email) }
end
context "for native releases" do
it { is_expected.to validate_attachment_of(:signature).on(:native) }
end
context "for non-native releases" do
it { is_expected.to validate_attachment_of(:contract).on(:non_native) }
end
end
describe "attachments" do
it { is_expected.to respond_to(:signature) }
end
describe "#uses_edl?" do
it { is_expected.not_to be_uses_edl }
end
describe "#contract_file_name" do
it "includes project name, signed at date, release type, release number and person name" do
release = create(:misc_release_with_contract_template, id: 100, signed_at: Date.new(2020, 2, 10), person_first_name: "John", person_last_name: "Doe")
expect(release.contract_file_name).to eq("my-video-project_misc_2020.02.10_1_doe-john")
end
context "when signed at is nil" do
it "uses the created at date" do
release = create(:misc_release_with_contract_template,
signed_at: nil,
created_at: DateTime.new(2020, 2, 10, 12, 0, 0),
person_first_name: "John", person_last_name: "Doe")
expect(release.contract_file_name).to eq("my-video-project_misc_2020.02.10_1_doe-john")
end
end
end
end

View File

@@ -1,5 +1,4 @@
require "rails_helper"
require "zoom_gateway"
RSpec.describe Project, type: :model do
describe "associations" do
@@ -10,6 +9,8 @@ RSpec.describe Project, type: :model do
it { is_expected.to have_many(:material_releases).dependent(:destroy) }
it { is_expected.to have_many(:music_releases).dependent(:destroy) }
it { is_expected.to have_many(:talent_releases).dependent(:destroy) }
it { is_expected.to have_many(:medical_releases).dependent(:destroy) }
it { is_expected.to have_many(:misc_releases).dependent(:destroy) }
it { is_expected.to have_many(:videos).dependent(:destroy) }
it { is_expected.to have_many(:contract_templates).dependent(:destroy) }
it { is_expected.to have_many(:project_memberships).dependent(:destroy) }
@@ -79,7 +80,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')

View File

@@ -1,5 +1,4 @@
require 'rails_helper'
require 'zoom_gateway'
RSpec.describe ZoomMeeting, type: :model do
let(:zoom_meeting) { build(:zoom_meeting, api_meeting_id: nil) }
@@ -16,6 +15,17 @@ RSpec.describe ZoomMeeting, type: :model do
end
describe "attachments" do
it { is_expected.to respond_to(:recording) }
end
describe "validations" do
context '#recording' do
it { is_expected.to allow_content_type("video/mp4").for(:recording) }
it { is_expected.not_to allow_content_types("image/png").for(:recording) }
end
end
describe 'associations' do
it { is_expected.to belong_to(:zoom_user) }
it { is_expected.to belong_to(:project).optional(true) }

View File

@@ -5,6 +5,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 +26,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