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

@@ -50,4 +50,21 @@ RSpec.describe BroadcastsChannel, type: :channel do
})
end
end
describe ".broadcast_file_upload_updates" do
it 'broadcasts to the channel with the right data' do
broadcast = create(:broadcast, :with_stream, :with_files, skip_create_callback: true)
files_content = ApplicationController.render partial: "broadcasts/file", collection: broadcast.files
expect {
BroadcastsChannel.broadcast_file_upload_updates(broadcast, broadcast.files, "pagination_content")
}.to have_broadcasted_to(broadcast).with({
event: 'file_upload_update',
broadcast_token: broadcast.token,
files_content: files_content,
pagination_content: "pagination_content"
})
end
end
end

View File

@@ -24,4 +24,20 @@ RSpec.describe ProjectsChannel, type: :channel do
}.to have_broadcasted_to(project).with(event: "video_status_update", content: content)
end
end
describe ".conference_recording_ready" do
it "broadcasts to the project channel" do
recording_file = Rack::Test::UploadedFile.new(Rails.root.join("spec", "fixtures", "files", "video_file.mp4"), "video/mp4")
zoom_meeting = create(:zoom_meeting, project: project, recording: recording_file)
video_url = 'http://url.to.video/video.mp4'
allow(zoom_meeting.recording).to receive(:service_url).and_return(video_url)
expect {
ProjectsChannel.conference_recording_ready(project, zoom_meeting.recording)
}.to have_broadcasted_to(project).with { |data|
expect(data['content']).to include(video_url)
expect(data['event']).to eq('conference_recording_ready')
}
end
end
end

View File

@@ -128,6 +128,26 @@ RSpec.describe Api::BroadcastsController, type: :controller do
expect(included.first.dig("id")).to eq broadcast.files.first.id.to_s
expect(included.first.dig("type")).to eq 'active_storage_attachment'
end
context "when files param contains a signed_id string" do
it "adds that file to the broadcast" do
project = create(:project, name: 'first', account_id: current_user.primary_account.id)
broadcast = create(:broadcast, :with_stream, skip_create_callback: true, project: project, status: 'created')
blob = ActiveStorage::Blob.create_after_upload!(io: StringIO.new("Hello"), filename: "hello.txt", content_type: "text/plain")
sign_in_to_api(current_user)
patch :update, params: { project_id: project, id: broadcast, broadcast: { files: [blob.signed_id] } }
relationships = JSON.parse(response.body).dig('data', 'relationships')
included = JSON.parse(response.body).dig('included')
expect(relationships.keys).to include('files')
expect(included.size).to eq 1
expect(included.first.dig("id")).to eq broadcast.files.first.id.to_s
expect(included.first.dig("type")).to eq 'active_storage_attachment'
expect(included.first.dig("attributes", "filename")).to eq 'hello.txt'
end
end
end
after do

View File

@@ -0,0 +1,36 @@
require 'rails_helper'
RSpec.describe Api::DirectUploadsController, type: :controller do
let(:current_user) { create(:user) }
let(:project) { create(:project, account: current_user.primary_account) }
before do
sign_in_to_api(current_user)
end
describe '#create' do
it 'returns data for a direct upload' do
post :create, params: { direct_upload: direct_upload_params }
expect(response).to be_successful
expect(response_body_data_attributes).to include('id', 'key', 'signed_id', 'url', 'headers')
end
end
private
def direct_upload_params
file = file_fixture("video_file.mp4")
checksum = Digest::MD5.base64digest(StringIO.new(file.read).to_s)
{ filename: file.basename.to_s, content_type: "video/mp4", byte_size: file.size, checksum: checksum }
end
def response_body_data
JSON.parse(response.body).dig('data')
end
def response_body_data_attributes
response_body_data.dig('attributes')
end
end

View File

@@ -26,8 +26,7 @@ RSpec.describe AppearanceReleasesController, tye: :controller do
get :index, params: { project_id: project }
expect(response.body).to have_content "John Doe"
expect(response.body).to have_content "555-123-4567"
expect(response.body).to have_content "jane.doe@test.com"
expect(response.body).to have_content "P: 5551234567E: jane.doe@test.com"
expect(response.body).to have_content "Some notes here"
expect(response.body).to have_button "Import Release"
expect(response.body).to have_content "Manage"
@@ -264,7 +263,12 @@ RSpec.describe AppearanceReleasesController, tye: :controller do
end
def minor_appearance_release_params
attributes_for(:appearance_release, :non_native, :minor_with_guardian_photo).except(:contract).merge(contract_param, exploitable_rights_params)
attributes_for(:appearance_release, :non_native, :minor_with_guardian_photo)
.except(:contract)
.except(:guardian_address_street2).except(:guardian_address_city)
.except(:guardian_address_state).except(:guardian_address_zip)
.except(:guardian_address_country)
.merge(contract_param, exploitable_rights_params)
end
def exploitable_rights_params

View File

@@ -111,17 +111,6 @@ RSpec.describe BroadcastsController, type: :controller do
end
end
describe "#update" do
let!(:broadcast) { create(:broadcast, :with_stream, skip_create_callback: true, project: project ) }
it "uploads files to broadcast" do
patch :update, params: { project_id: project.id, id: broadcast.id, broadcast: file_params }, xhr: true
expect(broadcast.files.count).to eq(1)
expect(broadcast.files.first.filename).to eq("contract.pdf")
end
end
describe "#show" do
let(:broadcast) { create(:broadcast, project: project, name: "Another Broadcast") }
@@ -198,6 +187,25 @@ RSpec.describe BroadcastsController, type: :controller do
end
end
describe "#update" do
let!(:broadcast) { create(:broadcast, :with_stream, skip_create_callback: true, project: project ) }
it "uploads files to broadcast" do
patch :update, params: { project_id: project.id, id: broadcast.id, broadcast: file_params }, xhr: true
expect(broadcast.files.count).to eq(1)
expect(broadcast.files.first.filename).to eq("contract.pdf")
end
it "sends an update to the broadcasts channel" do
allow(BroadcastsChannel).to receive(:broadcast_file_upload_updates)
patch :update, params: { project_id: project.id, id: broadcast.id, broadcast: file_params }, xhr: true
expect(BroadcastsChannel).to have_received(:broadcast_file_upload_updates)
end
end
describe "#destroy" do
let!(:broadcast_2) { create(:broadcast, :with_stream, skip_create_callback: true, project: project, name: "Another Broadcast") }

View File

@@ -63,4 +63,55 @@ RSpec.describe ContractsController, type: :controller do
it_behaves_like "a contracts controller"
end
context "for medical releases" do
let(:native_releasable) { create(:medical_release_with_contract_template, :native) }
let(:non_native_releasable) { create(:medical_release_with_contract_template, :non_native) }
describe "#show when user is account manager" do
it_behaves_like "a contracts controller"
end
shared_examples "a medical contracts controller for non-authorized users" do
describe "#show" do
context "for a native release" do
it "responds with not authorized error" do
pdf_body = Tempfile.new
allow_any_instance_of(Contract).to receive(:to_pdf).and_return(pdf_body)
expect {
get :show, params: { format: :pdf, "#{native_releasable.model_name.singular}_id" => native_releasable }
}.to raise_exception(Pundit::NotAuthorizedError)
end
end
context "for a non-native release" do
it "responds with the attached contract" do
contract = double(:contract, service_url: "http://example.org/contract.pdf")
allow_any_instance_of(non_native_releasable.class).to receive(:contract).and_return(contract)
expect {
get :show, params: { format: :pdf, "#{non_native_releasable.model_name.singular}_id" => non_native_releasable }
}.to raise_exception(Pundit::NotAuthorizedError)
end
end
end
end
describe "#show when user is project manager" do
let(:manager_user) { create(:user, :manager) }
before do
sign_in manager_user
end
it_behaves_like "a medical contracts controller for non-authorized users"
end
describe "#show when user is associate" do
let(:associate_user) { create(:user, :associate) }
before do
sign_in associate_user
end
it_behaves_like "a medical contracts controller for non-authorized users"
end
end
end

View File

@@ -0,0 +1,91 @@
require "rails_helper"
RSpec.describe MedicalReleasesController, type: :controller do
render_views
let(:user) { create(:user) }
let(:account) { user.primary_account }
let(:project) { create(:project, account: user.primary_account) }
before do
sign_in user
end
describe "#index" do
it "responds successfully" do
get :index, params: { project_id: project }
expect(response).to be_successful
end
it "renders content" do
release = create(:medical_release, project: project,
person_first_name: "My",
person_last_name: "Release",
person_phone: "5551234567",
person_email: "jane.doe@test.com")
create(:note, notable: release, content: "Some notes here")
get :index, params: { project_id: project }
expect(response.body).to have_content "My Release"
expect(response.body).to have_content "Some notes here"
expect(response.body).to have_content "Manage"
end
context "when there are no medical releases" do
it "renders an empty message" do
get :index, params: { project_id: project }
expect(response.body).to have_content("Medical releases will appear here")
end
end
context "when there are many records" do
it "paginates the table" do
create_list(:medical_release, 20, project: project)
get :index, params: { project_id: project }
expect(response.body).to have_link("2", href: project_medical_releases_path(project, page: 2))
end
end
context "for xhr request" do
it "filters the releases by a query param" do
medical_releases = [
create(:medical_release, person_name: "Adam Sandler", project: project),
create(:medical_release, person_name: "Zoe Perry", project: project),
]
get :index, params: { project_id: project, query: "Zoe" }, xhr: true
expect(response.body).not_to have_content("Adam Sandler")
expect(response.body).to have_content("Zoe Perry")
end
end
end
describe "#destroy" do
let!(:medical_release) { create(:medical_release, project: project) }
it "responds with redirect" do
delete :destroy, params: { project_id: project, id: medical_release }
expect(response).to be_redirect
expect(response).to redirect_to [project, :medical_releases]
end
it "sets the flash" do
delete :destroy, params: { project_id: project, id: medical_release }
expect(flash.alert).not_to be_nil
end
it "destroys the record" do
expect {
delete :destroy, params: { project_id: project, id: medical_release }
}.to change(MedicalRelease, :count).by(-1)
end
end
end

View File

@@ -0,0 +1,116 @@
require "rails_helper"
RSpec.describe MiscReleasesController, type: :controller do
render_views
let(:user) { create(:user) }
let(:account) { user.primary_account }
let(:project) { create(:project, account: user.primary_account) }
before do
sign_in user
end
describe "#index" do
it "responds successfully" do
get :index, params: { project_id: project }
expect(response).to be_successful
end
it "renders content" do
release = create(:misc_release, project: project,
person_first_name: "My",
person_last_name: "Release",
person_phone: "5551234567",
person_email: "jane.doe@test.com")
create(:note, notable: release, content: "Some notes here")
get :index, params: { project_id: project }
expect(response.body).to have_content "My Release"
expect(response.body).to have_content "P: 5551234567"
expect(response.body).to have_content "jane.doe@test.com"
expect(response.body).to have_content "Some notes here"
expect(response.body).to have_content "Manage"
end
context "when there are no misc releases" do
it "renders an empty message" do
get :index, params: { project_id: project }
expect(response.body).to have_content("Misc Releases will appear here")
end
end
context "when there are many records" do
it "paginates the table" do
create_list(:misc_release, 20, project: project)
get :index, params: { project_id: project }
expect(response.body).to have_link("2", href: project_misc_releases_path(project, page: 2))
end
end
context "for xhr request" do
it "filters the releases by a query param" do
misc_releases = [
create(:misc_release, person_name: "Adam Sandler", project: project),
create(:misc_release, person_name: "Zoe Perry", project: project),
]
get :index, params: { project_id: project, query: "Zoe" }, xhr: true
expect(response.body).not_to have_content("Adam Sandler")
expect(response.body).to have_content("Zoe Perry")
end
end
end
describe "#destroy" do
let!(:misc_release) { create(:misc_release, project: project) }
it "responds with redirect" do
delete :destroy, params: { project_id: project, id: misc_release }
expect(response).to be_redirect
expect(response).to redirect_to [project, :misc_releases]
end
it "sets the flash" do
delete :destroy, params: { project_id: project, id: misc_release }
expect(flash.alert).not_to be_nil
end
it "destroys the record" do
expect {
delete :destroy, params: { project_id: project, id: misc_release }
}.to change(MiscRelease, :count).by(-1)
end
end
private
def misc_release_params
attributes_for(:misc_release).merge(exploitable_rights_params)
end
def minor_misc_release_params
attributes_for(:misc_release, :minor_with_guardian_photo).merge(exploitable_rights_params)
end
def exploitable_rights_params
{
applicable_medium_id: ApplicableMedium.last.id,
applicable_medium_text: "applicable_media",
territory_id: Territory.last.id,
territory_text: "territory",
term_id: Term.last.id,
term_text: "term",
restriction_id: Restriction.last.id,
restriction_text: "restrictions",
}
end
end

View File

@@ -56,6 +56,16 @@ RSpec.describe PasswordResetsController, type: :controller do
expect(response.body).to have_content("Password Reset")
expect(response.body).to have_selector("input[name='password_reset[password]']")
end
context "when reset token is invalid" do
it "redirects to the sign in page" do
get :edit, params: { id: "bad token" }
expect(response).to be_redirect
expect(response).to redirect_to(new_session_path)
expect(flash.notice).to be_present
end
end
end
describe "#update" do

View File

