peer reviews api

refs: PFS-2071, PFS-2072, PFS-2073, PFS-2074

**Test Plan
PFS-2071
1. Create course with assignment, teacher and two students
2. setup peer reviews on assignment
3. As student 1 create a submission
4. As student 2 peer review submission, leave comments
5. execute the following api courses/:course_id/assignments/:assignment_id/peer_reviews
6. As account admin all information should be shown
7. As teacher all information should be shown
8. As student should see all information
9. Repeat above but set anonymous peer reviews on assignment
10. As account admin all information should be shown
11. As teacher all information should be shown
12. As student should see comments but all reviewer
information should not be shown
13. include the following include parameters, include[]=submission_comments,
include[]=user make sure additional information is shown according to parameter.

PFS-2072
1. Follow setup from PFS-2071
2. execute a get on the following api
   /api/v1/courses/:course_id/assignments/:assignment_id/submissions/:submission_id/peer_reviews
3. validate that only peer reviews for the given submission are shown

PFS-2073
1. Follow setup from PFS-2071
2. execute a post on the following api, including a user_id parameter
   /api/v1/courses/:course_id/assignments/:assignment1_id/submissions/:submission_id/peer_reviews
3. validate that user from user_id parameter is added as a reviwer on the submission

PFS-2074
1. follow setup from PFS-2071
2. execute a delete on the following api, including a user_id parameter
   /api/v1/courses/:course_id/assignments/:assignment1_id/submissions/:submission_id/peer_reviews
3. validate that user from user_id parameter is removed as a reviewer on the submission

(cherry picked from commit 91744bbcd5a81be968139b1f68b65c3e9eaa7b4a)

Change-Id: Ic09a16956cddb2f113625ff61bc733503d713abb
Reviewed-on: https://gerrit.instructure.com/56936
Tested-by: Jenkins
QA-Review: Adam Stone <astone@instructure.com>
Reviewed-by: John Corrigan <jcorrigan@instructure.com>
Product-Review: Brandon Broschinsky <brandonbr@instructure.com>
This commit is contained in:
Brandon Broschinsky 2015-06-17 10:34:45 -06:00
parent dbc9c5151e
commit eb216c52c7
8 changed files with 702 additions and 23 deletions

View File

