Upstream sync
This commit is contained in:
63
spec/controllers/api/user_token_controller_spec.rb
Normal file
63
spec/controllers/api/user_token_controller_spec.rb
Normal file
@@ -0,0 +1,63 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Api::UserTokenController, type: :request do
|
||||
let(:current_user) { create(:user) }
|
||||
|
||||
describe '#create' do
|
||||
it 'returns error if credentials are not corrent and does not set cookie' do
|
||||
|
||||
post create_endpoint, params: wrong_auth_params
|
||||
|
||||
expect(response).to be_successful
|
||||
expect(response.body).to match record_not_found
|
||||
expect(cookie_data).to eq nil
|
||||
end
|
||||
|
||||
it 'sends token and cookie if credentials are correct' do
|
||||
post create_endpoint, params: correct_auth_params
|
||||
|
||||
expect(response).to be_successful
|
||||
expect(response.body).not_to match record_not_found
|
||||
expect(response.body).to match token_response
|
||||
expect(cookie_data).not_to eq nil
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def wrong_auth_params
|
||||
{
|
||||
auth: {
|
||||
email: 'wrong_email@api-test.com',
|
||||
password: 'password'
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
def correct_auth_params
|
||||
{
|
||||
auth: {
|
||||
email: current_user.email,
|
||||
password: 'password'
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
def create_endpoint
|
||||
'/api/v1/user_token'
|
||||
end
|
||||
|
||||
def record_not_found
|
||||
/Record not found/
|
||||
end
|
||||
|
||||
def token_response
|
||||
/jwt/
|
||||
end
|
||||
|
||||
def cookie_data
|
||||
cookies[:_easy_release_session]
|
||||
end
|
||||
end
|
||||
78
spec/controllers/api/users_controller_spec.rb
Normal file
78
spec/controllers/api/users_controller_spec.rb
Normal file
@@ -0,0 +1,78 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Api::UsersController, type: :controller do
|
||||
before do
|
||||
ENV['CUSTOM_API_TOKEN'] = "custom_token"
|
||||
end
|
||||
describe '#create' do
|
||||
context 'Invalid token' do
|
||||
it 'Returns 401 (Unauthorized) status if token is not valid' do
|
||||
|
||||
post :create
|
||||
|
||||
expect(response).not_to be_successful
|
||||
expect(response).to have_http_status(401)
|
||||
end
|
||||
end
|
||||
|
||||
context 'Valid token' do
|
||||
before :each do
|
||||
controller.request.env['HTTP_AUTHORIZATION'] = 'Bearer custom_token'
|
||||
end
|
||||
|
||||
it 'Returns Server error if user param is missing' do
|
||||
user_count = User.all.count
|
||||
|
||||
expect do
|
||||
post :create
|
||||
end.to raise_exception ActionController::ParameterMissing
|
||||
|
||||
expect(User.all.count).to eq user_count
|
||||
end
|
||||
|
||||
it 'Returns Server Error if email or password is missing' do
|
||||
user_count = User.all.count
|
||||
|
||||
expect do
|
||||
post :create, params: { user: { email: "a@b.com" } }
|
||||
end.to raise_exception ActionController::ParameterMissing
|
||||
|
||||
expect do
|
||||
post :create, params: { user: { password: "123" } }
|
||||
end.to raise_exception ActionController::ParameterMissing
|
||||
|
||||
expect(User.all.count).to eq user_count
|
||||
end
|
||||
|
||||
it 'Returns Server Error if body contains not permitted params' do
|
||||
user_count = User.all.count
|
||||
|
||||
expect do
|
||||
post :create, params: { user: { email: "a@b.com", password: "123", admin: true } }
|
||||
end.to raise_exception ActionController::UnpermittedParameters
|
||||
|
||||
expect(User.all.count).to eq user_count
|
||||
end
|
||||
|
||||
it 'Creates user if body contains correct params' do
|
||||
expect do
|
||||
post :create, params: { user: { email: "a@b.com", password: "123" } }
|
||||
end.to change(User, :count).by(1)
|
||||
|
||||
expect(response).to be_successful
|
||||
end
|
||||
|
||||
it 'Nothing changes if existing email is used' do
|
||||
create(:user, email: "a@b.com")
|
||||
|
||||
expect do
|
||||
post :create, params: { user: { email: "a@b.com", password: "123" } }
|
||||
end.not_to change(User, :count)
|
||||
|
||||
expect(response).to be_successful
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -4,6 +4,22 @@ FactoryBot.define do
|
||||
|
||||
name "Test Acquired Media Release"
|
||||
|
||||
trait :with_address do
|
||||
person_address_street1 "St1"
|
||||
person_address_street2 "St2"
|
||||
person_address_city "City"
|
||||
person_address_state "State"
|
||||
person_address_zip "123"
|
||||
person_address_country "US"
|
||||
end
|
||||
|
||||
trait :with_owner_info do
|
||||
person_first_name "Jane"
|
||||
person_last_name "Doe"
|
||||
person_phone "100-555-1001"
|
||||
person_email "owner@email.com"
|
||||
end
|
||||
|
||||
trait :native do
|
||||
signature do
|
||||
path = Rails.root.join("spec", "fixtures", "files", "signature.png")
|
||||
|
||||
@@ -4,10 +4,20 @@ FactoryBot.define do
|
||||
|
||||
name "Test Materials"
|
||||
|
||||
trait :with_address do
|
||||
person_address_street1 "St1"
|
||||
person_address_street2 "St2"
|
||||
person_address_city "City"
|
||||
person_address_state "State"
|
||||
person_address_zip "123"
|
||||
person_address_country "US"
|
||||
end
|
||||
|
||||
trait :native do
|
||||
person_first_name "Jane"
|
||||
person_last_name "Doe"
|
||||
person_phone "100-555-1001"
|
||||
person_email "owner@email.com"
|
||||
|
||||
signature do
|
||||
path = Rails.root.join("spec", "fixtures", "files", "signature.png")
|
||||
|
||||
@@ -165,6 +165,24 @@ feature "User managing acquired_media releases" do
|
||||
sign_in current_user
|
||||
end
|
||||
|
||||
scenario "index table shows owner info" do
|
||||
release = create(:acquired_media_release, :with_owner_info, :with_address, project: project)
|
||||
|
||||
visit project_acquired_media_releases_path(project)
|
||||
|
||||
expect(page).to have_content owner_info_table_header
|
||||
|
||||
expect(page).to have_content release.person_first_name
|
||||
expect(page).to have_content release.person_last_name
|
||||
expect(page).to have_content release.person_phone
|
||||
expect(page).to have_content release.person_email
|
||||
expect(page).to have_content release.person_address_street1
|
||||
expect(page).to have_content release.person_address_city
|
||||
expect(page).to have_content release.person_address_state
|
||||
expect(page).to have_content release.person_address_zip
|
||||
expect(page).to have_content release.person_address_country
|
||||
end
|
||||
|
||||
scenario "creating a release for an adult", js: true do
|
||||
visit new_project_acquired_media_release_path(project)
|
||||
|
||||
@@ -262,62 +280,63 @@ feature "User managing acquired_media releases" do
|
||||
end
|
||||
|
||||
scenario "creating, updating, destroying a release", js: true do
|
||||
release_data = {
|
||||
name: "Test Acquired Media Release",
|
||||
applicable_media: ApplicableMedium.last.label,
|
||||
territory: Territory.last.label,
|
||||
term: Term.last.label,
|
||||
restriction: Restriction.first.label,
|
||||
restriction_text: "Not available in China",
|
||||
}
|
||||
resize_window_to(1_000, 1_000) do
|
||||
release_data = {
|
||||
name: "Test Acquired Media Release",
|
||||
applicable_media: ApplicableMedium.last.label,
|
||||
territory: Territory.last.label,
|
||||
term: Term.last.label,
|
||||
restriction: Restriction.first.label,
|
||||
restriction_text: "Not available in China",
|
||||
}
|
||||
|
||||
sign_in current_user
|
||||
visit new_project_acquired_media_release_path(project)
|
||||
sign_in current_user
|
||||
visit new_project_acquired_media_release_path(project)
|
||||
|
||||
by "attaching only a contract" do
|
||||
attach_file contract_field, Rails.root.join(file_fixture("contract.pdf")), visible: false
|
||||
click_button create_release_button
|
||||
by "attaching only a contract" do
|
||||
attach_file contract_field, Rails.root.join(file_fixture("contract.pdf")), visible: false
|
||||
click_button create_release_button
|
||||
|
||||
expect(page).to have_invalid_field(acquired_media_name_field)
|
||||
end
|
||||
|
||||
by "attaching files" do
|
||||
drop_file Rails.root.join(file_fixture("video_file.mp4")), type: "file-info-dropzone"
|
||||
click_button create_release_button
|
||||
|
||||
expect(page).to have_invalid_field(acquired_media_name_field)
|
||||
end
|
||||
|
||||
by "filling out the remaining information" do
|
||||
fill_in_release_fields release_data
|
||||
click_button create_release_button
|
||||
|
||||
expect(page).to have_content(create_release_notice)
|
||||
expect(page).to have_content("1")
|
||||
|
||||
click_on "Manage"
|
||||
expect(page).to have_link("Download")
|
||||
end
|
||||
|
||||
it_also "updates an existing release" do
|
||||
click_link "Edit"
|
||||
|
||||
within ".dropzone" do
|
||||
expect(page).to have_filename("video_file.mp4")
|
||||
expect(page).to have_invalid_field(acquired_media_name_field)
|
||||
end
|
||||
|
||||
expect(page).to have_filled_in_data(release_data)
|
||||
by "attaching files" do
|
||||
drop_file Rails.root.join(file_fixture("video_file.mp4")), type: "file-info-dropzone"
|
||||
click_button create_release_button
|
||||
|
||||
fill_in_release_fields name: "New name"
|
||||
drop_file Rails.root.join(file_fixture("person_photo.png")), type: "file-info-dropzone"
|
||||
click_button update_release_button
|
||||
expect(page).to have_invalid_field(acquired_media_name_field)
|
||||
end
|
||||
|
||||
expect(page).to have_content(update_release_notice)
|
||||
expect(page).to have_content("New name")
|
||||
expect(page).to have_content("2")
|
||||
end
|
||||
by "filling out the remaining information" do
|
||||
fill_in_release_fields release_data
|
||||
click_button create_release_button
|
||||
|
||||
it_also "deletes an existing release" do
|
||||
expect(page).to have_content(create_release_notice)
|
||||
expect(page).to have_content("1")
|
||||
|
||||
click_on "Manage"
|
||||
expect(page).to have_link("Download")
|
||||
end
|
||||
|
||||
it_also "updates an existing release" do
|
||||
click_link "Edit"
|
||||
|
||||
within ".dropzone" do
|
||||
expect(page).to have_filename("video_file.mp4")
|
||||
end
|
||||
|
||||
expect(page).to have_filled_in_data(release_data)
|
||||
|
||||
fill_in_release_fields name: "New name"
|
||||
drop_file Rails.root.join(file_fixture("person_photo.png")), type: "file-info-dropzone"
|
||||
click_button update_release_button
|
||||
|
||||
expect(page).to have_content(update_release_notice)
|
||||
expect(page).to have_content("New name")
|
||||
expect(page).to have_content("2")
|
||||
end
|
||||
|
||||
it_also "deletes an existing release" do
|
||||
click_button "Manage"
|
||||
accept_alert do
|
||||
click_link "Delete"
|
||||
@@ -325,6 +344,7 @@ feature "User managing acquired_media releases" do
|
||||
|
||||
expect(page).not_to have_content("New name")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
scenario "viewing the contract PDF for an adult" do
|
||||
@@ -836,4 +856,8 @@ feature "User managing acquired_media releases" do
|
||||
def successful_import_message
|
||||
t 'acquired_media_releases.create.notice'
|
||||
end
|
||||
|
||||
def owner_info_table_header
|
||||
t 'acquired_media_releases.index.table_headers.owner_info'
|
||||
end
|
||||
end
|
||||
|
||||
@@ -87,7 +87,7 @@ feature "User managing location releases" do
|
||||
|
||||
visit new_account_project_contract_template_location_release_amendment_path(project.account, project, contract_template, release)
|
||||
|
||||
expect(page).to have_content amendments_heading
|
||||
expect(page).to have_content amendments_heading.upcase
|
||||
|
||||
fill_in amendment_signer_name_field, with: 'Big Signer'
|
||||
draw_signature file_fixture("signature.png"), amendment_signature_field
|
||||
@@ -250,10 +250,7 @@ feature "User managing location releases" do
|
||||
|
||||
new_window = window_opened_by { click_link sign_amendment_link }
|
||||
within_window new_window do
|
||||
expect(page).to have_content amendments_heading
|
||||
expect(page).to have_content signed_contract_preview.upcase
|
||||
|
||||
expect(page).to have_selector 'embed'
|
||||
expect(page).to have_content amendments_heading.upcase
|
||||
|
||||
fill_in amendment_signer_name_field, with: 'Big Signer'
|
||||
draw_signature file_fixture("signature.png"), amendment_signature_field
|
||||
|
||||
@@ -185,6 +185,24 @@ feature "User managing material releases" do
|
||||
sign_in current_user
|
||||
end
|
||||
|
||||
scenario "index table shows owner info" do
|
||||
release = create(:material_release, :native, :with_address, project: project)
|
||||
|
||||
visit project_material_releases_path(project)
|
||||
|
||||
expect(page).to have_content owner_info_table_header
|
||||
|
||||
expect(page).to have_content release.person_first_name
|
||||
expect(page).to have_content release.person_last_name
|
||||
expect(page).to have_content release.person_phone
|
||||
expect(page).to have_content release.person_email
|
||||
expect(page).to have_content release.person_address_street1
|
||||
expect(page).to have_content release.person_address_city
|
||||
expect(page).to have_content release.person_address_state
|
||||
expect(page).to have_content release.person_address_zip
|
||||
expect(page).to have_content release.person_address_country
|
||||
end
|
||||
|
||||
scenario "creating a release for and adult", js: true do
|
||||
visit new_project_material_release_path(project)
|
||||
|
||||
@@ -813,4 +831,8 @@ feature "User managing material releases" do
|
||||
def signature_field
|
||||
'material_release_signature_base64'
|
||||
end
|
||||
|
||||
def owner_info_table_header
|
||||
t 'material_releases.index.table_headers.owner_info'
|
||||
end
|
||||
end
|
||||
|
||||
@@ -148,6 +148,18 @@ RSpec.describe Account do
|
||||
end
|
||||
end
|
||||
|
||||
describe "#total_number_of_releases" do
|
||||
it "returns total number of releases" do
|
||||
account = create(:account)
|
||||
project = create(:project, account: account)
|
||||
appearance_release = create(:appearance_release, project: project)
|
||||
talent_release = create(:talent_release, project: project)
|
||||
material_release = create(:material_release, project: project)
|
||||
|
||||
expect(account.total_number_of_releases).to eq 3
|
||||
end
|
||||
end
|
||||
|
||||
describe "#me_suite_enabled?" do
|
||||
it "returns true when plan_uid is me_suite" do
|
||||
expect(build(:account, plan_uid: "me_suite").me_suite_enabled?).to eq true
|
||||
|
||||
Reference in New Issue
Block a user