Skip to content

Commit

Permalink
[CPDNPQ-2437] Fix course calculator allowed_declaration_types
Browse files Browse the repository at this point in the history
  • Loading branch information
rwrrll committed Jan 7, 2025
1 parent ac60e83 commit 77ddc2b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
5 changes: 4 additions & 1 deletion app/services/statements/course_calculator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ def output_payment_subtotal
end

def allowed_declaration_types
course.schedule_for(cohort:).allowed_declaration_types.sort_by { Schedule::DECLARATION_TYPES.index(_1) }
Schedule.where(cohort:, course_group: course.course_group)
.flat_map(&:allowed_declaration_types)
.uniq
.sort_by { Schedule::DECLARATION_TYPES.index(_1) }
end

def declaration_count_for_declaration_type(declaration_type)
Expand Down
14 changes: 14 additions & 0 deletions spec/services/statements/course_calculator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,20 @@
end
end

describe "#allowed_declaration_types" do
let(:course_group) { course.course_group }

before do
course_group.schedules.destroy_all
create(:schedule, course_group:, cohort:, allowed_declaration_types: %w[started retained-1])
create(:schedule, course_group:, cohort:, allowed_declaration_types: %w[retained-1 completed])
end

it "is derived from schedules" do
expect(subject.allowed_declaration_types).to eql(%w[started retained-1 completed])
end
end

describe "#output_payment" do
it "is a hash" do
expect(subject.output_payment).to be_a(Hash)
Expand Down

0 comments on commit 77ddc2b

Please sign in to comment.