@ -0,0 +1,153 @@
#
# Copyright (C) 2011 - 2015 Instructure, Inc.
#
# This file is part of Canvas.
#
# Canvas is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, version 3 of the License.
#
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
#
# @API Peer Reviews
#
# @model PeerReview
# {
# "id": "PeerReview",
# "description": "",
# "properties":{
# "assessor_id": {
# "description": "The assessors user id",
# "example": 23,
# "type": "integer"
# },
# "asset_id": {
# "description": "The id for the asset associated with this Peer Review",
# "example": 13,
# "type": "integer"
# },
# "asset_type": {
# "description": "The type of the asset",
# "example": "Submission",
# "type": "string"
# },
# "id": {
# "description": "The id of the Peer Review",
# "example": 1,
# "type": "integer"
# },
# "user_id": {
# "description": "The user id for the owner of the asset",
# "example": 7,
# "type": "integer"
# },
# "workflow_state": {
# "description": "The state of the Peer Review, either 'assigned' or 'completed'",
# "example": "assigned",
# "type": "string"
# },
# "user": {
# "description": "the User object for the owner of the asset if the user include parameter is provided (see user API) (optional)",
# "example": "User",
# "type": "string"
# },
# "assessor": {
# "description": "The User object for the assessor if the user include parameter is provided (see user API) (optional)",
# "example": "User",
# "type": "string"
# },
# "submission_comments": {
# "description": "The submission comments associated with this Peer Review if the submission_comment include parameter is provided (see submissions API) (optional)",
# "example": "SubmissionComment",
# "type": "string"
# }
# }
# }
#
class PeerReviewsApiController < ApplicationController
include Api::V1::AssessmentRequest
before_filter :get_course_from_section, :require_context, :require_assignment
before_filter :peer_review_assets, only: [:create, :destroy]
# @API Get all Peer Reviews
# Get a list of all Peer Reviews for this assignment
#
# @argument include[] [String, "submission_comments"|"user"]
# Associations to include with the peer review.
#
# @returns [PeerReview]
def index
assessment_requests = AssessmentRequest.for_assignment(@assignment.id)
unless @assignment.grants_any_right?(@current_user, session, :grade)
assessment_requests = assessment_requests.for_assessee @current_user.id
end
if params.key?(:submission_id)
assessment_requests = assessment_requests.for_asset(params[:submission_id])
end
includes = Set.new(Array(params[:include]))
render :json => assessment_requests_json(assessment_requests, @current_user, session, includes)
end
# @API Create Peer Review
# Create a peer review for the assignment
#
# @argument user_id [Required, Integer]
# user_id to assign as reviewer on this assignment
#
# @returns PeerReview
def create
if authorized_action(@assignment, @current_user, :grade)
assessment_request = @assignment.assign_peer_review(@reviewer, @student)
includes = Set.new(Array(params[:include]))
render :json => assessment_request_json(assessment_request, @current_user, session, includes)
end
end
# @API Create Peer Review
# Delete a peer review for the assignment
#
# @argument user_id [Required, Integer]
# user_id to delete as reviewer on this assignment
#
# @returns PeerReview
def destroy
if authorized_action(@assignment, @current_user, :grade)
assessment_request = AssessmentRequest.for_asset(@submission).
for_assessor(@reviewer).
for_assessee(@student).first
if assessment_request
assessment_request.destroy
render :json => assessment_request_json(assessment_request, @current_user, session, [])
else
render :json => {:errors => {:base => t('errors.delete_reminder_failed', "Delete failed")}},
:status => :bad_request
end
end
end
private
def require_assignment
@assignment = @context.assignments.active.find(params[:assignment_id])
raise ActiveRecord::RecordNotFound unless @assignment
end
def peer_review_assets
@submission = @assignment.submissions.find(params[:submission_id])
@reviewer = @context.students_visible_to(@current_user).find params[:user_id]
@student = @context.students_visible_to(@current_user).find @submission.user.id
end
end

View File

@ -65,6 +65,8 @@ class AssessmentRequest < ActiveRecord::Base
scope :incomplete, where(:workflow_state => 'assigned')
scope :for_assessee, lambda { |user_id| where(:user_id => user_id) }
scope :for_assessor, lambda { |assessor_id| where(:assessor_id => assessor_id) }
scope :for_asset, lambda { |asset_id| where(:asset_id => asset_id)}
scope :for_assignment, lambda { |assignment_id| includes(:submission).where(:submissions => { :assignment_id => assignment_id})}
scope :for_course, lambda { |course_id| includes(:submission).where(:submissions => { :context_code => "course_#{course_id}"})}
scope :for_context_codes, lambda { |context_codes| includes(:submission).where(:submissions => { :context_code =>context_codes })}

View File

@ -934,6 +934,17 @@ CanvasRails::Application.routes.draw do
delete 'courses/:course_id/assignments/:id', action: :destroy, controller: :assignments
end
scope(controller: :peer_reviews_api) do
get 'courses/:course_id/assignments/:assignment_id/peer_reviews', action: :index
get 'sections/:section_id/assignments/:assignment_id/peer_reviews', action: :index
get 'courses/:course_id/assignments/:assignment_id/submissions/:submission_id/peer_reviews', action: :index
get 'sections/:section_id/assignments/:assignment_id/submissions/:submission_id/peer_reviews', action: :index
post 'courses/:course_id/assignments/:assignment_id/submissions/:submission_id/peer_reviews', action: :create
post 'sections/:section_id/assignments/:assignment_id/submissions/:submission_id/peer_reviews', action: :create
delete 'courses/:course_id/assignments/:assignment_id/submissions/:submission_id/peer_reviews', action: :destroy
delete 'sections/:section_id/assignments/:assignment_id/submissions/:submission_id/peer_reviews', action: :destroy
end
scope(controller: :assignment_overrides) do
get 'courses/:course_id/assignments/:assignment_id/overrides', action: :index
post 'courses/:course_id/assignments/:assignment_id/overrides', action: :create

