Add overrides to Checkpoints in REST API
closes VICE-4039 flag=discussion_checkpoints Test plan: - Specs pass. - Create a Checkpointed Discussion Topic with overrides using DiscussionCheckpointCreatorService. For an example, look at the specs. - Call the REST API and verify that overrides are there: - /api/v1/courses/[Course ID]/assignments.json?include[]=checkpoints - /api/v1/courses/[Course ID]/assignments/[Assignment ID].json?include[]=checkpoints Change-Id: I7882014e287f6d0881681134958d1ad6f4251bdf Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/344243 Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com> Reviewed-by: Caleb Guanzon <cguanzon@instructure.com> QA-Review: Jason Gillett <jason.gillett@instructure.com> Product-Review: Omar Soto-Fortuño <omar.soto@instructure.com>
This commit is contained in:
parent
1d8821b025
commit
71cc32fdd1
|
@ -172,7 +172,7 @@ module Api::V1::Assignment
|
|||
|
||||
if opts[:include_checkpoints] && assignment.root_account.feature_enabled?(:discussion_checkpoints)
|
||||
hash["has_sub_assignments"] = assignment.has_sub_assignments?
|
||||
hash["checkpoints"] = assignment.sub_assignments.map { |sub_assignment| Checkpoint.new(sub_assignment).as_json }
|
||||
hash["checkpoints"] = assignment.sub_assignments.map { |sub_assignment| Checkpoint.new(sub_assignment, user).as_json }
|
||||
end
|
||||
|
||||
if opts[:overrides].present?
|
||||
|
|
|
@ -19,8 +19,11 @@
|
|||
#
|
||||
|
||||
class Checkpoint
|
||||
def initialize(assignment)
|
||||
include Api::V1::AssignmentOverride
|
||||
|
||||
def initialize(assignment, user)
|
||||
@assignment = assignment
|
||||
@user = user
|
||||
end
|
||||
|
||||
def as_json
|
||||
|
@ -29,7 +32,8 @@ class Checkpoint
|
|||
tag:,
|
||||
points_possible:,
|
||||
due_at:,
|
||||
only_visible_to_overrides:
|
||||
only_visible_to_overrides:,
|
||||
overrides:
|
||||
}
|
||||
end
|
||||
|
||||
|
@ -54,4 +58,12 @@ class Checkpoint
|
|||
def only_visible_to_overrides
|
||||
@assignment.only_visible_to_overrides
|
||||
end
|
||||
|
||||
def overrides
|
||||
assignment_overrides_json(@assignment.assignment_overrides.select(&:active?), @user)
|
||||
end
|
||||
|
||||
def session
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
|
|
@ -88,12 +88,20 @@ describe AssignmentsApiController, type: :request do
|
|||
assignment = @course.assignments.create!(title: "Assignment 1", has_sub_assignments: true)
|
||||
@c1 = assignment.sub_assignments.create!(context: assignment.context, sub_assignment_tag: CheckpointLabels::REPLY_TO_TOPIC, points_possible: 5, due_at: 3.days.from_now)
|
||||
@c2 = assignment.sub_assignments.create!(context: assignment.context, sub_assignment_tag: CheckpointLabels::REPLY_TO_ENTRY, points_possible: 10, due_at: 5.days.from_now)
|
||||
|
||||
user = user_factory(active_all: true)
|
||||
@course.enroll_student(user).accept!
|
||||
@students = [user]
|
||||
|
||||
create_adhoc_override_for_assignment(@c2, @students, due_at: 2.days.from_now)
|
||||
end
|
||||
|
||||
it "returns the assignments list with API-formatted Checkpoint data" do
|
||||
json = api_get_assignments_index_from_course(@course, include: ["checkpoints"])
|
||||
assignment = json.first
|
||||
checkpoints = assignment["checkpoints"]
|
||||
first_checkpoint = checkpoints.find { |c| c["tag"] == CheckpointLabels::REPLY_TO_TOPIC }
|
||||
second_checkpoint = checkpoints.find { |c| c["tag"] == CheckpointLabels::REPLY_TO_ENTRY }
|
||||
|
||||
expect(assignment["has_sub_assignments"]).to be_truthy
|
||||
|
||||
|
@ -103,6 +111,10 @@ describe AssignmentsApiController, type: :request do
|
|||
expect(checkpoints.pluck("points_possible")).to match_array [@c1.points_possible, @c2.points_possible]
|
||||
expect(checkpoints.pluck("due_at")).to match_array [@c1.due_at.iso8601, @c2.due_at.iso8601]
|
||||
expect(checkpoints.pluck("only_visible_to_overrides")).to match_array [@c1.only_visible_to_overrides, @c2.only_visible_to_overrides]
|
||||
expect(first_checkpoint["overrides"].length).to eq 0
|
||||
expect(second_checkpoint["overrides"].length).to eq 1
|
||||
expect(second_checkpoint["overrides"].first["assignment_id"]).to eq @c2.id
|
||||
expect(second_checkpoint["overrides"].first["student_ids"]).to match_array @students.map(&:id)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -239,11 +239,18 @@ describe "Api::V1::Assignment" do
|
|||
|
||||
@c1 = assignment.sub_assignments.create!(context: assignment.context, sub_assignment_tag: CheckpointLabels::REPLY_TO_TOPIC, points_possible: 5, due_at: 2.days.from_now)
|
||||
@c2 = assignment.sub_assignments.create!(context: assignment.context, sub_assignment_tag: CheckpointLabels::REPLY_TO_ENTRY, points_possible: 5, due_at: 5.days.from_now)
|
||||
|
||||
@student = @assignment.course.enroll_student(User.create!, enrollment_state: "active").user
|
||||
@students = [@student]
|
||||
|
||||
create_adhoc_override_for_assignment(@c2, @students, due_at: 2.days.from_now)
|
||||
end
|
||||
|
||||
it "returns the checkpoints attribute with the correct values" do
|
||||
json = api.assignment_json(assignment, user, session, { include_checkpoints: true })
|
||||
json = api.assignment_json(assignment, @student, session, { include_checkpoints: true })
|
||||
checkpoints = json["checkpoints"]
|
||||
first_checkpoint = checkpoints.find { |c| c[:tag] == CheckpointLabels::REPLY_TO_TOPIC }
|
||||
second_checkpoint = checkpoints.find { |c| c[:tag] == CheckpointLabels::REPLY_TO_ENTRY }
|
||||
|
||||
expect(json["has_sub_assignments"]).to be_truthy
|
||||
|
||||
|
@ -252,6 +259,10 @@ describe "Api::V1::Assignment" do
|
|||
expect(checkpoints.pluck(:points_possible)).to match_array [@c1.points_possible, @c2.points_possible]
|
||||
expect(checkpoints.pluck(:due_at)).to match_array [@c1.due_at, @c2.due_at]
|
||||
expect(checkpoints.pluck(:only_visible_to_overrides)).to match_array [@c1.only_visible_to_overrides, @c2.only_visible_to_overrides]
|
||||
expect(first_checkpoint[:overrides].length).to eq 0
|
||||
expect(second_checkpoint[:overrides].length).to eq 1
|
||||
expect(second_checkpoint[:overrides].first[:assignment_id]).to eq @c2.id
|
||||
expect(second_checkpoint[:overrides].first[:student_ids]).to match_array @students.map(&:id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -20,22 +20,39 @@
|
|||
describe Checkpoint do
|
||||
describe "#as_json" do
|
||||
it "returns a hash with the correct keys" do
|
||||
assignment = Assignment.new(
|
||||
course_with_teacher(active_all: true)
|
||||
|
||||
parent_assignment = @course.assignments.create!
|
||||
|
||||
sub_assignment = SubAssignment.new(
|
||||
name: "Assignment Name",
|
||||
sub_assignment_tag: CheckpointLabels::REPLY_TO_TOPIC,
|
||||
points_possible: 10,
|
||||
due_at: 3.days.from_now,
|
||||
only_visible_to_overrides: false
|
||||
only_visible_to_overrides: false,
|
||||
context: @course,
|
||||
parent_assignment:
|
||||
)
|
||||
|
||||
checkpoint = Checkpoint.new(assignment)
|
||||
expect(checkpoint.as_json).to eq({
|
||||
name: assignment.name,
|
||||
tag: assignment.sub_assignment_tag,
|
||||
points_possible: assignment.points_possible,
|
||||
due_at: assignment.due_at,
|
||||
only_visible_to_overrides: assignment.only_visible_to_overrides
|
||||
})
|
||||
sub_assignment.save!
|
||||
|
||||
user = user_factory(active_all: true)
|
||||
@course.enroll_student(user).accept!
|
||||
students = [user]
|
||||
|
||||
create_adhoc_override_for_assignment(sub_assignment, students, due_at: 2.days.from_now)
|
||||
|
||||
checkpoint = Checkpoint.new(sub_assignment, @teacher)
|
||||
json = checkpoint.as_json
|
||||
|
||||
expect(json[:name]).to eq(sub_assignment.name)
|
||||
expect(json[:tag]).to eq(sub_assignment.sub_assignment_tag)
|
||||
expect(json[:points_possible]).to eq(sub_assignment.points_possible)
|
||||
expect(json[:due_at]).to eq(sub_assignment.due_at)
|
||||
expect(json[:only_visible_to_overrides]).to eq(sub_assignment.only_visible_to_overrides)
|
||||
expect(json[:overrides].length).to eq(1)
|
||||
expect(json[:overrides].first[:assignment_id]).to eq(sub_assignment.id)
|
||||
expect(json[:overrides].first[:student_ids]).to match_array(students.map(&:id))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue