require 'spec_helper' RSpec.describe CanvasSync do describe '.provisioning_sync' do it 'invokes the first job in the queue and passes on the rest of the job chain' do expected_job_chain = CanvasSync.default_provisioning_report_chain(['courses'], nil) first_job = expected_job_chain[:jobs].shift expect(CanvasSync::Jobs::SyncTermsJob).to receive(:perform_later) .with( expected_job_chain, first_job[:options] ) CanvasSync.provisioning_sync(['courses']) end context 'an invalid model is passed in' do it 'raises a helpful exception' do expect { CanvasSync.provisioning_sync(['courses', 'cheeses']) }.to raise_error("Invalid model(s) specified: cheeses. Only #{CanvasSync::SUPPORTED_MODELS.join(', ')} are supported.") end end describe '.default_provisioning_report_chain' do context 'we are syncing users with a term scope' do it 'syncs the users in a separate job that runs first' do chain = CanvasSync.default_provisioning_report_chain(['users', 'courses'], :active) expect(chain).to eq({ jobs: [ { job: CanvasSync::Jobs::SyncTermsJob.to_s, options: {} }, { job: CanvasSync::Jobs::SyncUsersJob.to_s, options: {} }, { job: CanvasSync::Jobs::SyncProvisioningReportJob.to_s, options: { term_scope: 'active', models: ['courses'] } } ], global_options: { legacy_support: false } }) end end context 'we are syncing users without a term scope' do it 'syncs users along with the rest of the provisioning report' do chain = CanvasSync.default_provisioning_report_chain(['users', 'courses']) expect(chain).to eq({ jobs: [ { job: CanvasSync::Jobs::SyncTermsJob.to_s, options: {} }, { job: CanvasSync::Jobs::SyncProvisioningReportJob.to_s, options: { term_scope: nil, models: ['users', 'courses'] } } ], global_options: { legacy_support: false } }) end end context 'we are syncing roles with a term scope' do it 'syncs the roles in a separate job that runs first' do chain = CanvasSync.default_provisioning_report_chain(['roles', 'courses'], :active) expect(chain).to eq({ jobs: [ { job: CanvasSync::Jobs::SyncTermsJob.to_s, options: {} }, { job: CanvasSync::Jobs::SyncRolesJob.to_s, options: {} }, { job: CanvasSync::Jobs::SyncProvisioningReportJob.to_s, options: { term_scope: 'active', models: ['courses'] } } ], global_options: { legacy_support: false } }) end end context 'we are syncing roles without a term scope' do it 'syncs roles separately even with no term scope' do chain = CanvasSync.default_provisioning_report_chain(['roles', 'courses']) expect(chain).to eq({ jobs: [ { job: CanvasSync::Jobs::SyncTermsJob.to_s, options: {} }, { job: CanvasSync::Jobs::SyncRolesJob.to_s, options: {} }, { job: CanvasSync::Jobs::SyncProvisioningReportJob.to_s, options: { term_scope: nil, models: ['courses'] } } ], global_options: { legacy_support: false } }) end end context 'we are syncing admins with a term scope' do it 'syncs the admins in a separate job that runs first' do chain = CanvasSync.default_provisioning_report_chain(['admins', 'courses'], :active) expect(chain).to eq({ jobs: [ { job: CanvasSync::Jobs::SyncTermsJob.to_s, options: {} }, { job: CanvasSync::Jobs::SyncAdminsJob.to_s, options: {} }, { job: CanvasSync::Jobs::SyncProvisioningReportJob.to_s, options: { term_scope: 'active', models: ['courses'] } } ], global_options: { legacy_support: false } }) end end context 'we are syncing admins without a term scope' do it 'syncs admins separately even with no term scope' do chain = CanvasSync.default_provisioning_report_chain(['admins', 'courses']) expect(chain).to eq({ jobs: [ { job: CanvasSync::Jobs::SyncTermsJob.to_s, options: {} }, { job: CanvasSync::Jobs::SyncAdminsJob.to_s, options: {} }, { job: CanvasSync::Jobs::SyncProvisioningReportJob.to_s, options: { term_scope: nil, models: ['courses'] } } ], global_options: { legacy_support: false } }) end end context "we are syncing assignments" do it "appends the SyncAssignmentsJob" do chain = CanvasSync.default_provisioning_report_chain(%w[users enrollments assignments]) expect(chain).to eq( jobs: [ { job: CanvasSync::Jobs::SyncTermsJob.to_s, options: {} }, { job: CanvasSync::Jobs::SyncProvisioningReportJob.to_s, options: { term_scope: nil, models: %w[users enrollments] } }, { job: CanvasSync::Jobs::SyncAssignmentsJob.to_s, options: {} }, ], global_options: { legacy_support: false }, ) end end context "we are syncing submissions" do it "appends the SyncSubmissionsJob" do chain = CanvasSync.default_provisioning_report_chain(%w[users enrollments submissions]) expect(chain).to eq( jobs: [ { job: CanvasSync::Jobs::SyncTermsJob.to_s, options: {} }, { job: CanvasSync::Jobs::SyncProvisioningReportJob.to_s, options: { term_scope: nil, models: %w[users enrollments] } }, { job: CanvasSync::Jobs::SyncSubmissionsJob.to_s, options: {} }, ], global_options: { legacy_support: false }, ) end end context "we are syncing assignment groups" do it "appends the SyncAssignmentGroupsJob" do chain = CanvasSync.default_provisioning_report_chain(%w[users enrollments assignment_groups]) expect(chain).to eq( jobs: [ { job: CanvasSync::Jobs::SyncTermsJob.to_s, options: {} }, { job: CanvasSync::Jobs::SyncProvisioningReportJob.to_s, options: { term_scope: nil, models: %w[users enrollments] } }, { job: CanvasSync::Jobs::SyncAssignmentGroupsJob.to_s, options: {} }, ], global_options: { legacy_support: false }, ) end end end end describe ".simple_report_sync" do it 'invokes the first job in the queue and passes on the rest of the job chain' do expected_job_chain = CanvasSync.simple_report_chain( [ { report_name: 'proservices_provisioning_csv', model: 'users', params: { "parameters[include_deleted]" => true, "parameters[users]" => true } } ] ) first_job = expected_job_chain[:jobs].shift expect(CanvasSync::Jobs::SyncSimpleTableJob).to receive(:perform_later) .with( expected_job_chain, first_job[:options] ) CanvasSync.simple_report_sync( [ { report_name: 'proservices_provisioning_csv', model: 'users', params: { "parameters[include_deleted]" => true, "parameters[users]" => true } } ] ) end it 'receives the job chain for the specified table' do chain = CanvasSync.simple_report_chain( [ { report_name: 'proservices_provisioning_csv', model: 'users', params: { "parameters[include_deleted]" => true, "parameters[users]" => true } } ] ) expected_job_chain = { jobs: [ { job: CanvasSync::Jobs::SyncSimpleTableJob.to_s, options: { report_name: 'proservices_provisioning_csv', model: 'users', mapping: 'users', klass: 'User', term_scope: nil, params: { "parameters[include_deleted]" => true, "parameters[users]" => true } } } ], global_options: {} } expect(chain).to eq(expected_job_chain) end end end