View File

@ -0,0 +1,50 @@
#
# Copyright (C) 2011 - 2015 Instructure, Inc.
#
# This file is part of Canvas.
#
# Canvas is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, version 3 of the License.
#
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
#
module Api::V1::AssessmentRequest
include Api::V1::Json
include Api::V1::Submission
include Api::V1::SubmissionComment
def assessment_request_json(assessment_request, user, session, includes = Set.new)
assignment = assessment_request.asset.assignment
json_attributes = %w(id user_id assessor_id asset_id asset_type workflow_state)
if assignment.anonymous_peer_reviews? && !assignment.grants_any_right?(user, session, :grade)
json_attributes.delete('assessor_id')
end
hash = api_json(assessment_request, user, session, :only => json_attributes)
if includes.include?("user")
hash['user'] = user_display_json(assessment_request.user, @context)
unless assignment.anonymous_peer_reviews? && !assignment.grants_any_right?(user, session, :grade)
hash['assessor'] = user_display_json(assessment_request.assessor, @context)
end
end
if includes.include?("submission_comments")
hash['submission_comments'] = assessment_request.asset.submission_comments.map{ |sc| submission_comment_json(sc, user) }
end
hash
end
def assessment_requests_json(assessment_requests, user, session, includes = Set.new)
assessment_requests.map{ |assessment_request| assessment_request_json(assessment_request, user, session, includes) }
end
end

View File

@ -23,6 +23,7 @@ module Api::V1::Submission
include Api::V1::DiscussionTopics
include Api::V1::Course
include Api::V1::User
include Api::V1::SubmissionComment
def submission_json(submission, assignment, user, session, context = nil, includes = [])
context ||= assignment.context
@ -38,27 +39,7 @@ module Api::V1::Submission
end
if includes.include?("submission_comments")
hash['submission_comments'] = submission.comments_for(@current_user).map do |sc|
sc_hash = sc.as_json(
:include_root => false,
:only => %w(id author_id author_name created_at comment))
if sc.media_comment?
sc_hash['media_comment'] = media_comment_json(:media_id => sc.media_comment_id, :media_type => sc.media_comment_type)
end
sc_hash['attachments'] = sc.attachments.map do |a|
attachment_json(a, user)
end unless sc.attachments.blank?
if sc.grants_right?(@current_user, :read_author)
sc_hash['author'] = user_display_json(sc.author, sc.context)
else
sc_hash.merge!({
author: {},
author_id: nil,
author_name: I18n.t("Anonymous User")
})
end
sc_hash
end
hash['submission_comments'] = submission_comments_json(submission.comments_for(@current_user), user)
end
if includes.include?("rubric_assessment") && submission.rubric_assessment && submission.grants_right?(user, :read_grade)

View File

@ -0,0 +1,54 @@
#
# Copyright (C) 2011 - 2015 Instructure, Inc.
#
# This file is part of Canvas.
#
# Canvas is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, version 3 of the License.
#
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
#
module Api::V1::SubmissionComment
def submission_comment_json(submission_comment, user)
sc_hash = submission_comment.as_json(
:include_root => false,
:only => %w(id author_id author_name created_at comment)
)
if submission_comment.media_comment?
sc_hash['media_comment'] = media_comment_json(
:media_id => submission_comment.media_comment_id,
:media_type => submission_comment.media_comment_type
)
end
sc_hash['attachments'] = submission_comment.attachments.map do |a|
attachment_json(a, user)
end unless submission_comment.attachments.blank?
if submission_comment.grants_right?(@current_user, :read_author)
sc_hash['author'] = user_display_json(submission_comment.author, submission_comment.context)
else
sc_hash.merge!({
author: {},
author_id: nil,
author_name: I18n.t("Anonymous User")
})
end
sc_hash
end
def submission_comments_json(submission_comments, user)
submission_comments.map{ |submission_comment| submission_comment_json(submission_comment, user) }
end
end

