require 'spec_helper' RSpec.describe CanvasSync::Processors::ProvisioningReportProcessor do let(:subject) { CanvasSync::Processors::ProvisioningReportProcessor } describe '#process' do it 'process users' do expect { subject.process('spec/support/fixtures/reports/users.csv', { models: ['users'] }, 1) }.to change { User.count }.by(2) end it 'processes courses' do expect { subject.process('spec/support/fixtures/reports/courses.csv', { models: ['courses'] }, 1) }.to change { Course.count }.by(2) course = Course.first expect(course.start_date).to eq DateTime.parse("2017-03-27 21:53:18") expect(course.end_date).to eq DateTime.parse("2017-04-27 12:21:18") end it 'processes enrollments' do expect { subject.process('spec/support/fixtures/reports/enrollments.csv', { models: ['enrollments'] }, 1) }.to change { Enrollment.count }.by(2) end it 'processes sections' do expect { subject.process('spec/support/fixtures/reports/sections.csv', { models: ['sections'] }, 1) }.to change { Section.count }.by(2) section = Section.first expect(section.start_date).to eq DateTime.parse("2017-03-27 21:53:18") expect(section.end_date).to eq DateTime.parse("2017-03-27 21:53:18") end it 'processes xlist' do subject.process('spec/support/fixtures/reports/xlist.csv', { models: ['xlist'] }, 1) expect(Section.where.not(canvas_nonxlist_course_id: nil).count).to eq 1 cross_listed_section = Section.where.not(canvas_nonxlist_course_id: nil).first expect(cross_listed_section.canvas_section_id).to eq 2 expect(cross_listed_section.canvas_nonxlist_course_id).to eq 2 end context 'options[:models] is multiple models' do it 'extracts the ZIP and processes each model' do user_count = User.count course_count = Course.count subject.process('spec/support/fixtures/reports/provisioning_csv', { models: ['courses', 'users'] }, 1) expect(User.count).to eq(user_count + 2) expect(Course.count).to eq(course_count + 2) end end context 'legacy_support is true' do it 'uses the LegacyImporter' do expect(User).to receive(:create_or_update_from_csv).at_least(:once) subject.process('spec/support/fixtures/reports/users.csv', { models: ['users'], legacy_support: true }, 1) end end end end