@@ -31,7 +31,7 @@ describe Public::AppearanceReleasesController do
contract_template = create(:contract_template, project: project)
sign_in(user)
post :create, params: { account_id: user.primary_account.to_param, project_id: project, contract_template_id: contract_template, appearance_release: { person_address: "Albuquerque" } }
post :create, params: { account_id: user.primary_account.to_param, project_id: project, contract_template_id: contract_template, appearance_release: { person_email: "email@email.com" } }
body = CGI.unescape_html(response.body)
expect(body).to match /Person first name can't be blank/
expect(body).to match /Person last name can't be blank/
@@ -120,7 +120,19 @@ describe Public::AppearanceReleasesController do
def minor_appearance_release_params(with_guardian_photo = true)
minor_type = with_guardian_photo ? :minor_with_guardian_photo : :minor
attributes_for(:appearance_release, minor_type).merge(signature_param)
attributes_for(:appearance_release, minor_type)
.merge(signature_param, guardian_address_params)
end
def guardian_address_params
{
guardian_address_street1: "St1",
guardian_address_street2: "St2",
guardian_address_city: "City",
guardian_address_state: "State",
guardian_address_zip: "ZIP",
guardian_address_country: "Country"
}
end
def signature_param

View File

@@ -92,6 +92,14 @@ RSpec.describe Public::BroadcastsController, type: :controller do
expect(broadcast.files.count).to eq(1)
expect(broadcast.files.first.filename).to eq("contract.pdf")
end
it "sends an update to the broadcasts channel" do
allow(BroadcastsChannel).to receive(:broadcast_file_upload_updates)
patch :update, params: { token: broadcast.token, broadcast: file_params }, xhr: true
expect(BroadcastsChannel).to have_received(:broadcast_file_upload_updates)
end
end
after do

View File