View File

@ -117,7 +117,6 @@ def raw_api_call(method, path, params, body_params = {}, headers = {}, opts = {}
path = path.sub(%r{\Ahttps?://[^/]+}, '') # remove protocol+host
enable_forgery_protection do
params_from_with_nesting(method, path).each{|k, v| expect(params[k].to_s).to eq v.to_s }
if @use_basic_auth
user_session(@user)
else
@ -131,7 +130,6 @@ def raw_api_call(method, path, params, body_params = {}, headers = {}, opts = {}
end
end
LoadAccount.stubs(:default_domain_root_account).returns(opts[:domain_root_account]) if opts.has_key?(:domain_root_account)
__send__(method, path, params.reject { |k,v| %w(controller action).include?(k.to_s) }.merge(body_params), headers)
end
end

View File

@ -0,0 +1,430 @@
#
# Copyright (C) 2015 Instructure, Inc.
#
# This file is part of Canvas.
#
# Canvas is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, version 3 of the License.
#
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
#
require File.expand_path(File.dirname(__FILE__) + '/../api_spec_helper')
describe PeerReviewsApiController, type: :request do
def rubric_association_params_for_assignment(assign)
HashWithIndifferentAccess.new({
hide_score_total: "0",
purpose: "grading",
skip_updating_points_possible: false,
update_if_existing: true,
use_for_grading: "1",
association_object: assign
})
end
def assessment_request(submission, teacher, assessor)
ra_params = rubric_association_params_for_assignment(submission.assignment)
rubric_assoc = RubricAssociation.generate(teacher, @rubric, @course, ra_params)
rubric_assessment = RubricAssessment.create!({
artifact: submission,
assessment_type: 'peer_review',
assessor: assessor,
rubric: @rubric,
user: submission.user,
rubric_association: rubric_assoc
})
AssessmentRequest.create!(
rubric_assessment: rubric_assessment,
user: submission.user,
asset: submission,
assessor_asset: assessor,
assessor: assessor)
end
before :once do
course_with_teacher(active_all: true)
@cs = @course.course_sections.create!
@student1 = student_in_course(active_all: true).user
@student2 = student_in_course(active_all: true).user
@assignment1 = assignment_model(course: @course)
@submission = @assignment1.find_or_create_submission(@student1)
@rubric = @course.rubrics.create! { |r| r.user = @teacher }
@assessment_request = assessment_request(@submission, @teacher, @student2)
end
describe "Delete 'delete'" do
before :once do
@resource_path = "/api/v1/courses/#{@course.id}/assignments/#{@assignment1.id}/submissions/#{@submission.id}/peer_reviews"
@section_resource_path = "/api/v1/sections/#{@cs.id}/assignments/#{@assignment1.id}/submissions/#{@submission.id}/peer_reviews"
@resource_params = { controller: 'peer_reviews_api', action: 'destroy', format: 'json', course_id: @course.id,
assignment_id: @assignment1.id, submission_id: @submission.id, section_id: @cs.id }
end
def delete_peer_review(current_user, resource_path, resource_params)
student3 = student_in_course(active_all: true).user
assessment_request = @assignment.assign_peer_review(student3, @student1)
@user = current_user
json = api_call(:delete, resource_path, resource_params, {user_id: student3.id})
expect(AssessmentRequest.where(id: assessment_request.id).count).to eq(0)
expect(json).to eq({"assessor_id"=>assessment_request.assessor_id,
"asset_id"=>assessment_request.asset_id,
"asset_type"=>"Submission",
"id"=>assessment_request.id,
"user_id"=>assessment_request.user_id,
"workflow_state"=>"assigned"})
end
context 'with admin context' do
before :once do
account_admin_user()
end
it 'should delete peer review' do
delete_peer_review(@admin, @resource_path, @resource_params)
end
it 'should delete peer review for course section' do
delete_peer_review(@admin, @section_resource_path, @resource_params)
end
it 'should render bad request' do
student3 = student_in_course(active_all: true).user
@user = @admin
api_call(:delete, @resource_path, @resource_params, { user_id: student3.id },
{}, {:expected_status => 400})
end
end
context 'with teacher context' do
it 'should delete peer review' do
delete_peer_review(@teacher, @resource_path, @resource_params)
end
end
context 'with student context' do
it "returns 401 unauthorized access" do
student3 = student_in_course(active_all: true).user
api_call(:delete, @resource_path, @resource_params, { user_id: student3.id },
{}, {:expected_status => 401})
end
end
end
describe "Post 'create'" do
before :once do
@resource_path = "/api/v1/courses/#{@course.id}/assignments/#{@assignment1.id}/submissions/#{@submission.id}/peer_reviews"
@section_resource_path = "/api/v1/sections/#{@cs.id}/assignments/#{@assignment1.id}/submissions/#{@submission.id}/peer_reviews"
@resource_params = { controller: 'peer_reviews_api', action: 'create', format: 'json', course_id: @course.id,
assignment_id: @assignment1.id, submission_id: @submission.id, section_id: @cs.id }
end
def create_peer_review(current_user, resource_path, resource_params)
student3 = student_in_course(active_all: true).user
@user = current_user
json = api_call(:post, resource_path, resource_params, {user_id: student3.id})
requests = AssessmentRequest.for_assessor(student3.id)
expect(requests.count).to eq(1)
expect(json).to eq({"assessor_id"=>student3.id, "asset_id"=>@submission.id, "asset_type"=>"Submission", "id"=>requests.first.id, "user_id"=>@student1.id, "workflow_state"=>"assigned"})
end
context 'with admin_context' do
before :once do
account_admin_user()
end
it 'should create peer review' do
create_peer_review(@admin, @resource_path, @resource_params)
end
it 'should create peer review for course section' do
create_peer_review(@admin, @section_resource_path, @resource_params)
end
end
context 'with teacher context' do
it 'should create peer review' do
create_peer_review(@teacher, @resource_path, @resource_params)
end
end
context 'with student context' do
it "returns 401 unauthorized access" do
student3 = student_in_course(active_all: true).user
api_call(:post, @resource_path, @resource_params, { user_id: student3.id },
{}, {:expected_status => 401})
end
end
end
describe "Get 'index'" do
before :once do
@resource_path = "/api/v1/courses/#{@course.id}/assignments/#{@assignment1.id}/peer_reviews"
@section_resource_path = "/api/v1/sections/#{@cs.id}/assignments/#{@assignment1.id}/peer_reviews"
@submission_resource_path = "/api/v1/courses/#{@course.id}/assignments/#{@assignment1.id}/submissions/#{@submission.id}/peer_reviews"
@submission_section_resource_path = "/api/v1/sections/#{@cs.id}/assignments/#{@assignment1.id}/submissions/#{@submission.id}/peer_reviews"
@resource_params = { controller: 'peer_reviews_api', action: 'index', format: 'json', course_id: @course.id,
assignment_id: @assignment1.id, section_id: @cs.id }
@submission_resource_params = { controller: 'peer_reviews_api', action: 'index', format: 'json',
course_id: @course.id, assignment_id: @assignment1.id,
submission_id: @submission.id, section_id: @cs.id }
@assessment_with_user = {"assessor" => {"id"=>@student2.id,
"display_name"=>"User",
"avatar_image_url"=>"https://localhost/images/messages/avatar-50.png",
"html_url"=>"http://www.example.com/courses/#{@course.id}/users/#{@student2.id}"},
"assessor_id"=>@student2.id,
"asset_id"=>@submission.id,
"asset_type"=>"Submission",
"id"=>@assessment_request.id,
"user" => {"id"=>@student1.id,
"display_name"=>"User",
"avatar_image_url"=>"https://localhost/images/messages/avatar-50.png",
"html_url"=>"http://www.example.com/courses/#{@course.id}/users/#{@student1.id}"},
"user_id"=>@student1.id,
"workflow_state"=>@assessment_request.workflow_state}
end
def list_peer_review(current_user, resource_path, resource_params)
@user = current_user
json = api_call(:get, resource_path, resource_params)
expect(json.count).to eq(1)
expect(json[0]).to eq({"assessor_id"=>@student2.id,
"asset_id"=>@submission.id,
"asset_type"=>"Submission",
"id"=>@assessment_request.id,
"user_id"=>@student1.id,
"workflow_state"=>@assessment_request.workflow_state})
end
def assessment_with_comments(comment)
{"assessor_id"=>@student2.id,
"asset_id"=>@submission.id,
"asset_type"=>"Submission",
"id"=>@assessment_request.id,
"submission_comments" => [{"author_id"=>@student2.id,
"author_name"=>@student2.name,
"comment"=>comment.comment,
"created_at"=>comment.created_at.as_json,
"id"=>comment.id,
"author"=>{"id"=>@student2.id,
"display_name"=>@student2.name,
"avatar_image_url"=>"https://localhost/images/messages/avatar-50.png",
"html_url"=>"http://www.example.com/courses/#{@course.id}/users/#{@student2.id}"}}],
"user_id"=>@student1.id,
"workflow_state"=>@assessment_request.workflow_state}
end
context 'with admin_context' do
before :once do
account_admin_user()
end
it 'should return all peer reviews' do
list_peer_review(@admin, @resource_path, @resource_params)
end
it 'should return all peer reviews in a section' do
list_peer_review(@admin, @section_resource_path, @resource_params)
end
it 'should return all peer reviews when anonymous peer reviews enabled' do
@assignment1.update_attribute(:anonymous_peer_reviews, true)
list_peer_review(@admin, @resource_path, @resource_params)
end
it 'should include user information' do
json = api_call(:get, @resource_path, @resource_params, { :include => %w(user) })
expect(json.count).to eq(1)
expect(json[0]).to eq(@assessment_with_user)
end
it 'should include submission comments' do
@comment = @submission.add_comment(:author => @student2, :comment => "student2 comment")
json = api_call(:get, @resource_path, @resource_params, { :include => %w(submission_comments) })
expect(json.count).to eq(1)
expect(json[0]).to eq(assessment_with_comments(@comment))
end
it 'should return peer reviews for a specific submission' do
submission2 = @assignment1.find_or_create_submission(@student2)
assessment_request(submission2, @teacher, @student1)
list_peer_review(@admin, @submission_resource_path, @submission_resource_params)
end
it 'should return peer reviews for a specific submission in a section' do
submission2 = @assignment1.find_or_create_submission(@student2)
assessment_request(submission2, @teacher, @student1)
list_peer_review(@admin, @submission_section_resource_path, @submission_resource_params)
end
end
context 'with teacher_context' do
it 'should return all peer reviews' do
list_peer_review(@teacher, @resource_path, @resource_params)
end
it 'should return all peer reviews when anonymous peer reviews enabled' do
@assignment1.update_attribute(:anonymous_peer_reviews, true)
list_peer_review(@teacher, @resource_path, @resource_params)
end
it 'should include user information' do
@user = @teacher
json = api_call(:get, @resource_path, @resource_params, { :include => %w(user) })
expect(json.count).to eq(1)
expect(json[0]).to eq(@assessment_with_user)
end
it 'should include submission comments' do
@user = @teacher
@comment = @submission.add_comment(:author => @student2, :comment => "student2 comment")
json = api_call(:get, @resource_path, @resource_params, { :include => %w(submission_comments) })
expect(json.count).to eq(1)
expect(json[0]).to eq(assessment_with_comments(@comment))
end
it 'should return peer reviews for a specific submission' do
submission2 = @assignment1.find_or_create_submission(@student2)
assessment_request(submission2, @teacher, @student1)
list_peer_review(@teacher, @submission_resource_path, @submission_resource_params)
end
end
context 'with student_context' do
it 'should return peer reviews for user' do
list_peer_review(@student1, @resource_path, @resource_params)
end
it 'should not return assessor if anonymous peer reviews enabled' do
@user = @student1
@assignment1.update_attribute(:anonymous_peer_reviews, true)
json = api_call(:get, @resource_path, @resource_params)
expect(json.count).to eq(1)
expect(json[0]).to eq({"asset_id"=>@submission.id,
"asset_type"=>"Submission",
"id"=>@assessment_request.id,
"user_id"=>@student1.id,
"workflow_state"=>@assessment_request.workflow_state})
end
it 'should not return peer reviews for assessor' do
@user = @student2
json = api_call(:get, @resource_path, @resource_params)
expect(json.count).to eq(0)
end
it 'should include user information' do
@assignment1.update_attribute(:anonymous_peer_reviews, false)
@user = @student1
json = api_call(:get, @resource_path, @resource_params, { :include => %w(user) })
expect(json.count).to eq(1)
expect(json[0]).to eq(@assessment_with_user)
end
it 'should not include assessor information when peer reviews are enabled' do
@assignment1.update_attribute(:anonymous_peer_reviews, true)
@user = @student1
json = api_call(:get, @resource_path, @resource_params, { :include => %w(user) })
expect(json.count).to eq(1)
expect(json[0]).to eq({"asset_id"=>@submission.id,
"asset_type"=>"Submission",
"id"=>@assessment_request.id,
"user" => {"id"=>@student1.id,
"display_name"=>"User",
"avatar_image_url"=>"https://localhost/images/messages/avatar-50.png",
"html_url"=>"http://www.example.com/courses/#{@course.id}/users/#{@student1.id}"},
"user_id"=>@student1.id,
"workflow_state"=>@assessment_request.workflow_state})
end
it 'should include submission comments' do
@assignment1.update_attribute(:anonymous_peer_reviews, false)
@comment = @submission.add_comment(:author => @student2, :comment => "student2 comment")
@user = @student1
json = api_call(:get, @resource_path, @resource_params, { :include => %w(submission_comments) })
expect(json.count).to eq(1)
expect(json[0]).to eq(assessment_with_comments(@comment))
end
it 'should not include submission comments user information when anonymous peer reviews' do
@assignment1.update_attribute(:anonymous_peer_reviews, true)
@comment = @submission.add_comment(:author => @student2, :comment => "review comment")
@user = @student1
json = api_call(:get, @resource_path, @resource_params, { :include => %w(submission_comments) })
expect(json.count).to eq(1)
expect(json[0]).to eq({"asset_id"=>@submission.id,
"asset_type"=>"Submission",
"id"=>@assessment_request.id,
"submission_comments" => [{"author_id"=>nil,
"author_name"=>"Anonymous User",
"comment"=>"review comment",
"created_at"=>@comment.created_at.as_json,
"id"=>@comment.id,
"author"=>{}}],
"user_id"=>@student1.id,
"workflow_state"=>@assessment_request.workflow_state})
end
it 'should return peer reviews for a specific submission' do
@user = @student1
submission2 = @assignment1.find_or_create_submission(@student2)
assessment_request(submission2, @teacher, @student1)
json = api_call(:get, @submission_resource_path, @submission_resource_params)
expect(json.count).to eq(1)
expect(json[0]).to eq({"assessor_id"=>@student2.id,
"asset_id"=>@submission.id,
"asset_type"=>"Submission",
"id"=>@assessment_request.id,
"user_id"=>@student1.id,
"workflow_state"=>@assessment_request.workflow_state})
end
it 'should return no peer reviews for invalid submission' do
@assignment2 = assignment_model(course: @course)
@submission_resource_path = "/api/v1/courses/#{@course.id}/assignments/#{@assignment2.id}/submissions/#{@submission.id}/peer_reviews"
@submission_resource_params = { controller: 'peer_reviews_api', action: 'index', format: 'json',
course_id: @course.id, assignment_id: @assignment2.id,
submission_id: @submission.id, section_id: @cs.id }
json = api_call(:get, @submission_resource_path, @submission_resource_params)
expect(json.count).to eq(0)
end
end
end
end