diff --git a/doc/api/live_events.md b/doc/api/live_events.md index 8f74f9be654..88fd8716745 100644 --- a/doc/api/live_events.md +++ b/doc/api/live_events.md @@ -342,6 +342,7 @@ by `asset_type` and `asset_id`. | `url` | The URL of the submission (for 'online_url' submissions) | | `attempt` | This is the submission attempt number. | | `lti_assignment_id` | The LTI assignment guid of the submission's assignment | +| `group_id` | The submissions’s group ID if the assignment is a group assignment. | #### `submission_updated` @@ -361,6 +362,7 @@ by `asset_type` and `asset_id`. | `url` | The URL of the submission (for 'online_url' submissions) | | `attempt` | This is the submission attempt number. | | `lti_assignment_id` | The LTI assignment guid of the submission's assignment | +| `group_id` | The submissions’s group ID if the assignment is a group assignment. | #### `plagiarism_resubmit` @@ -380,6 +382,7 @@ by `asset_type` and `asset_id`. | `url` | The URL of the submission (for 'online_url' submissions) | | `attempt` | This is the submission attempt number. | | `lti_assignment_id` | The LTI assignment guid of the submission's assignment | +| `group_id` | The submissions’s group ID if the assignment is a group assignment. | #### `user_created` diff --git a/lib/canvas/live_events.rb b/lib/canvas/live_events.rb index 0a98599afb4..90375e5b0aa 100644 --- a/lib/canvas/live_events.rb +++ b/lib/canvas/live_events.rb @@ -199,7 +199,8 @@ module Canvas::LiveEvents body: LiveEvents.truncate(submission.body), url: submission.url, attempt: submission.attempt, - lti_assignment_id: submission.assignment.lti_context_id + lti_assignment_id: submission.assignment.lti_context_id, + group_id: submission.group_id } end diff --git a/spec/lib/canvas/live_events_spec.rb b/spec/lib/canvas/live_events_spec.rb index 3a85eefe0d5..168d547a529 100644 --- a/spec/lib/canvas/live_events_spec.rb +++ b/spec/lib/canvas/live_events_spec.rb @@ -367,50 +367,89 @@ describe Canvas::LiveEvents do end end - describe ".submission_created" do - it "should include the user_id and assignment_id" do + context 'submissions' do + let(:submission) do course_with_student_submissions - submission = @course.assignments.first.submissions.first - - expect_event('submission_created', - hash_including( - user_id: @student.global_id.to_s, - lti_user_id: @student.lti_context_id, - assignment_id: submission.global_assignment_id.to_s, - lti_assignment_id: submission.assignment.lti_context_id.to_s - )) - Canvas::LiveEvents.submission_created(submission) + @course.assignments.first.submissions.first end - end - describe ".submission_updated" do - it "should include the user_id and assignment_id" do - course_with_student_submissions - submission = @course.assignments.first.submissions.first - - expect_event('submission_updated', - hash_including( - user_id: @student.global_id.to_s, - lti_user_id: @student.lti_context_id, - assignment_id: submission.global_assignment_id.to_s, - lti_assignment_id: submission.assignment.lti_context_id.to_s - )) - Canvas::LiveEvents.submission_updated(submission) + let(:group) do + Group.create!( + name: 'test group', + workflow_state: 'available', + context: submission.assignment.course + ) end - end - describe '.plagiarism_resubmit' do - it "should include the user_id and assignment_id" do - course_with_student_submissions - submission = @course.assignments.first.submissions.first - expect_event('plagiarism_resubmit', - hash_including( - user_id: @student.global_id.to_s, - lti_user_id: @student.lti_context_id, - assignment_id: submission.global_assignment_id.to_s, - lti_assignment_id: submission.assignment.lti_context_id.to_s - )) - Canvas::LiveEvents.plagiarism_resubmit(submission) + before { submission } + + describe ".submission_created" do + it "should include the user_id and assignment_id" do + expect_event('submission_created', + hash_including( + user_id: @student.global_id.to_s, + lti_user_id: @student.lti_context_id, + assignment_id: submission.global_assignment_id.to_s, + lti_assignment_id: submission.assignment.lti_context_id.to_s + )) + Canvas::LiveEvents.submission_created(submission) + end + + it 'should include the group_id if assignment is a group assignment' do + submission.update_attributes(group: group) + + expect_event('submission_created', + hash_including( + group_id: group.id.to_s + )) + Canvas::LiveEvents.submission_created(submission) + end + end + + describe ".submission_updated" do + it "should include the user_id and assignment_id" do + expect_event('submission_updated', + hash_including( + user_id: @student.global_id.to_s, + lti_user_id: @student.lti_context_id, + assignment_id: submission.global_assignment_id.to_s, + lti_assignment_id: submission.assignment.lti_context_id.to_s + )) + Canvas::LiveEvents.submission_updated(submission) + end + + it 'should include the group_id if assignment is a group assignment' do + submission.update_attributes(group: group) + + expect_event('submission_updated', + hash_including( + group_id: group.id.to_s + )) + Canvas::LiveEvents.submission_updated(submission) + end + end + + describe '.plagiarism_resubmit' do + it "should include the user_id and assignment_id" do + expect_event('plagiarism_resubmit', + hash_including( + user_id: @student.global_id.to_s, + lti_user_id: @student.lti_context_id, + assignment_id: submission.global_assignment_id.to_s, + lti_assignment_id: submission.assignment.lti_context_id.to_s + )) + Canvas::LiveEvents.plagiarism_resubmit(submission) + end + + it 'should include the group_id if assignment is a group assignment' do + submission.update_attributes(group: group) + + expect_event('plagiarism_resubmit', + hash_including( + group_id: group.id.to_s + )) + Canvas::LiveEvents.plagiarism_resubmit(submission) + end end end