update pace duration calculation to include day enrolled

fixes LS-3582
flag=none

test plan:
  - tests pass

qa risk: low

Change-Id: Ifdc4dd0ff12df1ca7b0b26a450de634e81ec5f34
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/305148
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
Reviewed-by: Robin Kuss <rkuss@instructure.com>
QA-Review: Robin Kuss <rkuss@instructure.com>
Product-Review: Davis Hyer <dhyer@instructure.com>
This commit is contained in:
Davis Hyer 2022-11-10 10:47:49 -07:00
parent 85433e568e
commit 1fed5deb3e
4 changed files with 15 additions and 7 deletions

View File

@ -94,8 +94,16 @@ class CoursePace < ActiveRecord::Base
end
end
# We need to add one day to the sum of durations here to
# account for the oddity of the first item's set due date.
# If a user is enrolled via a pace item with a duration of
# one day on Jan 1 at 11:58pm, their due date would be on
# Jan 2 at 11:59pm. If that same user were enrolled on Jan
# 2 at 12:00am, their due date would be Jan 3 at 11:59pm.
# While this oddity of finishing out the current day exists,
# we will always need to add one to the sum of durations.
def duration
course_pace_module_items.sum(:duration)
course_pace_module_items.sum(:duration) + 1
end
def valid_secondary_context

View File

@ -160,8 +160,8 @@ describe CoursePace do
end
describe "#duration" do
it "returns 0 if there are no module items" do
expect(@course_pace.duration).to eq 0
it "returns 1 if there are no module items" do
expect(@course_pace.duration).to eq 1
end
context "multiple paced module items exist" do
@ -171,8 +171,8 @@ describe CoursePace do
end
end
it "returns the sum of all item durations" do
expect(@course_pace.duration).to eq 2
it "returns the sum of all item durations, taking into account the day of enrollment" do
expect(@course_pace.duration).to eq 3
end
end
end

View File

@ -54,7 +54,7 @@ describe "Pace Contexts API" do
applied_pace_json = course_json["applied_pace"]
expect(applied_pace_json["name"]).to eq course.name
expect(applied_pace_json["type"]).to eq "Course"
expect(applied_pace_json["duration"]).to eq 0
expect(applied_pace_json["duration"]).to eq 1
expect(Time.parse(applied_pace_json["last_modified"])).to be_within(1.second).of(default_pace.published_at)
end

View File

@ -105,7 +105,7 @@ describe "course pace landing page" do
expect(course_pace_context_table).to be_displayed
expect(number_of_students.text).to include("1")
expect(number_of_sections.text).to include("2")
expect(default_duration.text).to include("2 days")
expect(default_duration.text).to include("3 days")
end
end