Upstream sync

This commit is contained in:
Senad Uka
2020-07-14 14:10:30 +02:00
parent 35303cb570
commit 4c49a5db03
28 changed files with 407 additions and 29 deletions

View File

@@ -30,6 +30,21 @@ RSpec.describe Api::ContractTemplatesController, type: :controller do
expect(response).to be_successful
end
it 'returns electronic signature legal text when present' do
ct = create(:contract_template, name: 'ct1', project_id: project.id)
ct.signature_legal_text = "some electronic signature legal text"
ct.save
sign_in_to_api(current_user)
get :show, params: { id: ct.id }
expect(response).to be_successful
expect(response.body).to include("signature_legal_text")
expect(response.body).to include(ct.signature_legal_text.body.as_json)
end
end
private

View File

@@ -127,9 +127,16 @@ RSpec.describe Api::SyncController, type: :controller do
get :index
medical_releases = attributes_for_type('medical_releases')
expect(medical_releases.first).to include('id')
end
it 'contains signature legal text for contract templates' do
create_default_data_with_signature_legal_text
get :index
contract_templates = attributes_for_type('contract_templates')
expect(contract_templates.first).to include('signature_legal_text')
expect(contract_templates.first['signature_legal_text']).to eq ContractTemplate.first.signature_legal_text.as_json
end
end
private
@@ -149,6 +156,13 @@ RSpec.describe Api::SyncController, type: :controller do
create(:appearance_release, :minor_with_guardian_photo, project: project)
end
def create_default_data_with_signature_legal_text
create_default_data
ct = create(:contract_template, name: "with signature legal text", project: Project.first)
ct.signature_legal_text = "legal text example"
ct.save
end
def response_body_json
JSON.parse(response.body)
end

View File

@@ -7,6 +7,7 @@ FactoryBot.define do
body "This is a test contract template."
guardian_clause "Is the signer a minor?"
fee "$0.00"
accessibility "public_template"
trait :archived do
archived_at Time.zone.now

View File

@@ -49,12 +49,18 @@ FactoryBot.define do
predefined_client_name "nat_geo"
end
factory :project_with_contract_template do
factory :project_with_contract_template_public do
after(:build) do |project, _|
project.contract_templates << build(:contract_template, project: nil)
end
end
factory :project_with_contract_template_private do
after(:build) do |project, _|
project.contract_templates << build(:contract_template, project: nil, accessibility: "private_template")
end
end
factory :project_with_directories do
after(:build) do |project, _|
project.directories << build(:directory, project: nil, name: "Shared")

View File

@@ -11,7 +11,7 @@ describe GenerateContractsZipJob do
dir = Rails.root.join("spec", "fixtures", "files")
files = ["contract.pdf", "AppearanceRelease.pdf"]
# Attachments in the test environment do not persist to cloud storage
# Therefore we want to stub calls to `open` with a cloud storage URL
# Therefore we want to stub calls to `open` with a cloud storage URL
allow_any_instance_of(ReleaseContractCollectionService).to receive(:open).and_return(StringIO.new("file data"))
allow_any_instance_of(ReleaseContractCollectionService).to receive(:build).and_yield(dir, files)
end
@@ -35,6 +35,38 @@ describe GenerateContractsZipJob do
expect(download.file).to be_attached
end
it "generates ZIP containing CSV file with all releases data for all release types" do
release_types = %w[AcquiredMediaRelease AppearanceRelease LocationRelease MaterialRelease MedicalRelease MiscRelease MusicRelease TalentRelease]
create_releases_for_all_types
release_types.each do |type|
lowercase_plural = type.constantize.model_name.plural
GenerateContractsZipJob.perform_now(project, download, type, project.public_send(lowercase_plural).ids)
generated_zip = download.file.blob.download
csv_file_name = "#{project.name.parameterize}_#{lowercase_plural.gsub('_', '-')}.csv"
Zip::InputStream.open(StringIO.new(generated_zip)) do |io|
while entry = io.get_next_entry
next unless entry.name == csv_file_name
csv_file = entry.get_input_stream.read
release_class = Object.const_get type
release_headers = release_class.csv_headers
release_headers.each do |header|
expect(csv_file).to match header
end
end
dummy_zip_file_name = "#{project.name.parameterize}_#{lowercase_plural.gsub('_', '-')}.zip"
if File.exist?(file_fixture(dummy_zip_file_name))
File.delete(file_fixture(dummy_zip_file_name))
end
end
end
end
context "When there are errors" do
let(:error) { StandardError.new("Contracts or contract templates not found.") }
@@ -42,10 +74,10 @@ describe GenerateContractsZipJob do
allow(ProjectsChannel).to receive(:broadcast_download_generation_update).with(download, I18n.t("contract_downloads.download.failure"))
allow_any_instance_of(ReleaseContractCollectionService).to receive(:build).and_raise(StandardError, "Contracts or contract templates not found")
end
it "updates status to 'failure' and sends user a notification" do
GenerateContractsZipJob.perform_now(project, download, "AppearanceRelease", project.appearance_releases.ids)
expect(download.status).to eq "failure"
expect(ProjectsChannel).to have_received(:broadcast_download_generation_update).with(download, I18n.t("contract_downloads.download.failure"))
end
@@ -56,6 +88,21 @@ describe GenerateContractsZipJob do
# Delete the file created in fixture.
# Or the tests will fail on next run due to already existing files in existing zip.
path = Rails.root.join("spec", "fixtures", "files")
File.delete("#{path}/my-video-project_appearance-releases.zip") if File.exists? "#{path}/my-video-project_appearance-releases.zip"
if File.exists? "#{path}/my-video-project_appearance-releases.zip"
File.delete("#{path}/my-video-project_appearance-releases.zip")
end
end
private
def create_releases_for_all_types
create(:acquired_media_release_with_contract_template, :native, project: project)
create(:appearance_release_with_contract_template, :native, project: project, person_name: "John Doe")
create(:location_release_with_contract_template, :native, project: project)
create(:material_release_with_contract_template, :native, project: project)
create(:medical_release_with_contract_template, :native, project: project)
create(:misc_release_with_contract_template, :native, project: project)
create(:music_release_with_contract_template, project: project)
create(:talent_release_with_contract_template, :native, project: project)
end
end

