Task me sync

This commit is contained in:
Senad Uka
2020-06-03 07:24:01 +02:00
parent e3d4d22a34
commit 88836e937e
76 changed files with 847 additions and 497 deletions

View File

@@ -24,20 +24,4 @@ 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

@@ -0,0 +1,68 @@
require "rails_helper"
RSpec.describe Admin::TaskRequestsController, type: :controller do
render_views
let!(:current_user) { create(:user, :admin) }
before do
sign_in(current_user)
end
describe "#index" do
it "returns a successful response" do
get :index
expect(response).to be_successful
end
end
describe "#edit" do
let(:task_request) { create(:task_request) }
it "returns a successful response" do
get :edit, params: { id: task_request }
expect(response).to be_successful
end
it "assigns task request" do
get :edit, params: { id: task_request }
expect(assigns(:task_request)).to eq task_request
end
end
describe "#update" do
let(:task_request) { create(:task_request) }
it "redirects to task requests page" do
patch :update, params: { id: task_request, task_request: update_params }
expect(response).to be_redirect
expect(response).to redirect_to admin_task_requests_path
end
it "sets a flash notice" do
patch :update, params: { id: task_request, task_request: update_params }
expect(flash.notice).to eq "The task request has been updated successfully"
end
it "updates task request" do
patch :update, params: { id: task_request, task_request: update_params }
expect(task_request.reload.status).to eq("completed")
expect(task_request.reload.deliverable_url).to eq("example.com/deliverables")
end
end
private
def update_params
{
status: "completed",
deliverable_url: "example.com/deliverables"
}
end
end

View File

@@ -26,7 +26,8 @@ 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 "P: 5551234567E: jane.doe@test.com"
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 "Some notes here"
expect(response.body).to have_button "Import Release"
expect(response.body).to have_content "Manage"

View File

@@ -56,16 +56,6 @@ 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

@@ -0,0 +1,130 @@
require 'rails_helper'
RSpec.describe TaskRequestsController, 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
create(:task_request, project: project, description: "Another Request")
get :index, params: { project_id: project }
expect(response.body).to have_link "Create Task Request"
expect(response.body).to have_content "Pending"
end
context "when there are many records" do
it "paginates the table" do
create_list(:task_request, 20, project: project)
get :index, params: { project_id: project }
expect(response.body).to have_link("2", href: project_task_requests_path(project, page: 2))
end
end
end
describe "#new" do
it "responds successfully" do
get :new, params: { project_id: project }
expect(response).to be_successful
expect(assigns(:task_request)).to be_a_new(TaskRequest)
expect(response).to render_template(:new)
end
end
describe "#create" do
it "responds with a redirect" do
post :create, params: { project_id: project.id, task_request: task_request_params }
expect(response).to be_redirect
expect(flash.notice).not_to be_nil
end
it "does create a new record" do
expect {
post :create, params: { project_id: project.id, task_request: task_request_params }
}.to change(TaskRequest, :count)
end
it "logs an event" do
expect {
post :create, params: { project_id: project.id, task_request: task_request_params }
}.to have_enqueued_job(TrackAnalyticsJob).with(user, account, :track_create_task_request, user_agent: "Rails Testing", user_ip: "0.0.0.0")
end
end
describe "#update" do
let!(:task_request) { create(:task_request, project: project, description: "My description" ) }
it "updates task request" do
patch :update, params: { project_id: project.id, id: task_request.id, task_request: update_params }
expect(task_request.reload.description).to eq("This is updated description")
end
end
describe "#show" do
let!(:task_request) { create(:task_request, project: project, description: "Task Request") }
it "responds successfully" do
get :show, params: { project_id: project.id, id: task_request.id }
expect(response).to be_successful
expect(assigns(:task_request)).to eq(task_request)
end
it "renders content" do
get :show, params: { project_id: project.id, id: task_request.id }
expect(response.body).to have_content "Task Request"
expect(response.body).to have_content "pending"
end
end
describe "#cancel" do
let!(:task_request) { create(:task_request, project: project, description: "Task to be cancelled") }
it "responds with redirect" do
post :cancel, params: { project_id: project.id, id: task_request.id }
expect(response).to be_redirect
expect(response).to redirect_to(project_task_requests_path(project))
expect(flash.notice).not_to be_nil
end
it "updates the status to 'cancelled'" do
expect {
post :cancel, params: { project_id: project.id, id: task_request.id }
}.to change { task_request.reload.status }.from("pending").to("cancelled")
end
end
private
def task_request_params
attributes = attributes_for(:task_request).except(:status)
files = 2.times.map { Rack::Test::UploadedFile.new(file_fixture("location_photo.png"), "image/png") }
attributes.merge({ files: files })
end
def update_params
{ description: "This is updated description" }
end
end

