diff --git a/app/graphql/mutations/update_discussion_topic.rb b/app/graphql/mutations/update_discussion_topic.rb index a0aeadb7862..2849e8d817f 100644 --- a/app/graphql/mutations/update_discussion_topic.rb +++ b/app/graphql/mutations/update_discussion_topic.rb @@ -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], diff --git a/spec/graphql/mutations/update_discussion_topic_spec.rb b/spec/graphql/mutations/update_discussion_topic_spec.rb index cc06510103e..1b21b01f965 100644 --- a/spec/graphql/mutations/update_discussion_topic_spec.rb +++ b/spec/graphql/mutations/update_discussion_topic_spec.rb @@ -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 diff --git a/spec/selenium/discussions/discussions_edit_page_spec.rb b/spec/selenium/discussions/discussions_edit_page_spec.rb index cf2a6c81fed..f6f19dcc0be 100644 --- a/spec/selenium/discussions/discussions_edit_page_spec.rb +++ b/spec/selenium/discussions/discussions_edit_page_spec.rb @@ -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