fix discussion edit endpoint to create checkpoint

fix the discussion edit endpoint to create
checkpoints if none are found. This is to allow
editing a non checkpointed discussion into a
checkpointed discussion

closes VICE-4216
flag=discussion_checkpoints
flag=discussion_create

Test Plan:
- have a graded discussion that is not
  checkpointed
- go to edit the discussion and make it a
  checkpointed discussion and input checkpoint
  settings values
- save the discussion
- go back to edit the discussion and see that
  the discussion is now checkpointed with the
  respective checkpoint settings values

Change-Id: If8d285fd4c168ed0d02bf07a5198003c25ac31b3
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/345780
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
QA-Review: Caleb Guanzon <cguanzon@instructure.com>
Reviewed-by: Jason Gillett <jason.gillett@instructure.com>
Product-Review: Samuel Lee <samuel.lee@instructure.com>
This commit is contained in:
Samuel Lee 2024-04-20 09:35:53 -05:00
parent cecaf7659b
commit f5af977ec2
3 changed files with 70 additions and 2 deletions

View File

@ -103,10 +103,15 @@ class Mutations::UpdateDiscussionTopic < Mutations::DiscussionBase
if discussion_topic.assignment && input[:checkpoints]&.count == DiscussionTopic::REQUIRED_CHECKPOINT_COUNT
return validation_error(I18n.t("If checkpoints are defined, forCheckpoints: true must be provided to the discussion topic assignment.")) unless input.dig(:assignment, :for_checkpoints)
checkpoint_service = if discussion_topic.assignment.has_sub_assignments
Checkpoints::DiscussionCheckpointUpdaterService
else
Checkpoints::DiscussionCheckpointCreatorService
end
input[:checkpoints].each do |checkpoint|
dates = checkpoint[:dates]
Checkpoints::DiscussionCheckpointUpdaterService.call(
checkpoint_service.call(
discussion_topic:,
checkpoint_label: checkpoint[:checkpoint_label],
points_possible: checkpoint[:points_possible],

View File

@ -638,5 +638,39 @@ RSpec.describe Mutations::UpdateDiscussionTopic do
expect(active_checkpoints.count).to eq(0)
end
it "can edit a non-checkpointed discussion to a checkpointed discussion" do
@discussion_assignment = @course.assignments.create!(
title: "Graded Topic 1",
submission_types: "discussion_topic",
post_to_sis: false,
grading_type: "points",
points_possible: 5,
due_at: 3.months.from_now,
peer_reviews: false
)
@non_checkpoint_topic = @discussion_assignment.discussion_topic
run_mutation(id: @non_checkpoint_topic.id, assignment: { forCheckpoints: true }, checkpoints: [
{ checkpointLabel: CheckpointLabels::REPLY_TO_TOPIC, dates: [{ type: "everyone", dueAt: @due_at1.iso8601 }], pointsPossible: 6 },
{ checkpointLabel: CheckpointLabels::REPLY_TO_ENTRY, dates: [{ type: "everyone", dueAt: @due_at2.iso8601 }], pointsPossible: 8, repliesRequired: 5 }
])
assignment = Assignment.last
expect(assignment.has_sub_assignments?).to be true
expect(DiscussionTopic.last.reply_to_entry_required_count).to eq 5
sub_assignments = SubAssignment.where(parent_assignment_id: assignment.id)
sub_assignment1 = sub_assignments.find_by(sub_assignment_tag: CheckpointLabels::REPLY_TO_TOPIC)
sub_assignment2 = sub_assignments.find_by(sub_assignment_tag: CheckpointLabels::REPLY_TO_ENTRY)
expect(sub_assignment1.sub_assignment_tag).to eq "reply_to_topic"
expect(sub_assignment1.points_possible).to eq 6
expect(sub_assignment2.sub_assignment_tag).to eq "reply_to_entry"
expect(sub_assignment2.points_possible).to eq 8
expect(assignment.points_possible).to eq 14
end
end
end

View File

@ -1096,6 +1096,35 @@ describe "discussions" do
expect(assignment.sub_assignments.count).to eq 0
expect(Assignment.last.has_sub_assignments).to be(false)
end
it "can edit a non-checkpointed discussion into a checkpointed discussion" do
graded_discussion = create_graded_discussion(course)
get "/courses/#{course.id}/discussion_topics/#{graded_discussion.id}/edit"
force_click_native('input[type=checkbox][value="checkpoints"]')
f("input[data-testid='points-possible-input-reply-to-topic']").send_keys :backspace
f("input[data-testid='points-possible-input-reply-to-topic']").send_keys "5"
f("input[data-testid='reply-to-entry-required-count']").send_keys :backspace
f("input[data-testid='reply-to-entry-required-count']").send_keys "6"
f("input[data-testid='points-possible-input-reply-to-entry']").send_keys :backspace
f("input[data-testid='points-possible-input-reply-to-entry']").send_keys "7"
fj("button:contains('Save')").click
assignment = Assignment.last
expect(assignment.has_sub_assignments?).to be true
expect(DiscussionTopic.last.reply_to_entry_required_count).to eq 6
sub_assignments = SubAssignment.where(parent_assignment_id: assignment.id)
sub_assignment1 = sub_assignments.find_by(sub_assignment_tag: CheckpointLabels::REPLY_TO_TOPIC)
sub_assignment2 = sub_assignments.find_by(sub_assignment_tag: CheckpointLabels::REPLY_TO_ENTRY)
expect(sub_assignment1.points_possible).to eq 5
expect(sub_assignment2.points_possible).to eq 7
end
end
end
end