@@ -7,6 +7,15 @@ describe Public::LocationReleasesController do
render_views
describe "#create" do
it "allows photos param" do
contract_template = create(:contract_template, project: project)
post :create, params: { account_id: user.primary_account.to_param, project_id: project, contract_template_id: contract_template, location_release: location_release_params_with_photos }
expect(response).to be_successful
expect(LocationRelease.last.photos.attached?).to eq true
end
it "logs analytics" do
contract_template = create(:contract_template, project: project)
@@ -67,6 +76,10 @@ describe Public::LocationReleasesController do
attributes_for(:location_release, :native).except(:signature).merge(signature_param).merge(person_address_params)
end
def location_release_params_with_photos
attributes_for(:location_release, :native, :with_photo).except(:signature).merge(signature_param)
end
def person_address_params
{
person_address_street1: "123 Broadway",

View File

@@ -7,6 +7,15 @@ describe Public::MaterialReleasesController do
render_views
describe "#create" do
it "allows photos param" do
contract_template = create(:contract_template, project: project)
post :create, params: { account_id: user.primary_account.to_param, project_id: project, contract_template_id: contract_template, material_release: material_release_params_with_photos }
expect(response).to be_successful
expect(MaterialRelease.last.photos.attached?).to eq true
end
it "logs analytics" do
contract_template = create(:contract_template, project: project)
@@ -65,6 +74,11 @@ describe Public::MaterialReleasesController do
attributes_for(:material_release, :native).except(:signature).merge(signature_param)
end
def material_release_params_with_photos
attributes_for(:material_release, :native, :with_photo).except(:signature).merge(signature_param)
end
def signature_param
file = file_fixture("signature.png")
data_uri = Base64Image.from_image(file).data_uri

View File

@@ -0,0 +1,71 @@
require "rails_helper"
RSpec.describe Public::MedicalReleasesController, type: :controller do
let(:user) { create(:user) }
let(:project) { create(:project, account: user.primary_account) }
render_views
describe "#create" do
it "logs analytics" do
contract_template = create(:contract_template, project: project)
expect {
post :create, params: { account_id: project.account.to_param, project_id: project, contract_template_id: contract_template, medical_release: medical_release_params }
}.to(
have_enqueued_job(TrackAnalyticsJob)
.with(nil, nil, :track_create_native_release, release_type: "MedicalRelease", account: project.account, user_agent: "Rails Testing", user_ip: "0.0.0.0")
)
end
it "displays validation errors" do
contract_template = create(:contract_template, project: project)
sign_in(user)
post :create, params: { account_id: user.primary_account.to_param, project_id: project, contract_template_id: contract_template, medical_release: { person_address_city: "Albuquerque" } }
body = CGI.unescape_html(response.body)
expect(body).to match /Person first name can't be blank/
expect(body).to match /Person last name can't be blank/
expect(body).to match />can't be blank</
end
it "responds with success " do
contract_template = create(:contract_template, project: project)
post :create, params: { account_id: user.primary_account.to_param, project_id: project, contract_template_id: contract_template, medical_release: medical_release_params }
expect(response).to be_successful
end
it "runs attach contract to releasable job" do
contract_template = create(:contract_template, project: project)
expect {
post :create, params: { account_id: project.account.to_param, project_id: project, contract_template_id: contract_template, medical_release: medical_release_params }
}.to(
have_enqueued_job(AttachContractToReleasableJob)
.with(MedicalRelease.last)
)
end
end
private
def medical_release_params
attributes_for(:medical_release, :native).except(:signature).merge(signature_param, photos_param)
end
def photos_param
path = Rails.root.join("spec", "fixtures", "files", "person_photo.png")
photo = Rack::Test::UploadedFile.new(path, "image/png")
{ photos: [photo] }
end
def signature_param
file = file_fixture("signature.png")
data_uri = Base64Image.from_image(file).data_uri
{ signature_base64: data_uri }
end
end

View File

@@ -1,5 +1,4 @@
require 'rails_helper'
require 'zoom_gateway'
RSpec.describe Public::ZoomMeetingsController, type: :controller do
let(:user) { create(:user) }

View File

@@ -1,5 +1,4 @@
require 'rails_helper'
require 'zoom_gateway'
RSpec.describe ZoomMeetingsController, type: :controller do
let(:user) { create(:user) }

View File

@@ -1,75 +0,0 @@
require "rails_helper"
RSpec.describe ZoomNotificationsController, type: :controller do
render_views
let!(:zoom_meeting) { create(:zoom_meeting, api_meeting_id: 'meeting_id') }
let(:started_status) { {event: 'meeting.started', payload: {object: {id: 'meeting_id' }}} }
let(:ended_status) { {event: 'meeting.ended', payload: {object: {id: 'meeting_id' }}} }
let(:wrong_meeting_id) { {payload: {object: {id: 'wrong_id' }}} }
let(:authorization_header) { {'Authorization' => 'xxx-xxx-xxx'} }
let(:wrong_authorization_header) { {'Authorization' => 'yyy-yyy-yyy'} }
before do
allow(ENV).to receive(:[]).with('ZOOM_VERIFICATION_TOKEN').and_return('xxx-xxx-xxx')
end
describe '#create' do
context 'with no authorization key' do
it 'raises 403 response' do
post :create, params: started_status
expect(response).to have_http_status(403)
end
end
context 'with wrong authorization key' do
it 'raises 403 response' do
request.headers.merge!(wrong_authorization_header)
post :create, params: started_status
expect(response).to have_http_status(403)
end
end
context 'authorized' do
before do
request.headers.merge!(authorization_header)
end
context 'with wrong meeting id' do
it 'raises RecordNotFound' do
expect {
post :create, params: wrong_meeting_id
}.to raise_error(ActiveRecord::RecordNotFound)
end
end
context 'with right meeting id' do
it 'responds with 200' do
post :create, params: started_status
expect(response).to have_http_status(200)
end
it 'assigns the zoom meeting' do
post :create, params: started_status
expect(assigns(:zoom_meeting)).to eq(zoom_meeting)
end
it 'updates the zoom_meeting when started status is received in notification' do
post :create, params: started_status
expect(zoom_meeting.reload).to be_started
end
it 'updates the zoom_meeting when ended status is received in notification' do
post :create, params: ended_status
expect(zoom_meeting.reload).to be_ended
end
end
end
end
end

View File

@@ -0,0 +1,101 @@
require "rails_helper"
RSpec.describe ZoomNotificationsController, type: :controller do
render_views
let!(:zoom_meeting) { create(:zoom_meeting, api_meeting_id: 'meeting_id') }
let(:started_status) { {event: 'meeting.started', payload: {object: {id: 'meeting_id' }}} }
let(:ended_status) { {event: 'meeting.ended', payload: {object: {id: 'meeting_id' }}} }
let(:wrong_meeting_id) { {event: 'meeting.started', payload: {object: {id: 'wrong_id' }}} }
let(:recording_complete) { {event: 'recording.completed', payload: {object: {id: 'meeting_id', recording_files: [Object.new]}}} }
let(:authorization_header) { {'Authorization' => 'xxx-xxx-xxx'} }
let(:wrong_authorization_header) { {'Authorization' => 'yyy-yyy-yyy'} }
before do
allow(ENV).to receive(:[]).with('ZOOM_VERIFICATION_TOKEN').and_return('xxx-xxx-xxx')
end
describe '#create' do
context 'with no authorization key' do
it 'raises 403 response' do
post :create, params: started_status
expect(response).to have_http_status(403)
end
end
context 'with wrong authorization key' do
it 'raises 403 response' do
request.headers.merge!(wrong_authorization_header)
post :create, params: started_status
expect(response).to have_http_status(403)
end
end
context 'authorized' do
before do
request.headers.merge!(authorization_header)
end
context 'user hooks' do
before(:each) { ZoomUser.create api_id: 'zoom_user_id' }
it 'deletes the user from db if user.deleted is passed with existing user id' do
expect {
post :create, params: {event: 'user.deleted', payload: {object: {id: 'zoom_user_id'}}}
}.to change { ZoomUser.count }.by(-1)
end
it 'does not do anything if user.deleted is passed with non-existing user' do
expect {
post :create, params: {event: 'user.deleted', payload: {object: {id: 'wrong-user-id'}}}
}.not_to change { ZoomUser.count }
end
end
context 'meeting hooks' do
context 'with wrong meeting id' do
it 'raises RecordNotFound' do
expect {
post :create, params: wrong_meeting_id
}.to raise_error(ActiveRecord::RecordNotFound)
end
end
context 'with right meeting id' do
it 'responds with 200' do
post :create, params: started_status
expect(response).to have_http_status(200)
end
it 'assigns the zoom meeting' do
post :create, params: started_status
expect(assigns(:zoom_meeting)).to eq(zoom_meeting)
end
it 'updates the zoom_meeting when started status is received in notification' do
post :create, params: started_status
expect(zoom_meeting.reload).to be_started
end
it 'updates the zoom_meeting when ended status is received in notification' do
post :create, params: ended_status
expect(zoom_meeting.reload).to be_ended
end
it 'updates the recording when recording complete notification is received' do
expect(AttachRecordingToZoomMeetingJob).to receive(:perform_later)
post :create, params: recording_complete
end
end
end
end
end
end

View File

@@ -11,7 +11,12 @@ FactoryBot.define do
end
trait :native do
person_address "100 Test Lane, New York, NY 10001"
person_address_street1 "St1"
person_address_street2 "St2"
person_address_city "City"
person_address_state "State"
person_address_zip "ZIP"
person_address_country "Country"
person_phone "123-555-6789"
signature do
@@ -31,16 +36,28 @@ FactoryBot.define do
minor true
guardian_first_name "Jamie"
guardian_last_name "Doe"
guardian_address "100 Test Lane, New York, 10001"
guardian_address_street1 "St1"
guardian_address_street2 "St2"
guardian_address_city "City"
guardian_address_state "State"
guardian_address_zip "ZIP"
guardian_address_country "Country"
guardian_phone "123-555-1234"
guardian_email "guardian@galaxy.all"
end
trait :minor_with_guardian_photo do
minor true
guardian_first_name "Jamie"
guardian_last_name "Doe"
guardian_address "100 Test Lane, New York, 10001"
guardian_phone "123-555-1234"
guardian_email "guardian@galaxy.all"
guardian_address_street1 "St1"
guardian_address_street2 "St2"
guardian_address_city "City"
guardian_address_state "State"
guardian_address_zip "ZIP"
guardian_address_country "Country"
guardian_photo do
path = Rails.root.join("spec", "fixtures", "files", "pratt.jpg")
Rack::Test::UploadedFile.new(path, "image/jpeg")
@@ -65,5 +82,24 @@ FactoryBot.define do
appearance_release.contract_template = build(:appearance_release_contract_template)
end
end
factory :appearance_release_import do
person_photo nil
trait :with_headshot do
person_photo do
path = Rails.root.join("spec", "fixtures", "files", "person_photo.png")
Rack::Test::UploadedFile.new(path, "image/png")
end
end
trait :with_contract do
contract do
path = Rails.root.join("spec", "fixtures", "files", "AppearanceRelease.pdf")
Rack::Test::UploadedFile.new(path, "application/pdf")
end
end
end
end
end

View File

@@ -8,6 +8,10 @@ FactoryBot.define do
guardian_clause "Is the signer a minor?"
fee "$0.00"
trait :archived do
archived_at Time.zone.now
end
factory :appearance_release_contract_template do
release_type "appearance"
end
@@ -16,10 +20,18 @@ FactoryBot.define do
release_type "talent"
end
factory :medical_release_contract_template do
release_type "medical"
end
factory :material_release_contract_template do
release_type "material"
end
factory :misc_release_contract_template do
release_type "misc"
end
factory :location_release_contract_template do
release_type "location"
end

View File

@@ -15,6 +15,13 @@ FactoryBot.define do
end
end
trait :with_photo do
photos do
path = Rails.root.join("spec", "fixtures", "files", "location_photo.png")
[Rack::Test::UploadedFile.new(path, "image/png")]
end
end
trait :non_native do
contract do
path = Rails.root.join("spec", "fixtures", "files", "contract.pdf")

View File

@@ -15,6 +15,14 @@ FactoryBot.define do
end
end
trait :with_photo do
photos do
path = Rails.root.join("spec", "fixtures", "files", "material_photo.png")
[Rack::Test::UploadedFile.new(path, "image/png")]
end
end
trait :non_native do
contract do
path = Rails.root.join("spec", "fixtures", "files", "contract.pdf")

View File

@@ -0,0 +1,47 @@
FactoryBot.define do
factory :medical_release do
association :project
person_first_name "Jane"
person_last_name "Doe"
photos [Rack::Test::UploadedFile.new(Rails.root.join("spec", "fixtures", "files", "person_photo.png"), "image/png")]
trait :native do
person_phone "123-555-6789"
signature do
path = Rails.root.join("spec", "fixtures", "files", "signature.png")
Rack::Test::UploadedFile.new(path, "image/png")
end
end
trait :non_native do
contract do
path = Rails.root.join("spec", "fixtures", "files", "contract.pdf")
Rack::Test::UploadedFile.new(path, "application/pdf")
end
end
factory :medical_release_with_contract_template do
after(:build) do |medical_release, _|
medical_release.contract_template = build(:medical_release_contract_template)
end
end
factory :medical_release_with_contract_template_and_photos do
after(:build) do |medical_release, _|
medical_release.contract_template = build(:medical_release_contract_template)
path = Rails.root.join("spec", "fixtures", "files", "person_photo.png")
medical_release.photos.attach Rack::Test::UploadedFile.new(path, "image/png")
end
end
factory :medical_release_with_photo do
after(:build) do |medical_release, _|
path = Rails.root.join("spec", "fixtures", "files", "person_photo.png")
medical_release.photos.attach Rack::Test::UploadedFile.new(path, "image/png")
end
end
end
end

View File

@@ -0,0 +1,58 @@
FactoryBot.define do
factory :misc_release do
association :project
person_first_name "Jane"
person_last_name "Doe"
photos [Rack::Test::UploadedFile.new(Rails.root.join("spec", "fixtures", "files", "person_photo.png"), "image/png")]
trait :native do
person_phone "123-555-6789"
signature do
path = Rails.root.join("spec", "fixtures", "files", "signature.png")
Rack::Test::UploadedFile.new(path, "image/png")
end
end
trait :minor do
minor true
guardian_first_name "Jamie"
guardian_last_name "Doe"
guardian_phone "123-555-1234"
end
trait :minor_with_guardian_photo do
minor true
guardian_first_name "Jamie"
guardian_last_name "Doe"
guardian_phone "123-555-1234"
guardian_photo do
path = Rails.root.join("spec", "fixtures", "files", "pratt.jpg")
Rack::Test::UploadedFile.new(path, "image/jpeg")
end
end
factory :misc_release_with_contract_template do
after(:build) do |misc_release, _|
misc_release.contract_template = build(:misc_release_contract_template)
end
end
factory :misc_release_with_contract_template_and_photos do
after(:build) do |misc_release, _|
misc_release.contract_template = build(:misc_release_contract_template)
path = Rails.root.join("spec", "fixtures", "files", "person_photo.png")
misc_release.photos.attach Rack::Test::UploadedFile.new(path, "image/png")
end
end
factory :misc_release_with_photo do
after(:build) do |misc_release, _|
path = Rails.root.join("spec", "fixtures", "files", "person_photo.png")
misc_release.photos.attach Rack::Test::UploadedFile.new(path, "image/png")
end
end
end
end

View File

@@ -16,6 +16,7 @@ FactoryBot.define do
appearance_release: true,
location_release: true,
material_release: true,
medical_release: true,
music_release: true,
talent_release: true,
video_analysis: true,

View File

@@ -1,5 +1,8 @@
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

View File

@@ -103,4 +103,16 @@ feature "User creates notes" do
it_behaves_like "a notable collection UI"
end
context "for medical releases" do
subject! { create(:medical_release, project: project, notes: []) }
it_behaves_like "a notable collection UI"
end
context "for misc releases" do
subject! { create(:misc_release, project: project, notes: []) }
it_behaves_like "a notable collection UI"
end
end

View File

@@ -86,4 +86,16 @@ feature "User creates tags" do
it_behaves_like "a taggable collection UI"
end
context "for medical releases" do
subject! { create(:medical_release, project: project, tags: []) }
it_behaves_like "a taggable collection UI"
end
context "for misc releases" do
subject! { create(:misc_release, project: project, tags: []) }
it_behaves_like "a taggable collection UI"
end
end

View File

@@ -5,6 +5,7 @@ require 'rails_helper'
RSpec.feature 'User manages contract templates', type: :feature do
let(:current_user) { create(:user, :manager) }
let(:project) { create(:project, members: current_user, account: current_user.primary_account) }
let(:project2) { create(:project, members: current_user, account: current_user.primary_account, name: 'New project') }
before do
sign_in(current_user)
@@ -27,6 +28,18 @@ RSpec.feature 'User manages contract templates', type: :feature do
expect(page).to have_content('The release template has been created')
end
scenario 'medical release template has a guardian clause field' do
visit new_project_contract_template_path(project)
fill_in 'Name', with: 'My Release Template'
select 'Medical Release', from: 'Release type'
fill_hidden guardian_clause_field, with: 'Guardian clause text'
click_on 'Create Release Template'
expect(page).to have_content('The release template has been created')
expect(ContractTemplate.last.guardian_clause.body.to_s).to match /Guardian clause text/
end
scenario 'preview new talent release template without guardian clause' do
visit new_project_contract_template_path(project)
select 'Talent Release', from: 'Release type'
@@ -191,6 +204,21 @@ RSpec.feature 'User manages contract templates', type: :feature do
expect(page).not_to have_content('Test template')
end
scenario 'archived contract templates from other projects are not shown when importing contract templates' do
create(:contract_template, :archived, project: project2, name: 'Archived template')
create(:contract_template, project: project2, name: 'Active template')
create(:contract_template, project: project)
visit project_contract_templates_path(project)
expect(page).to have_content('Test template')
click_on import_template_button
expect(page).not_to have_content('Test template')
expect(page).not_to have_content('Archived template')
expect(page).to have_content('Active template')
end
context 'When the user is associate' do
let(:current_user) { create(:user, :associate) }
@@ -198,7 +226,7 @@ RSpec.feature 'User manages contract templates', type: :feature do
visit project_contract_templates_path(project)
expect(page).not_to have_content('Create New Release Template')
expect(page).not_to have_content('Import Release Template')
expect(page).not_to have_content(import_template_button)
expect(page).not_to have_content('Delete')
end
end
@@ -218,6 +246,14 @@ RSpec.feature 'User manages contract templates', type: :feature do
private
def import_template_button
t 'contract_templates.index.actions.import'
end
def import_selected_templates_button
t 'release_template_imports.new.actions.import'
end
def preview_heading
t 'blank_contracts.new.preview_heading'
end

View File

@@ -5,6 +5,13 @@ feature "User managing acquired_media releases" do
let(:project) { create(:project, members: current_user, account: current_user.primary_account) }
context "when signed out" do
scenario "United States is default country" do
contract_template = create(:contract_template, project: project)
visit new_account_project_contract_template_acquired_media_release_path(project.account, project, contract_template)
expect(country_field_value).to eq "US"
end
scenario "creating a release", js: true do
contract_template = create(:contract_template, project: project)
@@ -13,13 +20,24 @@ feature "User managing acquired_media releases" do
by "filling out the form" do
fill_in acquired_media_name_field, with: "Jane Doe"
acquired_media_category_fields
fill_in acquried_media_description_field, with: "Description"
fill_in acquried_media_owner_first_name, with: "Jane"
fill_in acquried_media_owner_last_name, with: "Doe"
fill_in acquired_media_person_title, with: "Ms."
fill_in acquired_media_person_phone, with: "555-5555-5555"
fill_in acquired_media_person_email, with: "person@example.com"
fill_in acquired_media_person_fax, with: "FAX"
fill_in acquired_media_person_address_street_1, with: "Street 1"
fill_in acquired_media_person_address_city, with: "City"
fill_in acquired_media_person_address_state, with: "State"
fill_in acquired_media_release_person_address_zip, with: "ZIP"
draw_signature file_fixture("signature.png"), "acquired_media_release_signature_base64"
end
click_button "I have read and agree to the above"
expect(AcquiredMediaRelease.last.categories).to include("Artwork")
expect(AcquiredMediaRelease.last.categories).to include("Video Footage")
expect(AcquiredMediaRelease.last.categories).to include("Still Photograph")
expect(page).to have_content("Your release was successfully submitted. Thank you.")
end
@@ -205,12 +223,60 @@ feature "User managing acquired_media releases" do
private
def country_field_value
find_field("acquired_media_release[person_address_country]").value
end
def acquired_media_name_field
"acquired_media_release[name]"
end
def acquried_media_description_field
"acquired_media_release[description]"
end
def acquried_media_owner_first_name
"acquired_media_release[person_first_name]"
end
def acquried_media_owner_last_name
"acquired_media_release[person_last_name]"
end
def acquired_media_person_title
"acquired_media_release[person_title]"
end
def acquired_media_person_phone
"acquired_media_release[person_phone]"
end
def acquired_media_person_email
"acquired_media_release[person_email]"
end
def acquired_media_person_fax
"acquired_media_release[person_fax]"
end
def acquired_media_person_address_street_1
"acquired_media_release[person_address_street1]"
end
def acquired_media_person_address_city
"acquired_media_release[person_address_city]"
end
def acquired_media_person_address_state
"acquired_media_release[person_address_state]"
end
def acquired_media_release_person_address_zip
"acquired_media_release[person_address_zip]"
end
def acquired_media_category_fields
find(:css, "#acquired_media_release_categories_artwork").set(true)
find(:css, "#acquired_media_release_categories_video_footage").set(true)
find(:css, "#acquired_media_release_categories_still_photograph").set(true)
end

View File

@@ -19,13 +19,13 @@ feature 'User managing appearance releases' do
fill_in person_first_name_field, with: 'Jane'
fill_in person_last_name_field, with: 'Doe'
fill_in person_address_field, with: '123 Test Lane, New York, NY 10000'
fill_in_person_address_fields
fill_in person_phone_field, with: '555-555-5555'
fill_in person_email_field, with: 'jane.doe@test.com'
fill_in person_date_of_birth, with: '01/01/1999'
attach_file person_photo_field, file_fixture('person_photo.png'), visible: :all
draw_signature file_fixture('signature.png'), 'appearance_release_signature_base64'
click_button 'I have read and agree to the above'
click_button submit_release_button
expect(page).to have_content(successful_submission_message)
end
@@ -45,23 +45,88 @@ feature 'User managing appearance releases' do
page.check person_is_minor_checkbox
expect(page).to have_content('GUARDIAN INFORMATION')
expect(page).to have_content('GUARDIAN PHOTO')
expect(page).to have_content 'Guardian Email'
fill_in guardian_first_name_field, with: 'Guardian'
fill_in guardian_last_name_field, with: 'Name'
fill_in guardian_phone_field, with: '001101'
fill_in person_first_name_field, with: 'Jane'
fill_in person_last_name_field, with: 'Doe'
fill_in person_address_field, with: '123 Test Lane, New York, NY 10000'
fill_in_person_address_fields
fill_in person_phone_field, with: '555-555-5555'
fill_in person_email_field, with: 'jane.doe@test.com'
fill_in person_date_of_birth, with: '01/01/1999'
attach_file person_photo_field, file_fixture('person_photo.png'), visible: :all
attach_file guardian_photo_field, file_fixture('hemsworth.jpeg'), visible: :all
draw_signature file_fixture('signature.png'), 'appearance_release_signature_base64'
click_button 'I have read and agree to the above'
fill_in guardian_email_field, with: 'invalid@email'
click_button submit_release_button
expect(page).to have_content('Guardian email is not an email')
fill_in guardian_email_field, with: 'valid@email.com'
fill_in_guardian_address_fields
attach_file guardian_photo_field, file_fixture('hemsworth.jpeg'), visible: :all
draw_signature file_fixture('signature.png'), 'appearance_release_signature_base64'
click_button submit_release_button
expect(page).to have_content(successful_submission_message)
end
scenario 'creating a release for a minor with two guardians', js: true do
allow(BrayniacAI::Validation).to receive(:create).and_return(double(:validation, valid: true))
project = create(:project, members: current_user, account: current_user.primary_account)
contract_template = create(:contract_template, project: project)
visit new_account_project_contract_template_appearance_release_path(project.account, project, contract_template)
expect(page).to have_photo_button
expect(page).not_to have_content('SECOND GUARDIAN INFORMATION')
expect(page).not_to have_content('SECOND GUARDIAN PHOTO')
page.check person_is_minor_checkbox
expect(page).to have_content('GUARDIAN INFORMATION')
expect(page).to have_content('GUARDIAN PHOTO')
expect(page).to have_content 'Guardian Email'
expect(page).to have_content 'SECOND GUARDIAN INFORMATION'
expect(page).to have_content 'SECOND GUARDIAN PHOTO'
expect(page).to have_content 'Guardian 2 Email'
expect(page).to have_content 'Guardian 2 Phone'
expect(page).to have_content 'Guardian 2 Address'
fill_in guardian_first_name_field, with: 'Guardian'
fill_in guardian_last_name_field, with: 'Name'
fill_in guardian_phone_field, with: '001101'
fill_in person_first_name_field, with: 'Jane'
fill_in person_last_name_field, with: 'Doe'
fill_in_person_address_fields
fill_in person_phone_field, with: '555-555-5555'
fill_in person_email_field, with: 'jane.doe@test.com'
fill_in person_date_of_birth, with: '01/01/1999'
attach_file person_photo_field, file_fixture('person_photo.png'), visible: :all
attach_file guardian_photo_field, file_fixture('hemsworth.jpeg'), visible: :all
draw_signature file_fixture('signature.png'), 'appearance_release_signature_base64'
fill_in guardian_email_field, with: 'invalid@email'
click_button submit_release_button
expect(page).to have_content('Guardian email is not an email')
fill_in guardian_email_field, with: 'valid@email.com'
fill_in_guardian_address_fields
attach_file guardian_photo_field, file_fixture('hemsworth.jpeg'), visible: :all
draw_signature file_fixture('signature.png'), 'appearance_release_signature_base64'
fill_in guardian_2_first_name_field, with: 'Second'
fill_in guardian_2_last_name_field, with: 'Guardian'
fill_in guardian_2_phone_field, with: '999'
click_button submit_release_button
expect(page).to have_content(successful_submission_message)
expect(AppearanceRelease.last.guardian_2_first_name).to eq 'Second'
end
end
context 'when signed in' do
@@ -129,49 +194,48 @@ feature 'User managing appearance releases' do
expect(page).to have_content 'New Jane'
end
scenario 'user can enter information for second guardian when editing non native release for minor', js: true do
appearance_release = create(:appearance_release, :non_native, :minor, project: project)
visit edit_appearance_release_path(appearance_release)
expect(page).to have_content guardian_2_first_name_field.titleize
expect(page).to have_content guardian_2_photo_heading
fill_in guardian_first_name_field, with: 'Guardian'
fill_in guardian_last_name_field, with: 'Name'
attach_file guardian_photo_field, file_fixture('hemsworth.jpeg'), visible: :all
fill_in guardian_2_first_name_field, with: 'Second'
fill_in guardian_2_last_name_field, with: 'guardian'
attach_file guardian_2_photo_field, file_fixture('person_photo.png'), visible: :all
click_button submit_update_button
expect(page).to have_content successful_update_message
expect(AppearanceRelease.last.guardian_2_photo.attached?).to eq true
end
scenario 'progress bar shows when user imports a release', js: true do
skip "TODO"
visit project_appearance_releases_path(project)
expect(page).not_to have_css('#upload-progress-container')
large_pdf_file = build_large_pdf_file
attach_file import_appearance_release_field, Rails.root.join(large_pdf_file.path), visible: false
expect(page).to have_css('#upload-progress-container')
expect(page).to have_content submit_create_button, wait: 30
click_button submit_create_button
expect(page).to have_content matching_started
end
scenario 'MatchAppearanceReleasesJob is started when import is finished', js: true do
visit project_appearance_releases_path(project)
attach_file import_appearance_release_field, Rails.root.join(file_fixture('person_photo.png')), visible: false
expect(page).to have_content importing_label
allow(MatchAppearanceReleasesJob).to receive(:perform_later).with(project, anything)
click_button submit_create_button
expect(page).to have_css('.progress')
end
scenario 'importing a releases works when image is selected', js: true do
expect(page).to have_content matching_started
visit project_appearance_releases_path(project)
expect(page).to have_content submit_create_button
expect(page).to have_content no_appearance_releases
attach_file import_appearance_release_field, Rails.root.join(file_fixture('person_photo.png')), visible: false
expect(page).to have_content importing_label
click_button submit_create_button
expect(page).not_to have_content no_appearance_releases
expect(page).to have_content /Imported Headshot\s+\d{7}/
end
scenario 'importing a releases works when pdf is selected', js: true do
visit project_appearance_releases_path(project)
expect(page).to have_content submit_create_button
expect(page).to have_content no_appearance_releases
attach_file import_appearance_release_field, Rails.root.join(file_fixture('contract.pdf')), visible: false
expect(page).to have_content importing_label
click_button submit_create_button
expect(page).not_to have_content no_appearance_releases
expect(page).to have_content /Imported Contract\s+\d{7}/
end
scenario 'importing a releases fails when file other than image or pdf is selected', js: true do
visit project_appearance_releases_path(project)
expect(page).to have_content submit_create_button
expect(page).to have_content no_appearance_releases
attach_file import_appearance_release_field, Rails.root.join(file_fixture('audio.mp3')), visible: false
expect(page).to have_content importing_label
click_button submit_create_button
expect(page).to have_content failed_to_import_notice
expect(page).to have_content no_appearance_releases
end
@@ -249,6 +313,7 @@ feature 'User managing appearance releases' do
expect(pdf_body).to have_content('TAGS')
expect(pdf_body).to have_content('Woman')
expect(pdf_body).to have_content('Brunette')
expect(pdf_body).not_to have_content('Guardian Email')
end
scenario 'viewing contract PDF for a minor without guardian photo' do
@@ -262,8 +327,10 @@ feature 'User managing appearance releases' do
expect(pdf_filename).to include(appearance_release.filename_suffix.parameterize)
expect(pdf_body).to have_content(appearance_release.name)
expect(pdf_body).to have_content(appearance_release.guardian_name)
expect(pdf_body).to have_content(appearance_release.guardian_email)
expect(pdf_body).to have_content photos_heading.upcase
expect(pdf_body).to have_content(appearance_release.photo.filename.to_s)
expect(pdf_body).to have_content('Guardian Email')
end
scenario 'viewing contract PDF for a minor with guardian photo' do
@@ -277,9 +344,11 @@ feature 'User managing appearance releases' do
expect(pdf_filename).to include(appearance_release.filename_suffix.parameterize)
expect(pdf_body).to have_content(appearance_release.name)
expect(pdf_body).to have_content(appearance_release.guardian_name)
expect(pdf_body).to have_content(appearance_release.guardian_email)
expect(pdf_body).to have_content photos_heading(2).upcase
expect(pdf_body).to have_content(appearance_release.photo.filename.to_s)
expect(pdf_body).to have_content(appearance_release.guardian_photo.filename.to_s)
expect(pdf_body).to have_content('Guardian Email')
end
scenario 'deleting a release', js: true do
@@ -422,6 +491,10 @@ feature 'User managing appearance releases' do
tempfile
end
def matching_started
t 'appearance_releases.create.matching_started'
end
def filter_type_all
t 'appearance_releases.type_filter_actions.all_releases'
end
@@ -458,6 +531,18 @@ feature 'User managing appearance releases' do
'appearance_release_minor'
end
def guardian_2_first_name_field
'Guardian 2 first name'
end
def guardian_2_last_name_field
'Guardian 2 last name'
end
def guardian_2_phone_field
'Guardian 2 phone'
end
def guardian_first_name_field
'Guardian first name'
end
@@ -470,24 +555,74 @@ feature 'User managing appearance releases' do
'Guardian phone'
end
def guardian_email_field
'Guardian email'
end
def guardian_address_street1_field
t('helpers.label.appearance_release.guardian_address_street1')
end
def guardian_address_city_field
t('helpers.label.appearance_release.guardian_address_city')
end
def guardian_address_state_field
t('helpers.label.appearance_release.guardian_address_state')
end
def guardian_address_zip_field
t('helpers.label.appearance_release.guardian_address_zip')
end
def guardian_photo_field
'appearance_release[guardian_photo]'
end
def guardian_2_photo_field
'appearance_release[guardian_2_photo]'
end
def person_name_field
t('helpers.label.appearance_release.person_name')
end
def person_first_name_field
'Person first name'
t('helpers.label.appearance_release.person_first_name')
end
def person_last_name_field
'Person last name'
t('helpers.label.appearance_release.person_last_name')
end
def person_address_field
t('helpers.label.appearance_release.person_address')
def fill_in_person_address_fields
fill_in person_address_street1_field, with: "123 Test Lane"
fill_in person_address_city_field, with: "New York"
fill_in person_address_state_field, with: "NY"
fill_in person_address_zip_field, with: '1000'
end
def fill_in_guardian_address_fields
fill_in guardian_address_street1_field, with: "124 Test Lane"
fill_in guardian_address_city_field, with: "New York"
fill_in guardian_address_state_field, with: "NY"
fill_in guardian_address_zip_field, with: '1000'
end
def person_address_street1_field
t('helpers.label.appearance_release.person_address_street1')
end
def person_address_city_field
t('helpers.label.appearance_release.person_address_city')
end
def person_address_state_field
t('helpers.label.appearance_release.person_address_state')
end
def person_address_zip_field
t('helpers.label.appearance_release.person_address_zip')
end
def person_email_field
@@ -518,6 +653,10 @@ feature 'User managing appearance releases' do
'Import Release'
end
def submit_release_button
'I have read and agree to the above'
end
def submit_update_button
'Save Changes'
end
@@ -549,4 +688,12 @@ feature 'User managing appearance releases' do
def successful_destroy_message
'The release has been deleted'
end
def guardian_photo_heading
t 'appearance_releases.form.photos.guardian_photo.heading'
end
def guardian_2_photo_heading
t 'appearance_releases.form.photos.guardian_2_photo.heading'
end
end

View File

@@ -1,83 +1,154 @@
require "rails_helper"
# frozen_string_literal: true
feature "User managing broadcasts" do
require 'rails_helper'
feature 'User managing broadcasts' do
let(:current_user) { create(:user, :manager) }
let(:project) { create(:project, members: current_user, account: current_user.primary_account) }
context "managing broadcasts" do
context 'managing broadcasts' do
before do
sign_in current_user
allow(MuxLiveStream).to receive(:new).and_return(double(id: "id", key: "key", playback_id: "playback_id"))
allow(MuxLiveStream).to receive(:new).and_return(double(id: 'id', key: 'key', playback_id: 'playback_id'))
end
scenario "creating and deleting a broadcast", js: true do
scenario 'creating and deleting a broadcast', js: true do
visit new_project_broadcast_path(project)
by "filling out the form" do
fill_in broadcast_name_field, with: "My Broadcast"
by 'filling out the form' do
fill_in broadcast_name_field, with: 'My Broadcast'
end
click_button "Create Live Stream"
expect(page).to have_content("A live stream has been created")
click_on "Manage"
expect(page).to have_link("Copy Stream URL", exact: true)
expect(page).to have_link("Copy Stream Key", exact: true)
expect(page).to have_link("View", exact: true)
expect(page).to have_link("Delete", exact: true)
click_button 'Create Live Stream'
expect(page).to have_content('A live stream has been created')
click_on 'Manage'
expect(page).to have_link('Copy Stream URL', exact: true)
expect(page).to have_link('Copy Stream Key', exact: true)
expect(page).to have_link('View', exact: true)
expect(page).to have_link('Delete', exact: true)
it_also "Deletes the broadcast" do
it_also 'Deletes the broadcast' do
allow_any_instance_of(Broadcast).to receive(:destroy_mux_live_stream).and_return(true)
accept_alert do
click_link "Delete"
click_link 'Delete'
end
expect(page).to have_content("A live stream has been deleted")
expect(page).not_to have_content("My Broadcast")
expect(page).to have_content('A live stream has been deleted')
expect(page).not_to have_content('My Broadcast')
end
end
scenario "visit show page of broadcast", js: true do
scenario 'visit show page of broadcast', js: true do
broadcast = create(:broadcast, :with_stream, :with_files, project: project)
recording = create(:broadcast_recording, broadcast: broadcast)
visit project_broadcast_path(project, broadcast)
expect(page).to have_content("Live stream is waiting to begin.")
expect(page).to have_content("Copy URL")
click_on "Files"
expect(page).to have_content("contract.pdf")
expect(page).to have_content('Live stream is waiting to begin.')
expect(page).to have_content('Copy URL')
click_on "Previous Sessions"
within '#files' do
expect(page).to have_content('contract.pdf')
end
click_on 'Previous Sessions'
expect(page).to have_content(recording.download_file_name)
end
scenario "visit multi-view broadcast page", js: true do
broadcasts = create_list(:broadcast, 4, :with_stream, project: project)
scenario 'user can go back and forth between live session and previous sessions', js: true do
broadcast = create(:broadcast, :with_stream, :with_files, project: project)
recording = create(:broadcast_recording, broadcast: broadcast)
visit project_broadcast_path(project, broadcast)
expect(page).to have_content broadcast.name.titleize, count: 1
expect(page).to have_content recording.download_file_name, count: 0
click_on switch_view_dropdown
expect(page).to have_content broadcast.name.titleize, count: 2
expect(page).to have_content recording.download_file_name, count: 1
live_stream_nav_item = page.find('.dropdown-item', text: broadcast.name.titleize)
recording_nav_item = page.find('.dropdown-item', text: recording.download_file_name)
expect(live_stream_nav_item[:class].include?('active')).to eq true
expect(recording_nav_item[:class].include?('active')).to eq false
click_on recording.download_file_name
expect(page).to have_content broadcast.name.titleize, count: 1
expect(page).to have_content recording.download_file_name, count: 0
expect(live_stream_nav_item[:class].include?('active')).to eq false
expect(recording_nav_item[:class].include?('active')).to eq true
click_on switch_view_dropdown
click_on broadcast.name.titleize
expect(page).to have_content broadcast.name.titleize, count: 1
expect(page).to have_content recording.download_file_name, count: 0
# Page is reloaded, we need to get dropdown items again
live_stream_nav_item = page.find('.dropdown-item', text: broadcast.name.titleize, visible: :all)
recording_nav_item = page.find('.dropdown-item', text: recording.download_file_name, visible: :all)
expect(live_stream_nav_item[:class].include?('active')).to eq true
expect(recording_nav_item[:class].include?('active')).to eq false
end
scenario 'form will not submit if user clicks Add files without selected files', js: true do
broadcast = create(:broadcast, :with_stream, :with_files, project: project)
visit project_broadcast_path(project, broadcast)
expect(page).to have_content('Live stream is waiting to begin.')
expect(page).to have_content add_file_button
click_on add_file_button
end
scenario 'visit multi-view broadcast page', js: true do
broadcast_one = create(:broadcast, :with_stream, :with_files, name: 'Broadcast 1', project: project)
broadcast_two = create(:broadcast, :with_stream, :with_files, name: 'Broadcast 2', project: project)
visit project_broadcasts_path(project)
click_checkboxes
new_window = window_opened_by { click_link "Multi-View" }
within_window new_window do
expect(page).to have_content("Switch View")
click_on "Switch View"
expect(page).to have_link(broadcasts.first.name)
expect(page).to have_link(broadcasts.second.name)
end
new_window = window_opened_by { click_link 'Multi-View' }
within_window new_window do
expect(page).to have_content switch_view_dropdown
click_on switch_view_dropdown
expect(page).to have_link('Broadcast 1')
expect(page).to have_link('Broadcast 2')
within '#files' do
click_on 'Broadcast 1'
expect(page).to have_content('contract.pdf')
click_on 'Broadcast 2'
expect(page).to have_content('contract.pdf')
end
end
end
end
private
def add_file_button
'Add File'
end
def broadcast_name_field
"broadcast[name]"
'broadcast[name]'
end
def click_checkboxes
all('input[type="checkbox"]')[0].click
all('input[type="checkbox"]')[1].click
all('input[type="checkbox"]')[2].click
end
def switch_view_dropdown
'Switch View'
end
end

View File

@@ -5,25 +5,72 @@ feature "User managing location releases" do
let(:project) { create(:project, members: current_user, account: current_user.primary_account) }
context "when signed out" do
scenario "creating a release", js: true do
scenario "United States is default country" do
contract_template = create(:contract_template, project: project)
visit new_account_project_contract_template_location_release_path(project.account, project, contract_template)
expect(country_field_value).to eq "US"
end
scenario "creating a release without photos", js: true do
contract_template = create(:contract_template, project: project)
visit new_account_project_contract_template_location_release_path(project.account, project, contract_template)
by "filling out the form" do
fill_in location_name_field, with: "Benny's Burritos"
fill_in location_address_street_1, with: "Location's street address"
fill_in location_address_city, with: "Location's city"
fill_in location_address_state, with: "Location's state"
fill_in location_address_zip, with: "Location's zip"
fill_in person_first_name_field, with: "Jane"
fill_in person_last_name_field, with: "Doe"
fill_in person_phone_field, with: "555-555-5555"
fill_in person_email_field, with: "jane.doe@test.com"
fill_in person_company_field, with: "BIG"
fill_in person_title_field, with: "Ms."
fill_in person_address_street1_field, with: "100 Broadway"
fill_in person_address_city, with: "Person's City"
fill_in person_address_state, with: "Person's State"
fill_in person_address_zip, with: "Person's Zip"
fill_in filming_hours_field, with: "04:00 - 22:00"
draw_signature file_fixture("signature.png"), "location_release_signature_base64"
end
click_button "I have read and agree to the above"
click_button submit_release_button
expect(page).to have_content("Your release was successfully submitted. Thank you.")
end
scenario "creating a release with photos", js: true do
contract_template = create(:contract_template, project: project)
visit new_account_project_contract_template_location_release_path(project.account, project, contract_template)
fill_in location_name_field, with: "Benny's Burritos"
fill_in location_address_street_1, with: "Location's street address"
fill_in location_address_city, with: "Location's city"
fill_in location_address_state, with: "Location's state"
fill_in location_address_zip, with: "Location's zip"
fill_in person_first_name_field, with: "Jane"
fill_in person_last_name_field, with: "Doe"
fill_in person_phone_field, with: "555-555-5555"
fill_in person_email_field, with: "jane.doe@test.com"
fill_in person_company_field, with: "BIG"
fill_in person_title_field, with: "Ms."
fill_in person_address_street1_field, with: "100 Broadway"
fill_in person_address_city, with: "Person's City"
fill_in person_address_state, with: "Person's State"
fill_in person_address_zip, with: "Person's Zip"
fill_in filming_hours_field, with: "04:00 - 22:00"
draw_signature file_fixture("signature.png"), "location_release_signature_base64"
drop_file Rails.root.join(file_fixture("location_photo.png")), type: :dropzone
click_button submit_release_button
expect(page).to have_content("Your release was successfully submitted. Thank you.")
expect(LocationRelease.last.photos.attached?).to eq true
end
end
context "when signed in" do
@@ -51,6 +98,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 +184,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 +221,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
@@ -190,6 +241,10 @@ feature "User managing location releases" do
private
def country_field_value
find_field("location_release[person_address_country]").value
end
def photos_heading(photos_count = 1)
t 'contracts.photos.heading', count: photos_count
end
@@ -198,6 +253,22 @@ feature "User managing location releases" do
"location_release[name]"
end
def location_address_street_1
"location_release[address_street1]"
end
def location_address_city
"location_release[address_city]"
end
def location_address_state
"location_release[address_state]"
end
def location_address_zip
"location_release[address_zip]"
end
def contract_field
"location_release[contract]"
end
@@ -210,18 +281,42 @@ feature "User managing location releases" do
"location_release[person_last_name]"
end
def person_email_field
"location_release[person_email]"
end
def person_address_street1_field
"location_release[person_address_street1]"
end
def person_address_city
"location_release[person_address_city]"
end
def person_address_state
"location_release[person_address_state]"
end
def person_address_zip
"location_release[person_address_zip]"
end
def person_phone_field
"location_release[person_phone]"
end
def person_email_field
"location_release[person_email]"
end
def person_company_field
"location_release[person_company]"
end
def person_title_field
"location_release[person_title]"
end
def filming_hours_field
"location_release[filming_hours]"
end
def have_photo(filename, attr: "src")
have_selector("img[#{attr}*='#{filename}']")
end
@@ -246,6 +341,10 @@ feature "User managing location releases" do
t "helpers.submit.location_release.create"
end
def submit_release_button
t("shared.submit_release_long")
end
def create_release_notice
t "location_releases.create.notice"
end

View File

@@ -5,21 +5,84 @@ feature "User managing material releases" do
let(:project) { create(:project, members: current_user, account: current_user.primary_account) }
context "when signed out" do
scenario "creating a release", js: true do
scenario "United States is default country" do
contract_template = create(:contract_template, project: project)
visit new_account_project_contract_template_material_release_path(project.account, project, contract_template)
expect(country_field_value).to eq "US"
end
scenario "creating a release without photos", js: true do
contract_template = create(:contract_template, project: project)
visit new_account_project_contract_template_material_release_path(project.account, project, contract_template)
by "filling out the form" do
fill_in material_name_field, with: "Pepsi Logo"
fill_in person_first_name_field, with: "Jane"
fill_in person_last_name_field, with: "Doe"
draw_signature file_fixture("signature.png"), "material_release_signature_base64"
end
fill_all_fields
draw_signature file_fixture("signature.png"), "material_release_signature_base64"
click_button "I have read and agree to the above"
click_button submit_release_button
expect(page).to have_content("Your release was successfully submitted. Thank you.")
expect(page).to have_content success_submit_message
end
scenario "creating a release with photos", js: true do
contract_template = create(:contract_template, project: project)
visit new_account_project_contract_template_material_release_path(project.account, project, contract_template)
fill_all_fields
draw_signature file_fixture("signature.png"), "material_release_signature_base64"
drop_file Rails.root.join(file_fixture("material_photo.png")), type: :dropzone
click_button submit_release_button
expect(page).to have_content success_submit_message
expect(MaterialRelease.last.photos.attached?).to eq true
end
scenario "creating release is possible only after filling all fields", js: true do
contract_template = create(:contract_template, project: project)
visit new_account_project_contract_template_material_release_path(project.account, project, contract_template)
fill_in material_name_field, with: "Pepsi Logo"
expect_failed_client_side_validation
fill_in material_description_field, with: "Description text"
expect_failed_client_side_validation
fill_in person_first_name_field, with: "Jane"
expect_failed_client_side_validation
fill_in person_last_name_field, with: "Doe"
expect_failed_client_side_validation
fill_in person_phone_field, with: "2229929229"
expect_failed_client_side_validation
fill_in person_email_field, with: "mail@mail.com"
expect_failed_client_side_validation
fill_in person_company_field, with: "Company"
expect_failed_client_side_validation
fill_in person_title_field, with: "Mr."
expect_failed_client_side_validation
fill_in person_address_street1_field, with: "Street 1 address"
expect_failed_client_side_validation
fill_in person_city_field, with: "City"
expect_failed_client_side_validation
fill_in person_state_field, with: "State"
expect_failed_client_side_validation
fill_in person_zip_field, with: "ZIP"
draw_signature file_fixture("signature.png"), "material_release_signature_base64"
click_button submit_release_button
expect(page).to have_content success_submit_message
end
end
@@ -180,6 +243,10 @@ feature "User managing material releases" do
private
def country_field_value
find_field("material_release[person_address_country]").value
end
def photos_heading(photos_count = 1)
t 'contracts.photos.heading', count: photos_count
end
@@ -188,6 +255,10 @@ feature "User managing material releases" do
"material_release[name]"
end
def material_description_field
"material_release[description]"
end
def person_first_name_field
"material_release[person_first_name]"
end
@@ -196,6 +267,38 @@ feature "User managing material releases" do
"material_release[person_last_name]"
end
def person_phone_field
"material_release[person_phone]"
end
def person_email_field
"material_release[person_email]"
end
def person_company_field
"material_release[person_company]"
end
def person_title_field
"material_release[person_title]"
end
def person_address_street1_field
"material_release[person_address_street1]"
end
def person_city_field
"material_release[person_address_city]"
end
def person_state_field
"material_release[person_address_state]"
end
def person_zip_field
"material_release[person_address_zip]"
end
def have_photo(filename)
have_selector("img[src*='#{filename}']")
end
@@ -224,6 +327,10 @@ feature "User managing material releases" do
t "helpers.submit.material_release.create"
end
def submit_release_button
t 'shared.submit_release_long'
end
def create_release_notice
t "material_releases.create.notice"
end
@@ -250,4 +357,29 @@ feature "User managing material releases" do
select "Other", from: "Restriction"
fill_in "Describe other restrictions", with: "Test"
end
def fill_all_fields
fill_in material_name_field, with: "Pepsi Logo"
fill_in material_description_field, with: "Description text"
fill_in person_first_name_field, with: "Jane"
fill_in person_last_name_field, with: "Doe"
fill_in person_phone_field, with: "2229929229"
fill_in person_email_field, with: "mail@mail.com"
fill_in person_company_field, with: "Company"
fill_in person_title_field, with: "Mr."
fill_in person_address_street1_field, with: "Street 1 address"
fill_in person_city_field, with: "City"
fill_in person_state_field, with: "State"
fill_in person_zip_field, with: "ZIP"
end
def success_submit_message
'Your release was successfully submitted. Thank you.'
end
def expect_failed_client_side_validation
draw_signature file_fixture("signature.png"), "material_release_signature_base64"
click_button submit_release_button
expect(page).not_to have_content success_submit_message
end
end

View File

@@ -0,0 +1,399 @@
require "rails_helper"
feature "User managing medical releases" do
let(:current_user) { create(:user) }
let(:project) { create(:project, members: current_user, account: current_user.primary_account) }
context "when signed out" do
scenario 'creating a release for an adult', js: true do
allow(BrayniacAI::Validation).to receive(:create).and_return(double(:validation, valid: true))
project = create(:project, members: current_user, account: current_user.primary_account)
contract_template = create(:contract_template, project: project)
visit new_account_project_contract_template_medical_release_path(project.account, project, contract_template)
fill_in person_first_name_field, with: 'Jane'
fill_in person_last_name_field, with: 'Doe'
fill_in_person_address_fields
fill_in person_phone_field, with: '555-555-5555'
fill_in person_email_field, with: 'jane.doe@test.com'
drop_file Rails.root.join(file_fixture("person_photo.png")), type: :dropzone
draw_signature file_fixture("signature.png"), "medical_release_signature_base64"
expect do
click_button submit_release_button
end.to change(MedicalRelease, :count).by(1)
expect(page).to have_content(successful_submission_message)
end
scenario 'creating a release for a minor', js: true do
allow(BrayniacAI::Validation).to receive(:create).and_return(double(:validation, valid: true))
project = create(:project, members: current_user, account: current_user.primary_account)
contract_template = create(:contract_template, project: project)
visit new_account_project_contract_template_medical_release_path(project.account, project, contract_template)
expect(page).not_to have_content guardian_information_heading.upcase
expect(page).not_to have_content guardian_photo_heading.upcase
page.check person_is_minor_checkbox
expect(page).to have_content guardian_information_heading.upcase
expect(page).to have_content guardian_photo_heading.upcase
expect(page).to have_content guardian_email_field.titleize
fill_in guardian_first_name_field, with: 'Guardian'
fill_in guardian_last_name_field, with: 'Name'
fill_in guardian_phone_field, with: '001101'
fill_in person_first_name_field, with: 'Jane'
fill_in person_last_name_field, with: 'Doe'
fill_in_person_address_fields
fill_in person_phone_field, with: '555-555-5555'
fill_in person_email_field, with: 'jane.doe@test.com'
drop_file Rails.root.join(file_fixture("person_photo.png")), type: :dropzone
attach_file guardian_photo_field, file_fixture('hemsworth.jpeg'), visible: :all
draw_signature file_fixture('signature.png'), 'medical_release_signature_base64'
fill_in guardian_email_field, with: 'invalid@email'
click_button submit_release_button
expect(page).to have_content email_validation_error_for('Guardian')
fill_in guardian_email_field, with: 'valid@email.com'
fill_in_guardian_address_fields
attach_file guardian_photo_field, file_fixture('hemsworth.jpeg'), visible: :all
draw_signature file_fixture('signature.png'), 'medical_release_signature_base64'
click_button submit_release_button
expect(page).to have_content(successful_submission_message)
end
scenario 'creating a release for a minor with two guardians', js: true do
allow(BrayniacAI::Validation).to receive(:create).and_return(double(:validation, valid: true))
project = create(:project, members: current_user, account: current_user.primary_account)
contract_template = create(:contract_template, project: project)
visit new_account_project_contract_template_medical_release_path(project.account, project, contract_template)
expect(page).not_to have_content guardian_2_information_heading.upcase
expect(page).not_to have_content guardian_2_photo_heading.upcase
page.check person_is_minor_checkbox
expect(page).to have_content guardian_information_heading.upcase
expect(page).to have_content guardian_photo_heading.upcase
expect(page).to have_content guardian_email_field.titleize
expect(page).to have_content guardian_2_information_heading.upcase
expect(page).to have_content guardian_2_photo_heading.upcase
expect(page).to have_content guardian_2_email_field.titleize
expect(page).to have_content guardian_2_phone_field.titleize
expect(page).to have_content guardian_2_address_street1_field.titleize
fill_in guardian_first_name_field, with: 'Guardian'
fill_in guardian_last_name_field, with: 'Name'
fill_in guardian_phone_field, with: '001101'
fill_in person_first_name_field, with: 'Jane'
fill_in person_last_name_field, with: 'Doe'
fill_in_person_address_fields
fill_in person_phone_field, with: '555-555-5555'
fill_in person_email_field, with: 'jane.doe@test.com'
drop_file Rails.root.join(file_fixture("person_photo.png")), type: :dropzone
attach_file guardian_photo_field, file_fixture('hemsworth.jpeg'), visible: :all
draw_signature file_fixture('signature.png'), 'medical_release_signature_base64'
fill_in guardian_email_field, with: 'invalid@email'
click_button submit_release_button
expect(page).to have_content email_validation_error_for('Guardian')
fill_in guardian_email_field, with: 'valid@email.com'
fill_in_guardian_address_fields
attach_file guardian_photo_field, file_fixture('hemsworth.jpeg'), visible: :all
draw_signature file_fixture('signature.png'), 'medical_release_signature_base64'
fill_in guardian_2_first_name_field, with: 'Second'
fill_in guardian_2_last_name_field, with: 'Guardian'
fill_in guardian_2_phone_field, with: '999'
click_button submit_release_button
expect(page).to have_content(successful_submission_message)
expect(MedicalRelease.last.guardian_2_first_name).to eq 'Second'
end
end
context "when signed in as account manager" do
before do
sign_in current_user
end
scenario "Download All is visible" do
create(:medical_release_with_contract_template, :native, project: project)
create(:medical_release_with_contract_template, :non_native, project: project)
visit project_medical_releases_path(project)
expect(page).to have_content download_all_button
end
scenario "Download action in Manage menu is visible" do
create(:medical_release_with_contract_template, :native, project: project)
create(:medical_release_with_contract_template, :non_native, project: project)
visit project_medical_releases_path(project)
expect(page).to have_link("Download", exact: true, count: 2)
end
scenario "Downloading PDF of native medical release is possible" do
native_release = create(:medical_release_with_contract_template, :native, project: project)
visit project_medical_releases_path(project)
click_link *view_release_pdf_link_for(native_release)
expect(content_type).to eq('application/pdf')
end
end
context "when the user is manager(project manager)" do
let(:current_user) { create(:user, :manager) }
before do
sign_in current_user
end
scenario "Download All is not visible" do
create(:medical_release_with_contract_template, :native, project: project)
create(:medical_release_with_contract_template, :non_native, project: project)
visit project_medical_releases_path(project)
expect(page).not_to have_content download_all_button
end
scenario "Download action in Manage menu is not visible" do
create(:medical_release_with_contract_template, :native, project: project)
create(:medical_release_with_contract_template, :non_native, project: project)
visit project_medical_releases_path(project)
expect(page).to have_link("Download", exact: true, count: 0)
end
scenario "Downloading PDF of native medical release is not possible" do
native_release = create(:medical_release_with_contract_template, :native, project: project)
visit project_medical_releases_path(project)
link = medical_release_contracts_path(native_release, format: 'pdf')
expect { visit link }.to raise_exception Pundit::NotAuthorizedError
end
scenario "Downloading PDF of non native medical release is not possible" do
non_native_release = create(:medical_release_with_contract_template, :non_native, project: project)
visit project_medical_releases_path(project)
link = medical_release_contracts_path(non_native_release, format: 'pdf')
expect { visit link }.to raise_exception Pundit::NotAuthorizedError
end
end
context "when the user is associate" do
let(:current_user) { create(:user, :associate) }
before do
sign_in current_user
end
scenario "Download All is not visible" do
create(:medical_release_with_contract_template, :native, project: project)
create(:medical_release_with_contract_template, :non_native, project: project)
visit project_medical_releases_path(project)
expect(page).not_to have_content download_all_button
end
scenario "Download action in Manage menu is not visible" do
create(:medical_release_with_contract_template, :native, project: project)
create(:medical_release_with_contract_template, :non_native, project: project)
visit project_medical_releases_path(project)
expect(page).to have_link("Download", exact: true, count: 0)
end
scenario "Downloading PDF of native medical release is not possible" do
native_release = create(:medical_release_with_contract_template, :native, project: project)
visit project_medical_releases_path(project)
link = medical_release_contracts_path(native_release, format: 'pdf')
expect { visit link }.to raise_exception Pundit::NotAuthorizedError
end
scenario "Downloading PDF of non native medical release is not possible" do
non_native_release = create(:medical_release_with_contract_template, :non_native, project: project)
visit project_medical_releases_path(project)
link = medical_release_contracts_path(non_native_release, format: 'pdf')
expect { visit link }.to raise_exception Pundit::NotAuthorizedError
end
end
private
def download_all_button
'Download All'
end
def download_action
'Download'
end
def manage_button
t 'medical_releases.medical_release.actions.manage'
end
def view_release_pdf_link_for(release)
['Download', href: medical_release_contracts_path(release, format: 'pdf')]
end
def person_first_name_field
"medical_release[person_first_name]"
end
def person_last_name_field
"medical_release[person_last_name]"
end
def person_email_field
"medical_release[person_email]"
end
def person_phone_field
"medical_release[person_phone]"
end
def submit_release_button
t 'shared.submit_release_short'
end
def successful_submission_message
"Your release was successfully submitted. Thank you."
end
def fill_in_person_address_fields
fill_in person_address_street1_field, with: "123 Test Lane"
fill_in person_address_city_field, with: "New York"
fill_in person_address_state_field, with: "NY"
fill_in person_address_zip_field, with: '1000'
end
def fill_in_guardian_address_fields
fill_in guardian_address_street1_field, with: "124 Test Lane"
fill_in guardian_address_city_field, with: "New York"
fill_in guardian_address_state_field, with: "NY"
fill_in guardian_address_zip_field, with: '1000'
end
def person_address_street1_field
t('helpers.label.medical_release.person_address_street1')
end
def person_address_city_field
t('helpers.label.medical_release.person_address_city')
end
def person_address_state_field
t('helpers.label.medical_release.person_address_state')
end
def person_address_zip_field
t('helpers.label.medical_release.person_address_zip')
end
def guardian_first_name_field
t('helpers.label.medical_release.guardian_first_name')
end
def guardian_last_name_field
t('helpers.label.medical_release.guardian_last_name')
end
def guardian_phone_field
t('helpers.label.medical_release.guardian_phone')
end
def guardian_email_field
t('helpers.label.medical_release.guardian_email')
end
def guardian_address_street1_field
t('helpers.label.medical_release.guardian_address_street1')
end
def guardian_address_city_field
t('helpers.label.medical_release.guardian_address_city')
end
def guardian_address_state_field
t('helpers.label.medical_release.guardian_address_state')
end
def guardian_address_zip_field
t('helpers.label.medical_release.guardian_address_zip')
end
def guardian_photo_field
'medical_release[guardian_photo]'
end
def person_is_minor_checkbox
'medical_release_minor'
end
def guardian_2_first_name_field
t('helpers.label.medical_release.guardian_2_first_name')
end
def guardian_2_last_name_field
t('helpers.label.medical_release.guardian_2_last_name')
end
def guardian_2_phone_field
t('helpers.label.medical_release.guardian_2_phone')
end
def guardian_2_email_field
t('helpers.label.medical_release.guardian_2_email')
end
def guardian_2_address_street1_field
t('helpers.label.medical_release.guardian_2_address_street1')
end
def email_validation_error_for(prefix)
"#{prefix} email is not an email"
end
def guardian_photo_heading
t 'public.medical_releases.new.guardian_photo.heading'
end
def guardian_information_heading
t 'public.medical_releases.new.guardian_info.heading'
end
def guardian_2_photo_heading
t 'public.medical_releases.new.guardian_2_photo.heading'
end
def guardian_2_information_heading
t 'public.medical_releases.new.guardian_2_info.heading'
end
end

View File

@@ -0,0 +1,55 @@
require "rails_helper"
feature "User managing misc releases" do
let(:current_user) { create(:user) }
let(:project) { create(:project, members: current_user, account: current_user.primary_account) }
context "when signed in as account manager" do
before do
sign_in current_user
end
scenario "Download All is visible" do
create(:misc_release_with_contract_template, :native, project: project)
visit project_misc_releases_path(project)
expect(page).to have_content download_all_button
end
scenario "Downloading PDF of native misc release is possible" do
native_release = create(:misc_release_with_contract_template, :native, project: project)
visit project_misc_releases_path(project)
click_link *view_release_pdf_link_for(native_release)
expect(content_type).to eq('application/pdf')
end
end
context "when the user is manager(project manager)" do
let(:current_user) { create(:user, :manager) }
before do
sign_in current_user
end
scenario "Download action in Manage menu is not visible" do
create(:misc_release_with_contract_template, :native, project: project)
visit project_misc_releases_path(project)
expect(page).to have_link("Download", exact: true, count: 0)
end
end
private
def download_all_button
'Download All'
end
def view_release_pdf_link_for(release)
['Download', href: misc_release_contracts_path(release, format: 'pdf')]
end
end

View File

@@ -5,6 +5,13 @@ feature "User managing talent releases" do
let(:project) { create(:project, members: current_user, account: current_user.primary_account) }
context "when signed out" do
scenario "United States is default country" do
contract_template = create(:contract_template, project: project)
visit new_account_project_contract_template_talent_release_path(project.account, project, contract_template)
expect(country_field_value).to eq "US"
end
scenario "creating a release for an adult", js: true do
contract_template = create(:contract_template, project: project)
@@ -55,6 +62,47 @@ feature "User managing talent releases" do
expect(page).to have_content("Your release was successfully submitted. Thank you.")
end
scenario "creating a release for a minor with two guardians", js: true do
contract_template = create(:contract_template, project: project)
visit new_account_project_contract_template_talent_release_path(project.account, project, contract_template)
expect(page).not_to have_content guardian_information_heading.upcase
expect(page).not_to have_content guardian_2_information_heading.upcase
expect(page).not_to have_content guardian_photo_heading.upcase
expect(page).not_to have_content guardian_2_photo_heading.upcase
page.check person_is_minor_checkbox
expect(page).to have_content guardian_information_heading.upcase
expect(page).to have_content guardian_2_information_heading.upcase
expect(page).to have_content guardian_photo_heading.upcase
expect(page).to have_content guardian_2_photo_heading.upcase
fill_in person_first_name_field, with: "Jane"
fill_in person_last_name_field, with: "Doe"
fill_in person_address_field, with: "123 Test Lane, New York, NY 10000"
fill_in person_phone_field, with: "555-555-5555"
fill_in person_email_field, with: "jane.doe@test.com"
fill_in guardian_first_name_field, with: "Guardian"
fill_in guardian_last_name_field, with: "Name"
fill_in guardian_phone_field, with: "001101"
fill_in guardian_2_first_name_field, with: "Second"
fill_in guardian_2_last_name_field, with: "Guardian"
drop_file Rails.root.join(file_fixture("person_photo.png")), type: :dropzone
attach_file guardian_photo_field, file_fixture("hemsworth.jpeg"), visible: :all
attach_file guardian_2_photo_field, file_fixture("person_photo.png"), visible: :all
draw_signature file_fixture("signature.png"), "talent_release_signature_base64"
click_button submit_button
expect(page).to have_content success_submit_message
expect(TalentRelease.last.guardian_2_photo.attached?).to eq true
expect(TalentRelease.last.guardian_2_name).to eq "Second Guardian"
end
end
context "when signed in" do
@@ -118,6 +166,43 @@ feature "User managing talent releases" do
expect(page).to have_photo("person_photo.png")
end
scenario "creating a release for minor with two guardians", js: true do
visit new_project_talent_release_path(project)
expect(page).not_to have_content guardian_photo_heading
expect(page).not_to have_content guardian_2_photo_heading
page.check person_is_minor_checkbox
expect(page).to have_content guardian_photo_heading
expect(page).to have_content guardian_2_photo_heading
fill_in person_first_name_field, with: "John"
fill_in person_last_name_field, with: "Doe"
fill_in guardian_first_name_field, with: "Guardian"
fill_in guardian_last_name_field, with: "Name"
fill_in guardian_phone_field, with: "01010"
fill_in guardian_2_first_name_field, with: "Second"
fill_in guardian_2_last_name_field, with: "Guardian"
fill_in_exploitable_rights
attach_file contract_field, Rails.root.join(file_fixture("contract.pdf")), visible: false
drop_file Rails.root.join(file_fixture("person_photo.png")), type: :dropzone
attach_file guardian_photo_field, Rails.root.join(file_fixture("hemsworth.jpeg")), visible: false
attach_file guardian_2_photo_field, Rails.root.join(file_fixture("pratt.jpg")), visible: false
click_button create_release_button
expect(page).to have_content create_release_notice
expect(page).to have_photo("person_photo.png")
expect(TalentRelease.last.guardian_2_photo.attached?).to eq true
expect(TalentRelease.last.guardian_2_name).to eq "Second Guardian"
end
scenario "updating an existing release" do
talent_release = create(:talent_release, project: project)
@@ -274,6 +359,10 @@ feature "User managing talent releases" do
private
def country_field_value
find_field("talent_release[person_address_country]").value
end
def photos_heading(photos_count = 1)
t 'contracts.photos.heading', count: photos_count
end
@@ -290,6 +379,14 @@ feature "User managing talent releases" do
"Guardian last name"
end
def guardian_2_first_name_field
"talent_release[guardian_2_first_name]"
end
def guardian_2_last_name_field
"talent_release[guardian_2_last_name]"
end
def guardian_phone_field
"Guardian phone"
end
@@ -298,6 +395,10 @@ feature "User managing talent releases" do
"talent_release[guardian_photo]"
end
def guardian_2_photo_field
"talent_release[guardian_2_photo]"
end
def have_photo_button
have_selector(".take-photo-button")
end
@@ -376,4 +477,32 @@ feature "User managing talent releases" do
select "Other", from: "Restriction"
fill_in "Describe other restrictions", with: "Test"
end
def guardian_information_heading
t 'public.talent_releases.new.guardian_info.heading'
end
def guardian_2_information_heading
t 'public.talent_releases.new.guardian_2_info.heading'
end
def guardian_photo_heading
t 'public.talent_releases.new.guardian_photo.heading'
end
def guardian_2_photo_heading
t 'public.talent_releases.new.guardian_2_photo.heading'
end
def submit_button
t 'shared.submit_release_long'
end
def success_submit_message
"Your release was successfully submitted. Thank you."
end
def contract_field
"talent_release[contract]"
end
end

View File

@@ -521,8 +521,8 @@ feature "User performs video analysis" do
new_path = polymorphic_path([:new, video, release, :video_release_confirmation])
first("form[action='#{new_path}']").click_button
expect(page).to have_content "Timecode in"
expect(page).to have_content "Source file name"
expect(page).to have_content "Timecode In"
expect(page).to have_content "Source File Name"
click_on "Show/Hide EDL Events"
within "#edl_events" do
@@ -572,8 +572,8 @@ feature "User performs video analysis" do
new_path = polymorphic_path([:new, video, release, :video_release_confirmation])
first("form[action='#{new_path}']").click_button
expect(page).to have_content "Timecode in"
expect(page).to have_content "Source file name"
expect(page).to have_content "Timecode In"
expect(page).to have_content "Source File Name"
click_on "Show/Hide EDL Events"
within "#edl_events" do
@@ -748,8 +748,8 @@ feature "User performs video analysis" do
open_graphics_element_modal(video)
expect(page).to have_content "Timecode in"
expect(page).to have_content "Source file name"
expect(page).to have_content "Timecode In"
expect(page).to have_content "Source File Name"
click_on "Show/Hide EDL Events"
within "#edl_events" do
@@ -796,8 +796,8 @@ feature "User performs video analysis" do
open_graphics_element_modal(video)
expect(page).to have_content "Timecode in"
expect(page).to have_content "Source file name"
expect(page).to have_content "Timecode In"
expect(page).to have_content "Source File Name"
click_on "Show/Hide EDL Events"
within "#edl_events" do
@@ -1188,8 +1188,8 @@ feature "User performs video analysis" do
open_audio_confirmation_modal
expect(page).to have_field("Origin", with: "Original Music")
expect(page).to have_content "Timecode in"
expect(page).to have_content "Source file name"
expect(page).to have_content "Timecode In"
expect(page).to have_content "Source File Name"
expect(page).to have_field("Source EDL", with: "Audio")
click_on "Show/Hide EDL Events"
@@ -1219,10 +1219,10 @@ feature "User performs video analysis" do
expect(page).to have_field("Source EDL", with: "All Tracks")
expect(page).to have_field("Channel", with: "A1")
expect(page).to have_field("Origin", with: "Library Music")
expect(page).to have_field("Timecode in", with: "01:00:00:00")
expect(page).to have_field("Timecode In", with: "01:00:00:00")
expect(page).to have_field("Timecode out", with: "01:00:02:00")
expect(page).to have_field("Duration", with: "00:00:02")
expect(page).to have_field("Source file name", with: "source_file_name.wav")
expect(page).to have_field("Source File Name", with: "source_file_name.wav")
expect(page).to have_field("Clip name", with: "clip_name")
expect(page).to have_field("Description", with: "description")
@@ -1323,8 +1323,8 @@ feature "User performs video analysis" do
open_unreleased_modal(video)
expect(page).to have_content "Timecode in"
expect(page).to have_content "Source file name"
expect(page).to have_content "Timecode In"
expect(page).to have_content "Source File Name"
click_on "Show/Hide EDL Events"
within "#edl_events" do
@@ -1371,8 +1371,8 @@ feature "User performs video analysis" do
open_unreleased_modal(video)
expect(page).to have_content "Timecode in"
expect(page).to have_content "Source file name"
expect(page).to have_content "Timecode In"
expect(page).to have_content "Source File Name"
click_on "Show/Hide EDL Events"
within "#edl_events" do
@@ -1445,7 +1445,7 @@ feature "User performs video analysis" do
first("#suggested_matches form[action='#{new_path}']").click_button
expect(page).to have_content "Timecode in"
expect(page).to have_content "Timecode In"
within "form[action='#{create_path}']" do
click_button "Confirm Release"
@@ -1462,7 +1462,7 @@ feature "User performs video analysis" do
$("#audio_matches .releasable-match button")[0].click()
JS
expect(page).to have_content "Timecode in"
expect(page).to have_content "Timecode In"
end
def select_option(select_id, text)
@@ -1486,7 +1486,7 @@ feature "User performs video analysis" do
JS
expect(page).to have_field("Origin", with: "Library Music")
expect(page).to have_content "Timecode in"
expect(page).to have_content "Timecode In"
within "form[action='#{create_path}']" do
expect(page).to have_selector("#matched_file_name", text: "library_file_name")
@@ -1518,7 +1518,7 @@ feature "User performs video analysis" do
first("form[action='#{new_path}']", text: text).click_button
expect(page).to have_content "Timecode in"
expect(page).to have_content "Timecode In"
within "form[action='#{create_path}']" do
click_button "Confirm Release"
@@ -1536,7 +1536,7 @@ feature "User performs video analysis" do
first("#music_releases form[action='#{new_path}']", text: text).click_button
expect(page).to have_field("Origin", with: "Original Music")
expect(page).to have_content "Timecode in"
expect(page).to have_content "Timecode In"
within "form[action='#{create_path}']" do
select "Vocal", from: "Music type"

View File

@@ -0,0 +1,45 @@
require "rails_helper"
describe AttachRecordingToZoomMeetingJob do
let(:project) { create(:project) }
let(:zoom_meeting) { create(:zoom_meeting, project: project) }
let(:recording_hash) { {'id' => 'recording-id', 'download_url' => 'http://download.url', 'recording_start' => '2020-05-22 16:33:50 UTC', 'recording_end' => '2020-05-22 17:34:06 UTC'} }
let(:download_token) { 'download_token' }
before :each do
allow_any_instance_of(ZoomGateway).to receive(:delete_recording)
end
describe ".perform_now" do
it "downloads the video" do
allow(zoom_meeting.recording).to receive(:attach)
expect(URI).to receive(:open).with("http://download.url?access_token=download_token")
AttachRecordingToZoomMeetingJob.perform_now zoom_meeting, recording_hash, download_token
end
it "deletes the recording through the API" do
stub_uri_open
allow(zoom_meeting.recording).to receive(:attach).and_return(true)
expect_any_instance_of(ZoomGateway).to receive(:delete_recording).with(zoom_meeting.api_meeting_id, 'recording-id')
AttachRecordingToZoomMeetingJob.perform_now zoom_meeting, recording_hash, download_token
end
it "attaches downloaded video to recording" do
allow(zoom_meeting.recording).to receive(:attach)
stub_uri_open
AttachRecordingToZoomMeetingJob.perform_now zoom_meeting, recording_hash, download_token
expect(zoom_meeting.recording).to have_received(:attach).with(hash_including(content_type: 'video/mp4'))
end
end
private
def stub_uri_open
url = "http://download.url?access_token=download_token"
file = double(:file, read: 'stubbed read')
allow(URI).to receive(:open).with(url).and_return(file)
end
end

View File

@@ -0,0 +1,216 @@
require "rails_helper"
describe MatchAppearanceReleasesJob do
let(:project) { create(:project) }
let(:dummy_appearance_release) { create(:appearance_release_import, :with_headshot, :with_contract) }
let(:dummy_matching_request) { instance_double(MatchingRequest, id: 999) }
before :all do
ENV["AWS_BUCKET"] = ""
end
describe ".perform_now" do
it "returns if no attachment is sent" do
expect(MatchingRequest).not_to receive(:create)
attachments = []
MatchAppearanceReleasesJob.perform_now project, attachments
end
it "returns if no valid attachment is sent" do
expect(MatchingRequest).not_to receive(:create)
dummy_video = create(:video)
attachments = [dummy_video.file.blob.signed_id]
MatchAppearanceReleasesJob.perform_now project, attachments
end
it "does not create new appearance release if BrayniacAI returns empty matches array" do
signed_ids = [dummy_appearance_release.person_photo.blob.signed_id]
keys = [dummy_appearance_release.person_photo.key]
payload = {
project: project,
attachments: signed_ids
}
qr_matching_payload = {
bucket: '',
files: keys,
request_id: dummy_matching_request.id
}
qr_matching_mock_response = double(
request_id: dummy_matching_request.id,
matches: []
)
expect(MatchingRequest).to receive(:create).with(payload).and_return(dummy_matching_request)
expect(BrayniacAI::QrMatching).to receive(:create!).with(qr_matching_payload).and_return(qr_matching_mock_response)
expect(dummy_matching_request).to receive(:destroy)
MatchAppearanceReleasesJob.perform_now project, signed_ids
expect(AppearanceRelease.last).to eq dummy_appearance_release
end
it "creates new incomplete appearance release if BrayniacAI returns single headshot match" do
signed_ids = [dummy_appearance_release.person_photo.blob.signed_id]
keys = [dummy_appearance_release.person_photo.key]
payload = {
project: project,
attachments: signed_ids
}
qr_matching_payload = {
bucket: '',
files: keys,
request_id: dummy_matching_request.id
}
mock_match = double(
headshots: keys,
contracts: [],
unknowns: [],
identifier: 'some/identifier/123'
)
matches = [mock_match]
qr_matching_mock_response = double(
request_id: dummy_matching_request.id,
matches: matches
)
expect(MatchingRequest).to receive(:create).with(payload).and_return(dummy_matching_request)
expect(BrayniacAI::QrMatching).to receive(:create!).with(qr_matching_payload).and_return(qr_matching_mock_response)
expect(dummy_matching_request).to receive(:destroy)
MatchAppearanceReleasesJob.perform_now project, signed_ids
expect(AppearanceRelease.last.identifier).to eq mock_match.identifier
expect(AppearanceRelease.last.person_photo).to be_attached
expect(AppearanceRelease.last.contract).not_to be_attached
end
it "creates new incomplete appearance release if BrayniacAI returns single contract match" do
signed_ids = [dummy_appearance_release.contract.blob.signed_id]
keys = [dummy_appearance_release.contract.key]
payload = {
project: project,
attachments: signed_ids
}
qr_matching_payload = {
bucket: '',
files: keys,
request_id: dummy_matching_request.id
}
mock_match = double(
headshots: [],
contracts: keys,
unknowns: [],
identifier: 'some/identifier/123'
)
matches = [mock_match]
qr_matching_mock_response = double(
request_id: dummy_matching_request.id,
matches: matches
)
expect(MatchingRequest).to receive(:create).with(payload).and_return(dummy_matching_request)
expect(BrayniacAI::QrMatching).to receive(:create!).with(qr_matching_payload).and_return(qr_matching_mock_response)
expect(dummy_matching_request).to receive(:destroy)
MatchAppearanceReleasesJob.perform_now project, signed_ids
expect(AppearanceRelease.last.identifier).to eq mock_match.identifier
expect(AppearanceRelease.last.person_photo.attached?).to eq false
expect(AppearanceRelease.last.contract.attached?).to eq true
end
it "creates new complete appearance release if BrayniacAI returns match for headshot and contract" do
signed_ids = [
dummy_appearance_release.person_photo.blob.signed_id,
dummy_appearance_release.contract.blob.signed_id
]
keys = [
dummy_appearance_release.person_photo.key,
dummy_appearance_release.contract.key
]
payload = {
project: project,
attachments: signed_ids
}
qr_matching_payload = {
bucket: '',
files: keys,
request_id: dummy_matching_request.id
}
mock_match = double(
headshots: [keys[0]],
contracts: [keys[1]],
unknowns: [],
identifier: 'some/identifier/123'
)
matches = [mock_match]
qr_matching_mock_response = double(
request_id: dummy_matching_request.id,
matches: matches
)
expect(MatchingRequest).to receive(:create).with(payload).and_return(dummy_matching_request)
expect(BrayniacAI::QrMatching).to receive(:create!).with(qr_matching_payload).and_return(qr_matching_mock_response)
expect(dummy_matching_request).to receive(:destroy)
MatchAppearanceReleasesJob.perform_now project, signed_ids
expect(AppearanceRelease.last.identifier).to eq mock_match.identifier
expect(AppearanceRelease.last.person_photo.attached?).to eq true
expect(AppearanceRelease.last.contract.attached?).to eq true
end
it "creates two new incomplete appearance releases if BrayniacAI returns two matches for headshot and contract" do
signed_ids = [
dummy_appearance_release.person_photo.blob.signed_id,
dummy_appearance_release.contract.blob.signed_id
]
keys = [
dummy_appearance_release.person_photo.key,
dummy_appearance_release.contract.key
]
payload = {
project: project,
attachments: signed_ids
}
qr_matching_payload = {
bucket: '',
files: keys,
request_id: dummy_matching_request.id
}
mock_match1 = double(
headshots: [keys[0]],
contracts: [],
unknowns: [],
identifier: 'some/identifier/123'
)
mock_match2 = double(
headshots: [],
contracts: [keys[1]],
unknowns: [],
identifier: 'some/identifier/789'
)
matches = [mock_match1, mock_match2]
qr_matching_mock_response = double(
request_id: dummy_matching_request.id,
matches: matches
)
expect(MatchingRequest).to receive(:create).with(payload).and_return(dummy_matching_request)
expect(BrayniacAI::QrMatching).to receive(:create!).with(qr_matching_payload).and_return(qr_matching_mock_response)
expect(dummy_matching_request).to receive(:destroy)
MatchAppearanceReleasesJob.perform_now project, signed_ids
releases = AppearanceRelease.last(2)
expect(releases[0].identifier).to eq mock_match1.identifier
expect(releases[0].person_photo.attached?).to eq true
expect(releases[0].contract.attached?).to eq false
expect(releases[1].identifier).to eq mock_match2.identifier
expect(releases[1].person_photo.attached?).to eq false
expect(releases[1].contract.attached?).to eq true
end
end
end

View File

@@ -1,16 +1,16 @@
require 'rails_helper'
require 'zoom_gateway'
RSpec.describe ZoomGateway do
let(:roles_list_response) { {"roles" => [{"name" => 'pro-directme-host', "id" => "host_role_id"}, {"name" => 'basic-directme-host', "id" => "host_role_id"}]} }
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 }
describe "constants" do
describe "pseudo-constants" do
context '.USER_TYPE_NAME' do
it 'defaults to "basic"' do
expect(ZoomGateway.USER_TYPE_NAME).to eq('basic')
@@ -64,6 +64,36 @@ RSpec.describe ZoomGateway do
expect(ZoomGateway.HOST_ROLE).to eq('pro-directme-host')
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 'static methods' do
context '.enable_recordings?' do
it 'is truthy when ZOOM_ENABLE_RECORDINGS is set to true' do
stub_env_variable('ZOOM_ENABLE_RECORDINGS', 'true')
expect(ZoomGateway.enable_recordings?).to be_truthy
end
it 'is falsey otherwise' do
stub_env_variable('ZOOM_ENABLE_RECORDINGS', '1')
expect(ZoomGateway.enable_recordings?).to be_falsey
stub_env_variable('ZOOM_ENABLE_RECORDINGS', 'false')
expect(ZoomGateway.enable_recordings?).to be_falsey
end
end
context '.host_role_name' do
it 'returns given name with -directme-host prefix' do
expect(ZoomGateway.host_role_name('prefix')).to eq('prefix-directme-host')
end
end
end
describe ".find_meeting" do
@@ -92,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
@@ -102,20 +134,18 @@ 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
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)
describe '.delete_recording' do
it 'calls api client to delete recording' do
expect_any_instance_of(Zoom.new.class).to receive(:recording_delete)
gateway.delete_recording('meeting-id', 'recording-id')
end
end
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

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