View File

@@ -69,13 +69,6 @@ RSpec.describe ZoomNotificationsController, type: :controller do
expect(zoom_meeting.reload).to be_ended
end
it 'updates the recording when recording complete notification is received' do
expect {
post :create, params: recording_complete
}.to change { zoom_meeting.recording }
end
end
end
end

View File

@@ -0,0 +1,14 @@
FactoryBot.define do
factory :task_request do
association :project
deadline { 10.days.from_now }
time_allowed "10 days"
description "Task request"
additional_notes "Additional notes"
status 0
trait :with_files do
files { [Rack::Test::UploadedFile.new('spec/fixtures/files/contract.pdf', 'application/pdf')] }
end
end
end

View File

@@ -140,7 +140,6 @@ feature 'User managing appearance releases' do
end
scenario 'importing a releases works when image is selected', js: true do
skip 'Will be changed according to new matching capability'
visit project_appearance_releases_path(project)
expect(page).to have_content submit_create_button
@@ -153,7 +152,6 @@ feature 'User managing appearance releases' do
end
scenario 'importing a releases works when pdf is selected', js: true do
skip 'Will be changed according to new matching capability'
visit project_appearance_releases_path(project)
expect(page).to have_content submit_create_button
@@ -166,7 +164,6 @@ feature 'User managing appearance releases' do
end
scenario 'importing a releases fails when file other than image or pdf is selected', js: true do
skip 'Will be changed according to new matching capability'
visit project_appearance_releases_path(project)
expect(page).to have_content submit_create_button

View File

@@ -1,45 +0,0 @@
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

@@ -64,21 +64,6 @@ RSpec.describe ZoomGateway do
expect(ZoomGateway.HOST_ROLE).to eq('pro-directme-host')
end
end
context '.enable_recordings?' do
it 'is truthy when ZOOM_ENABLE_RECORDINGS is set to 1' do
stub_env_variable('ZOOM_ENABLE_RECORDINGS', '1')
expect(ZoomGateway.enable_recordings?).to be_truthy
end
it 'is falsey otherwise' do
stub_env_variable('ZOOM_ENABLE_RECORDINGS', '0')
expect(ZoomGateway.enable_recordings?).to be_falsey
stub_env_variable('ZOOM_ENABLE_RECORDINGS', '2')
expect(ZoomGateway.enable_recordings?).to be_falsey
end
end
end
describe ".find_meeting" do
@@ -126,13 +111,6 @@ RSpec.describe ZoomGateway do
end
end
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
private
def stub_env_variable(name, value)

View File

@@ -66,16 +66,14 @@ RSpec.describe Account do
end
describe "#storage_total" do
it "sums videos, release photos, contracts, signatures, recordings" do
it "sums videos, release photos, contracts, signatures" 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
@@ -91,9 +89,8 @@ 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 2_125_672
expect(account.storage_total).to eq 1_069_936
end
it "sums only for projects tied to account" do
@@ -129,8 +126,8 @@ RSpec.describe Account do
Download,
User,
Broadcast,
Account,
ZoomMeeting
TaskRequest,
Account
]
Rails.application.eager_load!
ActiveRecord::Base.descendants.each do |model|

View File

@@ -6,7 +6,6 @@ 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)
@@ -15,7 +14,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.headshot_collection_uid)
expect(collection.collection_uid).to eq(project.id)
end
context "when a release has no headshot photo attachment" do
@@ -86,17 +85,6 @@ 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
end
private

View File

@@ -0,0 +1,16 @@
require 'rails_helper'
RSpec.describe TaskRequest, type: :model do
describe "associations" do
it { is_expected.to belong_to(:project) }
end
describe "enums" do
it { is_expected.to define_enum_for(:status).with_values([:pending, :completed, :cancelled]) }
end
describe "#order_by_recent" do
subject { described_class }
it { is_expected.to respond_to(:order_by_recent) }
end
end

View File

@@ -16,17 +16,6 @@ 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

@@ -15,10 +15,6 @@ 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) }
@@ -37,32 +33,6 @@ 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) }
@@ -109,7 +79,7 @@ describe ContractTemplatePolicy do
context "for associate" do
let(:user) { create(:user, :associate, primary_account: account) }
it { is_expected.to include(member_project.contract_templates.first) }
it { is_expected.not_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