View File

@@ -36,7 +36,7 @@ RSpec.describe Project, type: :model do
describe "#import_contract_templates" do
it "imports contract templates from other projects within the account" do
existing_project = create(:project_with_contract_template)
existing_project = create(:project_with_contract_template_public)
new_project = create(:project, name: "New Project", account: existing_project.account)
expect {

View File

@@ -75,14 +75,17 @@ describe ContractTemplatePolicy do
end
permissions ".scope" do
let!(:member_project) do
create(:project_with_contract_template, name: "Member Project", members: user, account: account)
let!(:member_project_public_template) do
create(:project_with_contract_template_public, name: "Member Project Public Template", members: user, account: account)
end
let!(:member_project_private_template) do
create(:project_with_contract_template_private, name: "Member Project Private Template", members: user, account: account)
end
let!(:non_member_project) do
create(:project_with_contract_template, name: "Non-Member Project", account: account)
create(:project_with_contract_template_public, name: "Non-Member Project", account: account)
end
let!(:outside_project) do
create(:project_with_contract_template, name: "Outside Project", account: build(:account))
create(:project_with_contract_template_public, name: "Outside Project", account: build(:account))
end
let(:account) { build(:account) }
@@ -93,7 +96,8 @@ describe ContractTemplatePolicy do
context "for an account manager" do
let(:user) { create(:user, :account_manager, primary_account: account)}
it { is_expected.to include(member_project.contract_templates.first) }
it { is_expected.to include(member_project_public_template.contract_templates.first) }
it { is_expected.to include(member_project_private_template.contract_templates.first) }
it { is_expected.to include(non_member_project.contract_templates.first) }
it { is_expected.not_to include(outside_project.contract_templates.first) }
end
@@ -101,15 +105,17 @@ describe ContractTemplatePolicy do
context "for manager" do
let(:user) { create(:user, :manager, primary_account: account) }
it { is_expected.to include(member_project.contract_templates.first) }
it { is_expected.to include(member_project_public_template.contract_templates.first) }
it { is_expected.to include(member_project_private_template.contract_templates.first) }
it { is_expected.not_to include(non_member_project.contract_templates.first) }
it { is_expected.not_to include(outside_project.contract_templates.first) }
end
context "for associate" do
let(:user) { create(:user, :associate, primary_account: account) }
it { is_expected.to include(member_project.contract_templates.first) }
it { is_expected.to include(member_project_public_template.contract_templates.first) }
it { is_expected.not_to include(member_project_private_template.contract_templates.first) }
it { is_expected.not_to include(non_member_project.contract_templates.first) }
it { is_expected.not_to include(outside_project.contract_templates.first) }
end