|
9 | 9 | let(:cohort_identifier) { cohort.identifier } |
10 | 10 | let(:headship_course) { create(:course, :headship) } |
11 | 11 | let(:csv_file_path) { csv_file.path } |
| 12 | + let(:updater) { instance_double(CourseCohortProviders::Updater, call: nil) } |
12 | 13 |
|
13 | 14 | let(:csv_file) do |
14 | 15 | tempfile <<~CSV |
|
21 | 22 | before do |
22 | 23 | cohort |
23 | 24 | headship_course |
| 25 | + allow(CourseCohortProviders::Updater).to receive(:new).and_return(updater) |
24 | 26 | end |
25 | 27 |
|
26 | 28 | after do |
|
54 | 56 | context "when dry run is false" do |
55 | 57 | let(:dry_run) { "false" } |
56 | 58 |
|
57 | | - it "creates course cohorts" do |
58 | | - run_task |
59 | | - expect(cohort.course_cohorts.pluck(:course_id)).to contain_exactly(headship_course.id) |
60 | | - end |
61 | | - |
62 | | - it "creates course cohort providers" do |
63 | | - run_task |
64 | | - course_cohort = cohort.course_cohorts.find_by(course: headship_course) |
65 | | - expect(headship_course.course_cohort_providers.where(course_cohort:).pluck(:lead_provider_id)).to( |
66 | | - contain_exactly( |
67 | | - LeadProvider.find_by(name: "Ambition Institute").id, |
68 | | - LeadProvider.find_by(name: "Best Practice Network").id, |
69 | | - ), |
| 59 | + it "calls the updater" do |
| 60 | + expect(CourseCohortProviders::Updater).to receive(:new).with( |
| 61 | + cohort:, |
| 62 | + course_to_provider_csv: csv_file_path, |
| 63 | + dry_run: false, |
| 64 | + logger: Rails.logger, |
70 | 65 | ) |
| 66 | + expect(updater).to receive(:call) |
| 67 | + run_task |
71 | 68 | end |
72 | 69 | end |
73 | 70 |
|
74 | 71 | context "when dry run is true" do |
75 | | - it "does not create course cohorts" do |
76 | | - run_task |
77 | | - expect(CourseCohort.count).to eq 0 |
78 | | - end |
79 | | - |
80 | | - it "does not create course cohort providers" do |
| 72 | + it "calls the updater" do |
| 73 | + expect(CourseCohortProviders::Updater).to receive(:new).with( |
| 74 | + cohort:, |
| 75 | + course_to_provider_csv: csv_file_path, |
| 76 | + dry_run: true, |
| 77 | + logger: Rails.logger, |
| 78 | + ) |
| 79 | + expect(updater).to receive(:call) |
81 | 80 | run_task |
82 | | - expect(CourseCohortProvider.count).to eq 0 |
83 | 81 | end |
84 | 82 | end |
85 | 83 | end |
|
0 commit comments