View File

@@ -1,7 +1,8 @@
require "rails_helper"
describe AcquiredMediaReleasePolicy do
let(:user_context) { build(:user_context) }
let(:user) { create(:user, :manager) }
let(:user_context) { build(:user_context, user: user, account: user.primary_account) }
subject { described_class }
@@ -24,6 +25,14 @@ describe AcquiredMediaReleasePolicy do
end
permissions :destroy? do
it { is_expected.to permit(:destroy) }
it { is_expected.to permit(user_context, :destroy) }
end
context "for an associate" do
let(:user) { create(:user, :associate) }
permissions :destroy? do
it { is_expected.not_to permit(user_context, :destroy) }
end
end
end

View File

@@ -1,7 +1,8 @@
require "rails_helper"
describe AppearanceReleasePolicy do
let(:user_context) { build(:user_context) }
let(:user) { create(:user, :manager) }
let(:user_context) { build(:user_context, user: user, account: user.primary_account) }
subject { described_class }
@@ -24,6 +25,14 @@ describe AppearanceReleasePolicy do
end
permissions :destroy? do
it { is_expected.to permit(:destroy) }
it { is_expected.to permit(user_context, :destroy) }
end
context "for an associate" do
let(:user) { create(:user, :associate) }
permissions :destroy? do
it { is_expected.not_to permit(user_context, :destroy) }
end
end
end

View File

@@ -15,6 +15,10 @@ describe ContractTemplatePolicy do
it { is_expected.not_to permit(user_context, :create) }
end
permissions :show? do
it { is_expected.to permit(user_context, :show) }
end
permissions :destroy? do
it { is_expected.not_to permit(user_context, contract_template) }
@@ -33,6 +37,32 @@ describe ContractTemplatePolicy do
it { is_expected.to permit(user_context, :create) }
end
permissions :show? do
it { is_expected.to permit(user_context, :show) }
end
permissions :destroy? do
it { is_expected.to permit(user_context, contract_template) }
context "when there are associated releases" do
let(:contract_template) { create(:contract_template, appearance_releases: build_list(:appearance_release, 1)) }
it { is_expected.to permit(user_context, contract_template) }
end
end
end
context "for an account manager" do
let(:user) { create(:user, :account_manager) }
permissions :create? do
it { is_expected.to permit(user_context, :create) }
end
permissions :show? do
it { is_expected.to permit(user_context, :show) }
end
permissions :destroy? do
it { is_expected.to permit(user_context, contract_template) }
@@ -79,7 +109,7 @@ describe ContractTemplatePolicy do
context "for associate" do
let(:user) { create(:user, :associate, primary_account: account) }
it { is_expected.not_to include(member_project.contract_templates.first) }
it { is_expected.to include(member_project.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

View File

@@ -1,7 +1,8 @@
require "rails_helper"
describe LocationReleasePolicy do
let(:user_context) { build(:user_context) }
let(:user) { create(:user, :manager) }
let(:user_context) { build(:user_context, user: user, account: user.primary_account) }
subject { described_class }
@@ -23,10 +24,6 @@ describe LocationReleasePolicy do
end
end
permissions :destroy? do
it { is_expected.to permit(:destroy) }
end
permissions :edit_photos? do
it { is_expected.to permit(:edit_photos) }
end
@@ -34,4 +31,16 @@ describe LocationReleasePolicy do
permissions :update_photos? do
it { is_expected.to permit(:update_photos) }
end
permissions :destroy? do
it { is_expected.to permit(user_context, :destroy) }
end
context "for an associate" do
let(:user) { create(:user, :associate) }
permissions :destroy? do
it { is_expected.not_to permit(user_context, :destroy) }
end
end
end

View File

@@ -1,7 +1,8 @@
require "rails_helper"
describe MaterialReleasePolicy do
let(:user_context) { build(:user_context) }
let(:user) { create(:user, :manager) }
let(:user_context) { build(:user_context, user: user, account: user.primary_account) }
subject { described_class }
@@ -23,10 +24,6 @@ describe MaterialReleasePolicy do
end
end
permissions :destroy? do
it { is_expected.to permit(:destroy) }
end
permissions :edit_photos? do
it { is_expected.to permit(:edit_photos) }
end
@@ -34,4 +31,16 @@ describe MaterialReleasePolicy do
permissions :update_photos? do
it { is_expected.to permit(:update_photos) }
end
permissions :destroy? do
it { is_expected.to permit(user_context, :destroy) }
end
context "for an associate" do
let(:user) { create(:user, :associate) }
permissions :destroy? do
it { is_expected.not_to permit(user_context, :destroy) }
end
end
end

View File

@@ -0,0 +1,46 @@
require "rails_helper"
describe MedicalReleasePolicy do
let(:user) { create(:user, :manager) }
let(:user_context) { build(:user_context, user: user, account: user.primary_account) }
subject { described_class }
permissions :create? do
it { is_expected.to permit(:create) }
end
permissions :show? do
it { is_expected.to permit(:show) }
end
permissions :update? do
context "for a native release" do
it { is_expected.not_to permit(user_context, build(:medical_release, :native)) }
end
context "for a non-native release" do
it { is_expected.to permit(user_context, build(:medical_release, :non_native)) }
end
end
permissions :edit_photos? do
it { is_expected.to permit(:edit_photos) }
end
permissions :update_photos? do
it { is_expected.to permit(:update_photos) }
end
permissions :destroy? do
it { is_expected.to permit(user_context, :destroy) }
end
context "for an associate" do
let(:user) { create(:user, :associate) }
permissions :destroy? do
it { is_expected.not_to permit(user_context, :destroy) }
end
end
end

View File

@@ -0,0 +1,42 @@
require "rails_helper"
describe MiscReleasePolicy do
let(:user) { create(:user, :manager) }
let(:user_context) { build(:user_context, user: user, account: user.primary_account) }
subject { described_class }
permissions :create? do
it { is_expected.to permit(:create) }
end
permissions :show? do
it { is_expected.to permit(:show) }
end
permissions :update? do
context "for a native release" do
it { is_expected.not_to permit(user_context, build(:misc_release, :native)) }
end
end
permissions :edit_photos? do
it { is_expected.to permit(:edit_photos) }
end
permissions :update_photos? do
it { is_expected.to permit(:update_photos) }
end
permissions :destroy? do
it { is_expected.to permit(user_context, :destroy) }
end
context "for an associate" do
let(:user) { create(:user, :associate) }
permissions :destroy? do
it { is_expected.not_to permit(user_context, :destroy) }
end
end
end

View File

@@ -1,7 +1,8 @@
require "rails_helper"
RSpec.describe MusicReleasePolicy do
let(:user_context) { build(:user_context) }
let(:user) { create(:user, :manager) }
let(:user_context) { build(:user_context, user: user, account: user.primary_account) }
subject { described_class }
@@ -18,6 +19,14 @@ RSpec.describe MusicReleasePolicy do
end
permissions :destroy? do
it { is_expected.to permit(:destroy) }
it { is_expected.to permit(user_context, :destroy) }
end
context "for an associate" do
let(:user) { create(:user, :associate) }
permissions :destroy? do
it { is_expected.not_to permit(user_context, :destroy) }
end
end
end

View File

@@ -1,7 +1,8 @@
require "rails_helper"
describe TalentReleasePolicy do
let(:user_context) { build(:user_context) }
let(:user) { create(:user, :manager) }
let(:user_context) { build(:user_context, user: user, account: user.primary_account) }
subject { described_class }
@@ -23,10 +24,6 @@ describe TalentReleasePolicy do
end
end
permissions :destroy? do
it { is_expected.to permit(:destroy) }
end
permissions :edit_photos? do
it { is_expected.to permit(:edit_photos) }
end
@@ -34,4 +31,16 @@ describe TalentReleasePolicy do
permissions :update_photos? do
it { is_expected.to permit(:update_photos) }
end
permissions :destroy? do
it { is_expected.to permit(user_context, :destroy) }
end
context "for an associate" do
let(:user) { create(:user, :associate) }
permissions :destroy? do
it { is_expected.not_to permit(user_context, :destroy) }
end
end
end

View 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