import ActiveModel::Serializers port and convert quizzes api to it
test plan:
- The quiz api should work like it normally does when you don't pass
an 'Accept: application/vnd.api+json' header.
- The quizzes index page and quiz edit page should work like they
always do.
- Testing the Quizzes API for "jsonapi" style:
- For all requests, you MUST have the "Accept" header set to
"application/vnd.api+json"
- Test all the endpoints (PUT, POST, GET, INDEX, DELETE) like you
normally would, except you'll need to format the data according to
the next few steps:
- For "POST" and "PUT" (create and update) requests, you should send
the data like: { "quizzes": [ { id: 1, title: "blah" } ]
- For all requests (except DELETE), you should get back a response
that looks like: { "quizzes": [ { quiz you requested } ]
- For the "delete" action, you should get a "no content" response
and the request should be successful
Change-Id: Ie91deaeb6772cbe52a0fc46a28ab93a4e3036061
Reviewed-on: https://gerrit.instructure.com/25997
Reviewed-by: Jacob Fugal <jacob@instructure.com>
Tested-by: Jenkins <jenkins@instructure.com>
QA-Review: Caleb Guanzon <cguanzon@instructure.com>
Product-Review: Stanley Stuart <stanley@instructure.com>
2013-12-05 03:06:32 +08:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2014-03-05 00:38:40 +08:00
|
|
|
describe Quizzes::QuizSerializer do
|
2014-03-05 00:33:05 +08:00
|
|
|
|
|
|
|
def quiz_serializer(options={})
|
|
|
|
options.reverse_merge!({
|
|
|
|
controller: controller,
|
|
|
|
scope: @user,
|
|
|
|
session: @session
|
|
|
|
})
|
|
|
|
Quizzes::QuizSerializer.new(@quiz, options)
|
|
|
|
end
|
import ActiveModel::Serializers port and convert quizzes api to it
test plan:
- The quiz api should work like it normally does when you don't pass
an 'Accept: application/vnd.api+json' header.
- The quizzes index page and quiz edit page should work like they
always do.
- Testing the Quizzes API for "jsonapi" style:
- For all requests, you MUST have the "Accept" header set to
"application/vnd.api+json"
- Test all the endpoints (PUT, POST, GET, INDEX, DELETE) like you
normally would, except you'll need to format the data according to
the next few steps:
- For "POST" and "PUT" (create and update) requests, you should send
the data like: { "quizzes": [ { id: 1, title: "blah" } ]
- For all requests (except DELETE), you should get back a response
that looks like: { "quizzes": [ { quiz you requested } ]
- For the "delete" action, you should get a "no content" response
and the request should be successful
Change-Id: Ie91deaeb6772cbe52a0fc46a28ab93a4e3036061
Reviewed-on: https://gerrit.instructure.com/25997
Reviewed-by: Jacob Fugal <jacob@instructure.com>
Tested-by: Jenkins <jenkins@instructure.com>
QA-Review: Caleb Guanzon <cguanzon@instructure.com>
Product-Review: Stanley Stuart <stanley@instructure.com>
2013-12-05 03:06:32 +08:00
|
|
|
let(:quiz) { @quiz }
|
|
|
|
let(:context ) { @context }
|
|
|
|
let(:serializer) { @serializer }
|
|
|
|
let(:host_name) { 'example.com' }
|
|
|
|
let(:json) { @json }
|
|
|
|
let(:session) { @session }
|
|
|
|
let(:controller) do
|
|
|
|
ActiveModel::FakeController.new(accepts_jsonapi: true, stringify_json_ids: false)
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
2016-01-07 13:00:57 +08:00
|
|
|
@context = Account.default.courses.new
|
import ActiveModel::Serializers port and convert quizzes api to it
test plan:
- The quiz api should work like it normally does when you don't pass
an 'Accept: application/vnd.api+json' header.
- The quizzes index page and quiz edit page should work like they
always do.
- Testing the Quizzes API for "jsonapi" style:
- For all requests, you MUST have the "Accept" header set to
"application/vnd.api+json"
- Test all the endpoints (PUT, POST, GET, INDEX, DELETE) like you
normally would, except you'll need to format the data according to
the next few steps:
- For "POST" and "PUT" (create and update) requests, you should send
the data like: { "quizzes": [ { id: 1, title: "blah" } ]
- For all requests (except DELETE), you should get back a response
that looks like: { "quizzes": [ { quiz you requested } ]
- For the "delete" action, you should get a "no content" response
and the request should be successful
Change-Id: Ie91deaeb6772cbe52a0fc46a28ab93a4e3036061
Reviewed-on: https://gerrit.instructure.com/25997
Reviewed-by: Jacob Fugal <jacob@instructure.com>
Tested-by: Jenkins <jenkins@instructure.com>
QA-Review: Caleb Guanzon <cguanzon@instructure.com>
Product-Review: Stanley Stuart <stanley@instructure.com>
2013-12-05 03:06:32 +08:00
|
|
|
@context.id = 1
|
2015-05-20 04:43:57 +08:00
|
|
|
@quiz = Quizzes::Quiz.new title: 'test quiz', description: 'default quiz description'
|
import ActiveModel::Serializers port and convert quizzes api to it
test plan:
- The quiz api should work like it normally does when you don't pass
an 'Accept: application/vnd.api+json' header.
- The quizzes index page and quiz edit page should work like they
always do.
- Testing the Quizzes API for "jsonapi" style:
- For all requests, you MUST have the "Accept" header set to
"application/vnd.api+json"
- Test all the endpoints (PUT, POST, GET, INDEX, DELETE) like you
normally would, except you'll need to format the data according to
the next few steps:
- For "POST" and "PUT" (create and update) requests, you should send
the data like: { "quizzes": [ { id: 1, title: "blah" } ]
- For all requests (except DELETE), you should get back a response
that looks like: { "quizzes": [ { quiz you requested } ]
- For the "delete" action, you should get a "no content" response
and the request should be successful
Change-Id: Ie91deaeb6772cbe52a0fc46a28ab93a4e3036061
Reviewed-on: https://gerrit.instructure.com/25997
Reviewed-by: Jacob Fugal <jacob@instructure.com>
Tested-by: Jenkins <jenkins@instructure.com>
QA-Review: Caleb Guanzon <cguanzon@instructure.com>
Product-Review: Stanley Stuart <stanley@instructure.com>
2013-12-05 03:06:32 +08:00
|
|
|
@quiz.id = 1
|
|
|
|
@quiz.context = @context
|
|
|
|
@user = User.new
|
|
|
|
@quiz.stubs(:locked_for?).returns false
|
2014-06-11 07:05:13 +08:00
|
|
|
@quiz.stubs(:check_right?).returns true
|
2014-02-25 04:42:19 +08:00
|
|
|
@session = stub(:[] => nil)
|
import ActiveModel::Serializers port and convert quizzes api to it
test plan:
- The quiz api should work like it normally does when you don't pass
an 'Accept: application/vnd.api+json' header.
- The quizzes index page and quiz edit page should work like they
always do.
- Testing the Quizzes API for "jsonapi" style:
- For all requests, you MUST have the "Accept" header set to
"application/vnd.api+json"
- Test all the endpoints (PUT, POST, GET, INDEX, DELETE) like you
normally would, except you'll need to format the data according to
the next few steps:
- For "POST" and "PUT" (create and update) requests, you should send
the data like: { "quizzes": [ { id: 1, title: "blah" } ]
- For all requests (except DELETE), you should get back a response
that looks like: { "quizzes": [ { quiz you requested } ]
- For the "delete" action, you should get a "no content" response
and the request should be successful
Change-Id: Ie91deaeb6772cbe52a0fc46a28ab93a4e3036061
Reviewed-on: https://gerrit.instructure.com/25997
Reviewed-by: Jacob Fugal <jacob@instructure.com>
Tested-by: Jenkins <jenkins@instructure.com>
QA-Review: Caleb Guanzon <cguanzon@instructure.com>
Product-Review: Stanley Stuart <stanley@instructure.com>
2013-12-05 03:06:32 +08:00
|
|
|
controller.stubs(:session).returns session
|
|
|
|
controller.stubs(:context).returns context
|
2014-01-24 00:23:26 +08:00
|
|
|
@quiz.stubs(:grants_right?).at_least_once.returns true
|
2014-03-05 00:33:05 +08:00
|
|
|
@serializer = quiz_serializer
|
import ActiveModel::Serializers port and convert quizzes api to it
test plan:
- The quiz api should work like it normally does when you don't pass
an 'Accept: application/vnd.api+json' header.
- The quizzes index page and quiz edit page should work like they
always do.
- Testing the Quizzes API for "jsonapi" style:
- For all requests, you MUST have the "Accept" header set to
"application/vnd.api+json"
- Test all the endpoints (PUT, POST, GET, INDEX, DELETE) like you
normally would, except you'll need to format the data according to
the next few steps:
- For "POST" and "PUT" (create and update) requests, you should send
the data like: { "quizzes": [ { id: 1, title: "blah" } ]
- For all requests (except DELETE), you should get back a response
that looks like: { "quizzes": [ { quiz you requested } ]
- For the "delete" action, you should get a "no content" response
and the request should be successful
Change-Id: Ie91deaeb6772cbe52a0fc46a28ab93a4e3036061
Reviewed-on: https://gerrit.instructure.com/25997
Reviewed-by: Jacob Fugal <jacob@instructure.com>
Tested-by: Jenkins <jenkins@instructure.com>
QA-Review: Caleb Guanzon <cguanzon@instructure.com>
Product-Review: Stanley Stuart <stanley@instructure.com>
2013-12-05 03:06:32 +08:00
|
|
|
@json = @serializer.as_json[:quiz]
|
|
|
|
end
|
|
|
|
|
|
|
|
[
|
2015-05-20 04:43:57 +08:00
|
|
|
:title, :quiz_type, :hide_results, :time_limit,
|
|
|
|
:shuffle_answers, :show_correct_answers, :scoring_policy,
|
import ActiveModel::Serializers port and convert quizzes api to it
test plan:
- The quiz api should work like it normally does when you don't pass
an 'Accept: application/vnd.api+json' header.
- The quizzes index page and quiz edit page should work like they
always do.
- Testing the Quizzes API for "jsonapi" style:
- For all requests, you MUST have the "Accept" header set to
"application/vnd.api+json"
- Test all the endpoints (PUT, POST, GET, INDEX, DELETE) like you
normally would, except you'll need to format the data according to
the next few steps:
- For "POST" and "PUT" (create and update) requests, you should send
the data like: { "quizzes": [ { id: 1, title: "blah" } ]
- For all requests (except DELETE), you should get back a response
that looks like: { "quizzes": [ { quiz you requested } ]
- For the "delete" action, you should get a "no content" response
and the request should be successful
Change-Id: Ie91deaeb6772cbe52a0fc46a28ab93a4e3036061
Reviewed-on: https://gerrit.instructure.com/25997
Reviewed-by: Jacob Fugal <jacob@instructure.com>
Tested-by: Jenkins <jenkins@instructure.com>
QA-Review: Caleb Guanzon <cguanzon@instructure.com>
Product-Review: Stanley Stuart <stanley@instructure.com>
2013-12-05 03:06:32 +08:00
|
|
|
:allowed_attempts, :one_question_at_a_time, :question_count,
|
|
|
|
:points_possible, :cant_go_back, :access_code, :ip_filter, :due_at,
|
|
|
|
:lock_at, :unlock_at, :published, :show_correct_answers_at,
|
2015-05-15 06:47:02 +08:00
|
|
|
:hide_correct_answers_at, :show_correct_answers_last_attempt, :question_types,
|
|
|
|
:has_access_code
|
import ActiveModel::Serializers port and convert quizzes api to it
test plan:
- The quiz api should work like it normally does when you don't pass
an 'Accept: application/vnd.api+json' header.
- The quizzes index page and quiz edit page should work like they
always do.
- Testing the Quizzes API for "jsonapi" style:
- For all requests, you MUST have the "Accept" header set to
"application/vnd.api+json"
- Test all the endpoints (PUT, POST, GET, INDEX, DELETE) like you
normally would, except you'll need to format the data according to
the next few steps:
- For "POST" and "PUT" (create and update) requests, you should send
the data like: { "quizzes": [ { id: 1, title: "blah" } ]
- For all requests (except DELETE), you should get back a response
that looks like: { "quizzes": [ { quiz you requested } ]
- For the "delete" action, you should get a "no content" response
and the request should be successful
Change-Id: Ie91deaeb6772cbe52a0fc46a28ab93a4e3036061
Reviewed-on: https://gerrit.instructure.com/25997
Reviewed-by: Jacob Fugal <jacob@instructure.com>
Tested-by: Jenkins <jenkins@instructure.com>
QA-Review: Caleb Guanzon <cguanzon@instructure.com>
Product-Review: Stanley Stuart <stanley@instructure.com>
2013-12-05 03:06:32 +08:00
|
|
|
].each do |attribute|
|
|
|
|
|
|
|
|
it "serializes #{attribute}" do
|
2014-10-14 02:04:33 +08:00
|
|
|
expect(json[attribute]).to eq quiz.send(attribute)
|
import ActiveModel::Serializers port and convert quizzes api to it
test plan:
- The quiz api should work like it normally does when you don't pass
an 'Accept: application/vnd.api+json' header.
- The quizzes index page and quiz edit page should work like they
always do.
- Testing the Quizzes API for "jsonapi" style:
- For all requests, you MUST have the "Accept" header set to
"application/vnd.api+json"
- Test all the endpoints (PUT, POST, GET, INDEX, DELETE) like you
normally would, except you'll need to format the data according to
the next few steps:
- For "POST" and "PUT" (create and update) requests, you should send
the data like: { "quizzes": [ { id: 1, title: "blah" } ]
- For all requests (except DELETE), you should get back a response
that looks like: { "quizzes": [ { quiz you requested } ]
- For the "delete" action, you should get a "no content" response
and the request should be successful
Change-Id: Ie91deaeb6772cbe52a0fc46a28ab93a4e3036061
Reviewed-on: https://gerrit.instructure.com/25997
Reviewed-by: Jacob Fugal <jacob@instructure.com>
Tested-by: Jenkins <jenkins@instructure.com>
QA-Review: Caleb Guanzon <cguanzon@instructure.com>
Product-Review: Stanley Stuart <stanley@instructure.com>
2013-12-05 03:06:32 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "serializes mobile_url" do
|
2014-10-14 02:04:33 +08:00
|
|
|
expect(json[:mobile_url]).to eq 'http://example.com/courses/1/quizzes/1?force_user=1&persist_headless=1'
|
import ActiveModel::Serializers port and convert quizzes api to it
test plan:
- The quiz api should work like it normally does when you don't pass
an 'Accept: application/vnd.api+json' header.
- The quizzes index page and quiz edit page should work like they
always do.
- Testing the Quizzes API for "jsonapi" style:
- For all requests, you MUST have the "Accept" header set to
"application/vnd.api+json"
- Test all the endpoints (PUT, POST, GET, INDEX, DELETE) like you
normally would, except you'll need to format the data according to
the next few steps:
- For "POST" and "PUT" (create and update) requests, you should send
the data like: { "quizzes": [ { id: 1, title: "blah" } ]
- For all requests (except DELETE), you should get back a response
that looks like: { "quizzes": [ { quiz you requested } ]
- For the "delete" action, you should get a "no content" response
and the request should be successful
Change-Id: Ie91deaeb6772cbe52a0fc46a28ab93a4e3036061
Reviewed-on: https://gerrit.instructure.com/25997
Reviewed-by: Jacob Fugal <jacob@instructure.com>
Tested-by: Jenkins <jenkins@instructure.com>
QA-Review: Caleb Guanzon <cguanzon@instructure.com>
Product-Review: Stanley Stuart <stanley@instructure.com>
2013-12-05 03:06:32 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "serializes html_url" do
|
2014-10-14 02:04:33 +08:00
|
|
|
expect(json[:html_url]).to eq 'http://example.com/courses/1/quizzes/1'
|
import ActiveModel::Serializers port and convert quizzes api to it
test plan:
- The quiz api should work like it normally does when you don't pass
an 'Accept: application/vnd.api+json' header.
- The quizzes index page and quiz edit page should work like they
always do.
- Testing the Quizzes API for "jsonapi" style:
- For all requests, you MUST have the "Accept" header set to
"application/vnd.api+json"
- Test all the endpoints (PUT, POST, GET, INDEX, DELETE) like you
normally would, except you'll need to format the data according to
the next few steps:
- For "POST" and "PUT" (create and update) requests, you should send
the data like: { "quizzes": [ { id: 1, title: "blah" } ]
- For all requests (except DELETE), you should get back a response
that looks like: { "quizzes": [ { quiz you requested } ]
- For the "delete" action, you should get a "no content" response
and the request should be successful
Change-Id: Ie91deaeb6772cbe52a0fc46a28ab93a4e3036061
Reviewed-on: https://gerrit.instructure.com/25997
Reviewed-by: Jacob Fugal <jacob@instructure.com>
Tested-by: Jenkins <jenkins@instructure.com>
QA-Review: Caleb Guanzon <cguanzon@instructure.com>
Product-Review: Stanley Stuart <stanley@instructure.com>
2013-12-05 03:06:32 +08:00
|
|
|
end
|
|
|
|
|
2015-05-20 04:43:57 +08:00
|
|
|
describe "description" do
|
|
|
|
it "serializes description with a formatter if given" do
|
|
|
|
@serializer = quiz_serializer(
|
|
|
|
serializer_options: {
|
|
|
|
description_formatter: -> (_) {return "description from formatter"}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
@json = @serializer.as_json[:quiz]
|
|
|
|
|
|
|
|
expect(json[:description]).to eq "description from formatter"
|
|
|
|
end
|
|
|
|
it "returns desctiption otherwise" do
|
|
|
|
expect(json[:description]).to eq quiz.description
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-02-14 05:27:11 +08:00
|
|
|
it "serializes speed_grader_url" do
|
|
|
|
# No assignment, so it should be nil
|
2014-10-14 02:04:33 +08:00
|
|
|
expect(json[:speed_grader_url]).to be_nil
|
2014-02-14 05:27:11 +08:00
|
|
|
assignment = Assignment.new
|
|
|
|
assignment.id = 1
|
|
|
|
assignment.context_id = @context.id
|
|
|
|
@quiz.stubs(:assignment).returns assignment
|
|
|
|
|
|
|
|
# nil when quiz is unpublished
|
|
|
|
@quiz.stubs(:published?).returns false
|
2014-10-14 02:04:33 +08:00
|
|
|
expect(@serializer.as_json[:quiz][:speed_grader_url]).to be_nil
|
2014-02-14 05:27:11 +08:00
|
|
|
|
|
|
|
# nil when context doesn't allow speedgrader
|
|
|
|
@quiz.stubs(:published?).returns true
|
|
|
|
@context.expects(:allows_speed_grader?).returns false
|
2014-10-14 02:04:33 +08:00
|
|
|
expect(@serializer.as_json[:quiz][:speed_grader_url]).to be_nil
|
2014-02-14 05:27:11 +08:00
|
|
|
|
|
|
|
@context.expects(:allows_speed_grader?).returns true
|
|
|
|
json = @serializer.as_json[:quiz]
|
2014-10-14 02:04:33 +08:00
|
|
|
expect(json[:speed_grader_url]).to eq(
|
2014-02-14 05:27:11 +08:00
|
|
|
controller.send(:speed_grader_course_gradebook_url, @quiz.context, assignment_id: @quiz.assignment.id)
|
2014-10-14 02:04:33 +08:00
|
|
|
)
|
2014-02-14 05:27:11 +08:00
|
|
|
|
|
|
|
# Students shouldn't be able to see speed_grader_url
|
|
|
|
@quiz.stubs(:grants_right?).returns false
|
2014-10-14 02:04:33 +08:00
|
|
|
expect(@serializer.as_json[:quiz]).not_to have_key :speed_grader_url
|
2014-02-14 05:27:11 +08:00
|
|
|
end
|
|
|
|
|
2014-05-13 13:34:48 +08:00
|
|
|
it "doesn't include the section count unless the user can grade" do
|
|
|
|
quiz.expects(:grants_right?).with(@user, @session, :grade).
|
|
|
|
at_least_once.returns true
|
2014-10-14 02:04:33 +08:00
|
|
|
expect(serializer.as_json[:quiz]).to have_key :section_count
|
2014-05-13 13:34:48 +08:00
|
|
|
|
|
|
|
quiz.expects(:grants_right?).with(@user, @session, :grade).
|
|
|
|
at_least_once.returns false
|
2014-10-14 02:04:33 +08:00
|
|
|
expect(serializer.as_json[:quiz]).not_to have_key :section_count
|
2014-05-13 13:34:48 +08:00
|
|
|
end
|
|
|
|
|
import ActiveModel::Serializers port and convert quizzes api to it
test plan:
- The quiz api should work like it normally does when you don't pass
an 'Accept: application/vnd.api+json' header.
- The quizzes index page and quiz edit page should work like they
always do.
- Testing the Quizzes API for "jsonapi" style:
- For all requests, you MUST have the "Accept" header set to
"application/vnd.api+json"
- Test all the endpoints (PUT, POST, GET, INDEX, DELETE) like you
normally would, except you'll need to format the data according to
the next few steps:
- For "POST" and "PUT" (create and update) requests, you should send
the data like: { "quizzes": [ { id: 1, title: "blah" } ]
- For all requests (except DELETE), you should get back a response
that looks like: { "quizzes": [ { quiz you requested } ]
- For the "delete" action, you should get a "no content" response
and the request should be successful
Change-Id: Ie91deaeb6772cbe52a0fc46a28ab93a4e3036061
Reviewed-on: https://gerrit.instructure.com/25997
Reviewed-by: Jacob Fugal <jacob@instructure.com>
Tested-by: Jenkins <jenkins@instructure.com>
QA-Review: Caleb Guanzon <cguanzon@instructure.com>
Product-Review: Stanley Stuart <stanley@instructure.com>
2013-12-05 03:06:32 +08:00
|
|
|
it "uses available_question_count for question_count" do
|
|
|
|
quiz.stubs(:available_question_count).returns 5
|
2014-10-14 02:04:33 +08:00
|
|
|
expect(serializer.as_json[:quiz][:question_count]).to eq 5
|
import ActiveModel::Serializers port and convert quizzes api to it
test plan:
- The quiz api should work like it normally does when you don't pass
an 'Accept: application/vnd.api+json' header.
- The quizzes index page and quiz edit page should work like they
always do.
- Testing the Quizzes API for "jsonapi" style:
- For all requests, you MUST have the "Accept" header set to
"application/vnd.api+json"
- Test all the endpoints (PUT, POST, GET, INDEX, DELETE) like you
normally would, except you'll need to format the data according to
the next few steps:
- For "POST" and "PUT" (create and update) requests, you should send
the data like: { "quizzes": [ { id: 1, title: "blah" } ]
- For all requests (except DELETE), you should get back a response
that looks like: { "quizzes": [ { quiz you requested } ]
- For the "delete" action, you should get a "no content" response
and the request should be successful
Change-Id: Ie91deaeb6772cbe52a0fc46a28ab93a4e3036061
Reviewed-on: https://gerrit.instructure.com/25997
Reviewed-by: Jacob Fugal <jacob@instructure.com>
Tested-by: Jenkins <jenkins@instructure.com>
QA-Review: Caleb Guanzon <cguanzon@instructure.com>
Product-Review: Stanley Stuart <stanley@instructure.com>
2013-12-05 03:06:32 +08:00
|
|
|
end
|
|
|
|
|
2014-03-05 00:33:05 +08:00
|
|
|
it "sends the message_students_url when user can grade" do
|
|
|
|
quiz.expects(:grants_right?).at_least_once.returns true
|
2014-10-14 02:04:33 +08:00
|
|
|
expect(serializer.as_json[:quiz][:message_students_url]).to eq(
|
2014-03-05 00:33:05 +08:00
|
|
|
controller.send(:api_v1_course_quiz_submission_users_message_url, quiz, quiz.context)
|
2014-10-14 02:04:33 +08:00
|
|
|
)
|
2014-03-05 00:33:05 +08:00
|
|
|
|
|
|
|
quiz.expects(:grants_right?).at_least_once.returns false
|
2014-10-14 02:04:33 +08:00
|
|
|
expect(serializer.as_json[:quiz]).not_to have_key :message_students_url
|
2014-03-05 00:33:05 +08:00
|
|
|
end
|
|
|
|
|
2016-06-18 03:58:02 +08:00
|
|
|
describe "access code" do
|
|
|
|
it "is included if the user can grade" do
|
|
|
|
quiz.expects(:grants_right?).with(@user, @session, :grade).
|
|
|
|
at_least_once.returns true
|
|
|
|
expect(serializer.as_json[:quiz]).to have_key :access_code
|
|
|
|
end
|
|
|
|
|
|
|
|
it "is included if the user can manage" do
|
|
|
|
quiz.expects(:grants_right?).with(@user, @session, :manage).
|
|
|
|
at_least_once.returns true
|
|
|
|
expect(serializer.as_json[:quiz]).to have_key :access_code
|
|
|
|
end
|
|
|
|
|
|
|
|
it "is not included if the user can't grade or manage" do
|
|
|
|
quiz.expects(:grants_right?).with(@user, @session, :grade).
|
|
|
|
at_least_once.returns false
|
|
|
|
quiz.expects(:grants_right?).with(@user, @session, :manage).
|
|
|
|
at_least_once.returns false
|
|
|
|
expect(serializer.as_json[:quiz]).not_to have_key :access_code
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
import ActiveModel::Serializers port and convert quizzes api to it
test plan:
- The quiz api should work like it normally does when you don't pass
an 'Accept: application/vnd.api+json' header.
- The quizzes index page and quiz edit page should work like they
always do.
- Testing the Quizzes API for "jsonapi" style:
- For all requests, you MUST have the "Accept" header set to
"application/vnd.api+json"
- Test all the endpoints (PUT, POST, GET, INDEX, DELETE) like you
normally would, except you'll need to format the data according to
the next few steps:
- For "POST" and "PUT" (create and update) requests, you should send
the data like: { "quizzes": [ { id: 1, title: "blah" } ]
- For all requests (except DELETE), you should get back a response
that looks like: { "quizzes": [ { quiz you requested } ]
- For the "delete" action, you should get a "no content" response
and the request should be successful
Change-Id: Ie91deaeb6772cbe52a0fc46a28ab93a4e3036061
Reviewed-on: https://gerrit.instructure.com/25997
Reviewed-by: Jacob Fugal <jacob@instructure.com>
Tested-by: Jenkins <jenkins@instructure.com>
QA-Review: Caleb Guanzon <cguanzon@instructure.com>
Product-Review: Stanley Stuart <stanley@instructure.com>
2013-12-05 03:06:32 +08:00
|
|
|
describe "id" do
|
|
|
|
|
|
|
|
it "stringifys when stringify_json_ids? is true" do
|
|
|
|
controller.expects(:accepts_jsonapi?).at_least_once.returns false
|
|
|
|
controller.expects(:stringify_json_ids?).at_least_once.returns true
|
2014-10-14 02:04:33 +08:00
|
|
|
expect(serializer.as_json[:quiz][:id]).to eq quiz.id.to_s
|
import ActiveModel::Serializers port and convert quizzes api to it
test plan:
- The quiz api should work like it normally does when you don't pass
an 'Accept: application/vnd.api+json' header.
- The quizzes index page and quiz edit page should work like they
always do.
- Testing the Quizzes API for "jsonapi" style:
- For all requests, you MUST have the "Accept" header set to
"application/vnd.api+json"
- Test all the endpoints (PUT, POST, GET, INDEX, DELETE) like you
normally would, except you'll need to format the data according to
the next few steps:
- For "POST" and "PUT" (create and update) requests, you should send
the data like: { "quizzes": [ { id: 1, title: "blah" } ]
- For all requests (except DELETE), you should get back a response
that looks like: { "quizzes": [ { quiz you requested } ]
- For the "delete" action, you should get a "no content" response
and the request should be successful
Change-Id: Ie91deaeb6772cbe52a0fc46a28ab93a4e3036061
Reviewed-on: https://gerrit.instructure.com/25997
Reviewed-by: Jacob Fugal <jacob@instructure.com>
Tested-by: Jenkins <jenkins@instructure.com>
QA-Review: Caleb Guanzon <cguanzon@instructure.com>
Product-Review: Stanley Stuart <stanley@instructure.com>
2013-12-05 03:06:32 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "when stringify_json_ids? is false" do
|
|
|
|
controller.expects(:accepts_jsonapi?).at_least_once.returns false
|
2014-10-14 02:04:33 +08:00
|
|
|
expect(serializer.as_json[:quiz][:id]).to eq quiz.id
|
|
|
|
expect(serializer.as_json[:quiz][:id].is_a?(Fixnum)).to be_truthy
|
import ActiveModel::Serializers port and convert quizzes api to it
test plan:
- The quiz api should work like it normally does when you don't pass
an 'Accept: application/vnd.api+json' header.
- The quizzes index page and quiz edit page should work like they
always do.
- Testing the Quizzes API for "jsonapi" style:
- For all requests, you MUST have the "Accept" header set to
"application/vnd.api+json"
- Test all the endpoints (PUT, POST, GET, INDEX, DELETE) like you
normally would, except you'll need to format the data according to
the next few steps:
- For "POST" and "PUT" (create and update) requests, you should send
the data like: { "quizzes": [ { id: 1, title: "blah" } ]
- For all requests (except DELETE), you should get back a response
that looks like: { "quizzes": [ { quiz you requested } ]
- For the "delete" action, you should get a "no content" response
and the request should be successful
Change-Id: Ie91deaeb6772cbe52a0fc46a28ab93a4e3036061
Reviewed-on: https://gerrit.instructure.com/25997
Reviewed-by: Jacob Fugal <jacob@instructure.com>
Tested-by: Jenkins <jenkins@instructure.com>
QA-Review: Caleb Guanzon <cguanzon@instructure.com>
Product-Review: Stanley Stuart <stanley@instructure.com>
2013-12-05 03:06:32 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "lock_info" do
|
|
|
|
it "includes lock_info when appropriate" do
|
|
|
|
quiz.expects(:locked_for?).
|
|
|
|
with(@user, check_policies: true, context: @context).
|
|
|
|
returns({due_at: true})
|
2014-03-05 00:33:05 +08:00
|
|
|
json = quiz_serializer.as_json[:quiz]
|
2014-10-14 02:04:33 +08:00
|
|
|
expect(json).to have_key :lock_info
|
|
|
|
expect(json).to have_key :lock_explanation
|
|
|
|
expect(json[:locked_for_user]).to eq true
|
import ActiveModel::Serializers port and convert quizzes api to it
test plan:
- The quiz api should work like it normally does when you don't pass
an 'Accept: application/vnd.api+json' header.
- The quizzes index page and quiz edit page should work like they
always do.
- Testing the Quizzes API for "jsonapi" style:
- For all requests, you MUST have the "Accept" header set to
"application/vnd.api+json"
- Test all the endpoints (PUT, POST, GET, INDEX, DELETE) like you
normally would, except you'll need to format the data according to
the next few steps:
- For "POST" and "PUT" (create and update) requests, you should send
the data like: { "quizzes": [ { id: 1, title: "blah" } ]
- For all requests (except DELETE), you should get back a response
that looks like: { "quizzes": [ { quiz you requested } ]
- For the "delete" action, you should get a "no content" response
and the request should be successful
Change-Id: Ie91deaeb6772cbe52a0fc46a28ab93a4e3036061
Reviewed-on: https://gerrit.instructure.com/25997
Reviewed-by: Jacob Fugal <jacob@instructure.com>
Tested-by: Jenkins <jenkins@instructure.com>
QA-Review: Caleb Guanzon <cguanzon@instructure.com>
Product-Review: Stanley Stuart <stanley@instructure.com>
2013-12-05 03:06:32 +08:00
|
|
|
|
|
|
|
quiz.expects(:locked_for?).
|
|
|
|
with(@user, check_policies: true, context: @context).
|
|
|
|
returns false
|
2014-03-05 00:33:05 +08:00
|
|
|
json = quiz_serializer.as_json[:quiz]
|
2014-10-14 02:04:33 +08:00
|
|
|
expect(json).not_to have_key :lock_info
|
|
|
|
expect(json).not_to have_key :lock_explanation
|
|
|
|
expect(json[:locked_for_user]).to eq false
|
import ActiveModel::Serializers port and convert quizzes api to it
test plan:
- The quiz api should work like it normally does when you don't pass
an 'Accept: application/vnd.api+json' header.
- The quizzes index page and quiz edit page should work like they
always do.
- Testing the Quizzes API for "jsonapi" style:
- For all requests, you MUST have the "Accept" header set to
"application/vnd.api+json"
- Test all the endpoints (PUT, POST, GET, INDEX, DELETE) like you
normally would, except you'll need to format the data according to
the next few steps:
- For "POST" and "PUT" (create and update) requests, you should send
the data like: { "quizzes": [ { id: 1, title: "blah" } ]
- For all requests (except DELETE), you should get back a response
that looks like: { "quizzes": [ { quiz you requested } ]
- For the "delete" action, you should get a "no content" response
and the request should be successful
Change-Id: Ie91deaeb6772cbe52a0fc46a28ab93a4e3036061
Reviewed-on: https://gerrit.instructure.com/25997
Reviewed-by: Jacob Fugal <jacob@instructure.com>
Tested-by: Jenkins <jenkins@instructure.com>
QA-Review: Caleb Guanzon <cguanzon@instructure.com>
Product-Review: Stanley Stuart <stanley@instructure.com>
2013-12-05 03:06:32 +08:00
|
|
|
end
|
quiz index optimizations
Closes CNVS-15109, CNVS-15173
CHANGES
-------
- "auto-grading" of due submissions that was previously done
synchronously in the index action is now done in a DJ
- when viewing the index page, you don't get to see due/available
dates on load, instead the dates are fetched on the client-side and
load progressively
- new API endpoint for retrieving assignment overrides for a bunch of
quizzes at [GET] /courses/:course_id/quizzes/assignment_overrides
- we now cache the user's quiz permissions
- Canvas AMS API serializer now accepts a new option, see docs
- QuizSerializer behavior changed radically:
- "takeable", "submitted_students", "unsubmitted_students" disabled
- all associations disabled including the submission, assignment
group, and any student participants
- it can now utilize preloaded permissions
Rationale behind disabling things in the serializer is that these were
exclusive for the "show" action, so the next step forwards is to
allow the serializer to recognize different "modes" for output (e.g, for
index and one for show) and tailor the associations/fields accordingly.
Using "#filter" right now isn't cutting it, because assocs get loaded
anyway.
REFACTORING
-----------
- broke down index into three actions for visibility:
1. default, Draft-State version
2. legacy non-DS version that's not reachable in the UI, kept around
until we upgrade the tests
3. ember version
- legacy non-DS ERB code goes into its own file
- moved code that used to grade due submissions inside index to
SubmissionGrader in preparation to remove it from there entirely
- cleaned up internal docs for the Canvas AMS api serializer
TEST PLAN
---- ----
- create ~30 quizzes
+ make one of them have many questions
+ make a good number of submissions (i tested with 420 and 20
students)
- create multiple sections
+ specify date overrides for certain sections, and have at least one
student enrolled in that section
- as a teacher and/or an observer, go to quizzes index
+ verify the page renders fine
+ verify that you see "loading indicators" in the due/available
field which get replaced with actual dates when they're loaded
+ verify it's faster than the version in master (should be at least
60% faster)
- as a student in the general section, go to quizzes index
+ verify the page renders
+ verify you see the same loading behavior for dates as in teacher
view
- as a student in one of the section with overrides, go to index:
+ verify you see the overridden date
Change-Id: I741d89625da1b858148baa95e881fcc75c1802e5
Reviewed-on: https://gerrit.instructure.com/40350
Reviewed-by: Derek DeVries <ddevries@instructure.com>
Tested-by: Jenkins <jenkins@instructure.com>
QA-Review: Trevor deHaan <tdehaan@instructure.com>
Product-Review: Ahmad Amireh <ahmad@instructure.com>
2014-08-31 15:20:52 +08:00
|
|
|
|
|
|
|
it "doesn't if skip_lock_tests is on" do
|
|
|
|
quiz.expects(:locked_for?).never
|
|
|
|
json = quiz_serializer({
|
|
|
|
serializer_options: {
|
|
|
|
skip_lock_tests: true
|
|
|
|
}
|
|
|
|
}).as_json[:quiz]
|
2014-10-14 02:04:33 +08:00
|
|
|
expect(json).not_to have_key :lock_info
|
|
|
|
expect(json).not_to have_key :lock_explanation
|
|
|
|
expect(json).not_to have_key :locked_for_user
|
quiz index optimizations
Closes CNVS-15109, CNVS-15173
CHANGES
-------
- "auto-grading" of due submissions that was previously done
synchronously in the index action is now done in a DJ
- when viewing the index page, you don't get to see due/available
dates on load, instead the dates are fetched on the client-side and
load progressively
- new API endpoint for retrieving assignment overrides for a bunch of
quizzes at [GET] /courses/:course_id/quizzes/assignment_overrides
- we now cache the user's quiz permissions
- Canvas AMS API serializer now accepts a new option, see docs
- QuizSerializer behavior changed radically:
- "takeable", "submitted_students", "unsubmitted_students" disabled
- all associations disabled including the submission, assignment
group, and any student participants
- it can now utilize preloaded permissions
Rationale behind disabling things in the serializer is that these were
exclusive for the "show" action, so the next step forwards is to
allow the serializer to recognize different "modes" for output (e.g, for
index and one for show) and tailor the associations/fields accordingly.
Using "#filter" right now isn't cutting it, because assocs get loaded
anyway.
REFACTORING
-----------
- broke down index into three actions for visibility:
1. default, Draft-State version
2. legacy non-DS version that's not reachable in the UI, kept around
until we upgrade the tests
3. ember version
- legacy non-DS ERB code goes into its own file
- moved code that used to grade due submissions inside index to
SubmissionGrader in preparation to remove it from there entirely
- cleaned up internal docs for the Canvas AMS api serializer
TEST PLAN
---- ----
- create ~30 quizzes
+ make one of them have many questions
+ make a good number of submissions (i tested with 420 and 20
students)
- create multiple sections
+ specify date overrides for certain sections, and have at least one
student enrolled in that section
- as a teacher and/or an observer, go to quizzes index
+ verify the page renders fine
+ verify that you see "loading indicators" in the due/available
field which get replaced with actual dates when they're loaded
+ verify it's faster than the version in master (should be at least
60% faster)
- as a student in the general section, go to quizzes index
+ verify the page renders
+ verify you see the same loading behavior for dates as in teacher
view
- as a student in one of the section with overrides, go to index:
+ verify you see the overridden date
Change-Id: I741d89625da1b858148baa95e881fcc75c1802e5
Reviewed-on: https://gerrit.instructure.com/40350
Reviewed-by: Derek DeVries <ddevries@instructure.com>
Tested-by: Jenkins <jenkins@instructure.com>
QA-Review: Trevor deHaan <tdehaan@instructure.com>
Product-Review: Ahmad Amireh <ahmad@instructure.com>
2014-08-31 15:20:52 +08:00
|
|
|
end
|
import ActiveModel::Serializers port and convert quizzes api to it
test plan:
- The quiz api should work like it normally does when you don't pass
an 'Accept: application/vnd.api+json' header.
- The quizzes index page and quiz edit page should work like they
always do.
- Testing the Quizzes API for "jsonapi" style:
- For all requests, you MUST have the "Accept" header set to
"application/vnd.api+json"
- Test all the endpoints (PUT, POST, GET, INDEX, DELETE) like you
normally would, except you'll need to format the data according to
the next few steps:
- For "POST" and "PUT" (create and update) requests, you should send
the data like: { "quizzes": [ { id: 1, title: "blah" } ]
- For all requests (except DELETE), you should get back a response
that looks like: { "quizzes": [ { quiz you requested } ]
- For the "delete" action, you should get a "no content" response
and the request should be successful
Change-Id: Ie91deaeb6772cbe52a0fc46a28ab93a4e3036061
Reviewed-on: https://gerrit.instructure.com/25997
Reviewed-by: Jacob Fugal <jacob@instructure.com>
Tested-by: Jenkins <jenkins@instructure.com>
QA-Review: Caleb Guanzon <cguanzon@instructure.com>
Product-Review: Stanley Stuart <stanley@instructure.com>
2013-12-05 03:06:32 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "unpublishable" do
|
|
|
|
|
|
|
|
it "is not present unless the user can manage the quiz's assignments" do
|
|
|
|
quiz.expects(:grants_right?).with(@user, session, :manage).returns true
|
2014-10-14 02:04:33 +08:00
|
|
|
expect(serializer.filter(serializer.class._attributes)).to include :unpublishable
|
2014-05-22 06:39:53 +08:00
|
|
|
|
import ActiveModel::Serializers port and convert quizzes api to it
test plan:
- The quiz api should work like it normally does when you don't pass
an 'Accept: application/vnd.api+json' header.
- The quizzes index page and quiz edit page should work like they
always do.
- Testing the Quizzes API for "jsonapi" style:
- For all requests, you MUST have the "Accept" header set to
"application/vnd.api+json"
- Test all the endpoints (PUT, POST, GET, INDEX, DELETE) like you
normally would, except you'll need to format the data according to
the next few steps:
- For "POST" and "PUT" (create and update) requests, you should send
the data like: { "quizzes": [ { id: 1, title: "blah" } ]
- For all requests (except DELETE), you should get back a response
that looks like: { "quizzes": [ { quiz you requested } ]
- For the "delete" action, you should get a "no content" response
and the request should be successful
Change-Id: Ie91deaeb6772cbe52a0fc46a28ab93a4e3036061
Reviewed-on: https://gerrit.instructure.com/25997
Reviewed-by: Jacob Fugal <jacob@instructure.com>
Tested-by: Jenkins <jenkins@instructure.com>
QA-Review: Caleb Guanzon <cguanzon@instructure.com>
Product-Review: Stanley Stuart <stanley@instructure.com>
2013-12-05 03:06:32 +08:00
|
|
|
quiz.unstub(:grants_right?)
|
|
|
|
quiz.expects(:grants_right?).with(@user, session, :grade).at_least_once.returns false
|
|
|
|
quiz.expects(:grants_right?).with(@user, session, :manage).at_least_once.returns false
|
2014-10-14 02:04:33 +08:00
|
|
|
expect(serializer.filter(serializer.class._attributes)).not_to include :unpublishable
|
import ActiveModel::Serializers port and convert quizzes api to it
test plan:
- The quiz api should work like it normally does when you don't pass
an 'Accept: application/vnd.api+json' header.
- The quizzes index page and quiz edit page should work like they
always do.
- Testing the Quizzes API for "jsonapi" style:
- For all requests, you MUST have the "Accept" header set to
"application/vnd.api+json"
- Test all the endpoints (PUT, POST, GET, INDEX, DELETE) like you
normally would, except you'll need to format the data according to
the next few steps:
- For "POST" and "PUT" (create and update) requests, you should send
the data like: { "quizzes": [ { id: 1, title: "blah" } ]
- For all requests (except DELETE), you should get back a response
that looks like: { "quizzes": [ { quiz you requested } ]
- For the "delete" action, you should get a "no content" response
and the request should be successful
Change-Id: Ie91deaeb6772cbe52a0fc46a28ab93a4e3036061
Reviewed-on: https://gerrit.instructure.com/25997
Reviewed-by: Jacob Fugal <jacob@instructure.com>
Tested-by: Jenkins <jenkins@instructure.com>
QA-Review: Caleb Guanzon <cguanzon@instructure.com>
Product-Review: Stanley Stuart <stanley@instructure.com>
2013-12-05 03:06:32 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-05-15 08:22:39 +08:00
|
|
|
describe "takeable" do
|
2014-10-14 02:04:33 +08:00
|
|
|
before { skip }
|
2014-05-15 08:22:39 +08:00
|
|
|
before do
|
2016-12-06 06:06:14 +08:00
|
|
|
course_with_teacher(active_all: true)
|
2014-05-15 08:22:39 +08:00
|
|
|
course_quiz(true)
|
|
|
|
quiz_with_graded_submission([], user: @teacher, quiz: @quiz)
|
|
|
|
@serializer = quiz_serializer(quiz_submissions: { @quiz.id => @quiz_submission })
|
|
|
|
end
|
|
|
|
|
|
|
|
it "is true when there is no quiz submision" do
|
|
|
|
Quizzes::QuizSubmission.delete_all
|
2014-10-14 02:04:33 +08:00
|
|
|
expect(quiz_serializer.as_json[:quiz][:takeable]).to eq true
|
2014-05-15 08:22:39 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "is true when quiz_submission is present but not completed" do
|
|
|
|
@quiz_submission.workflow_state = "settings_only"
|
2014-10-14 02:04:33 +08:00
|
|
|
expect(@serializer.as_json[:quiz][:takeable]).to eq true
|
2014-05-15 08:22:39 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "is true when the quiz submission is completed but quiz has unlimited attempts" do
|
|
|
|
@quiz_submission.workflow_state = "complete"
|
|
|
|
@quiz.allowed_attempts = -1
|
2014-10-14 02:04:33 +08:00
|
|
|
expect(@serializer.as_json[:quiz][:takeable]).to eq true
|
2014-05-15 08:22:39 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "is true when quiz submission is completed, !quiz.unlimited_attempts" do
|
|
|
|
@quiz_submission.workflow_state = "complete"
|
|
|
|
@quiz.allowed_attempts = 2
|
|
|
|
# false when attempts left attempts is 0
|
|
|
|
@quiz_submission.expects(:attempts_left).at_least_once.returns 0
|
2014-10-14 02:04:33 +08:00
|
|
|
expect(@serializer.as_json[:quiz][:takeable]).to eq false
|
2014-05-15 08:22:39 +08:00
|
|
|
# true when than attempts left greater than 0
|
|
|
|
@quiz_submission.expects(:attempts_left).at_least_once.returns 1
|
2014-10-14 02:04:33 +08:00
|
|
|
expect(@serializer.as_json[:quiz][:takeable]).to eq true
|
2014-05-15 08:22:39 +08:00
|
|
|
end
|
2014-05-21 03:59:32 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "preview_url" do
|
2014-05-15 08:22:39 +08:00
|
|
|
|
2014-05-21 03:59:32 +08:00
|
|
|
it "is only present when the user can grade the quiz" do
|
2016-12-06 06:06:14 +08:00
|
|
|
course_with_teacher(active_all: true)
|
2014-05-21 03:59:32 +08:00
|
|
|
course_quiz(true)
|
2014-10-14 02:04:33 +08:00
|
|
|
expect(quiz_serializer(scope: @teacher).as_json[:quiz][:preview_url]).
|
|
|
|
to eq controller.send(:course_quiz_take_url, @quiz.context, @quiz, preview: '1')
|
2016-12-06 06:06:14 +08:00
|
|
|
course_with_student(active_all: true, course: @course)
|
2014-10-14 02:04:33 +08:00
|
|
|
expect(quiz_serializer(scope: @student).as_json[:quiz]).not_to have_key :preview_url
|
2014-05-21 03:59:32 +08:00
|
|
|
end
|
2014-05-15 08:22:39 +08:00
|
|
|
end
|
|
|
|
|
import ActiveModel::Serializers port and convert quizzes api to it
test plan:
- The quiz api should work like it normally does when you don't pass
an 'Accept: application/vnd.api+json' header.
- The quizzes index page and quiz edit page should work like they
always do.
- Testing the Quizzes API for "jsonapi" style:
- For all requests, you MUST have the "Accept" header set to
"application/vnd.api+json"
- Test all the endpoints (PUT, POST, GET, INDEX, DELETE) like you
normally would, except you'll need to format the data according to
the next few steps:
- For "POST" and "PUT" (create and update) requests, you should send
the data like: { "quizzes": [ { id: 1, title: "blah" } ]
- For all requests (except DELETE), you should get back a response
that looks like: { "quizzes": [ { quiz you requested } ]
- For the "delete" action, you should get a "no content" response
and the request should be successful
Change-Id: Ie91deaeb6772cbe52a0fc46a28ab93a4e3036061
Reviewed-on: https://gerrit.instructure.com/25997
Reviewed-by: Jacob Fugal <jacob@instructure.com>
Tested-by: Jenkins <jenkins@instructure.com>
QA-Review: Caleb Guanzon <cguanzon@instructure.com>
Product-Review: Stanley Stuart <stanley@instructure.com>
2013-12-05 03:06:32 +08:00
|
|
|
describe "links" do
|
|
|
|
|
|
|
|
describe "assignment_group" do
|
|
|
|
|
|
|
|
context "controller accepts_jsonapi?" do
|
2014-10-14 02:04:33 +08:00
|
|
|
before { skip }
|
import ActiveModel::Serializers port and convert quizzes api to it
test plan:
- The quiz api should work like it normally does when you don't pass
an 'Accept: application/vnd.api+json' header.
- The quizzes index page and quiz edit page should work like they
always do.
- Testing the Quizzes API for "jsonapi" style:
- For all requests, you MUST have the "Accept" header set to
"application/vnd.api+json"
- Test all the endpoints (PUT, POST, GET, INDEX, DELETE) like you
normally would, except you'll need to format the data according to
the next few steps:
- For "POST" and "PUT" (create and update) requests, you should send
the data like: { "quizzes": [ { id: 1, title: "blah" } ]
- For all requests (except DELETE), you should get back a response
that looks like: { "quizzes": [ { quiz you requested } ]
- For the "delete" action, you should get a "no content" response
and the request should be successful
Change-Id: Ie91deaeb6772cbe52a0fc46a28ab93a4e3036061
Reviewed-on: https://gerrit.instructure.com/25997
Reviewed-by: Jacob Fugal <jacob@instructure.com>
Tested-by: Jenkins <jenkins@instructure.com>
QA-Review: Caleb Guanzon <cguanzon@instructure.com>
Product-Review: Stanley Stuart <stanley@instructure.com>
2013-12-05 03:06:32 +08:00
|
|
|
|
|
|
|
it "serialize the assignment group's url when present" do
|
2016-01-07 13:00:57 +08:00
|
|
|
@quiz.stubs(:context).returns course = Account.default.courses.new
|
import ActiveModel::Serializers port and convert quizzes api to it
test plan:
- The quiz api should work like it normally does when you don't pass
an 'Accept: application/vnd.api+json' header.
- The quizzes index page and quiz edit page should work like they
always do.
- Testing the Quizzes API for "jsonapi" style:
- For all requests, you MUST have the "Accept" header set to
"application/vnd.api+json"
- Test all the endpoints (PUT, POST, GET, INDEX, DELETE) like you
normally would, except you'll need to format the data according to
the next few steps:
- For "POST" and "PUT" (create and update) requests, you should send
the data like: { "quizzes": [ { id: 1, title: "blah" } ]
- For all requests (except DELETE), you should get back a response
that looks like: { "quizzes": [ { quiz you requested } ]
- For the "delete" action, you should get a "no content" response
and the request should be successful
Change-Id: Ie91deaeb6772cbe52a0fc46a28ab93a4e3036061
Reviewed-on: https://gerrit.instructure.com/25997
Reviewed-by: Jacob Fugal <jacob@instructure.com>
Tested-by: Jenkins <jenkins@instructure.com>
QA-Review: Caleb Guanzon <cguanzon@instructure.com>
Product-Review: Stanley Stuart <stanley@instructure.com>
2013-12-05 03:06:32 +08:00
|
|
|
course.id = 1
|
|
|
|
@quiz.assignment_group = assignment_group = AssignmentGroup.new
|
|
|
|
assignment_group.id = 1
|
2014-10-14 02:04:33 +08:00
|
|
|
expect(serializer.as_json[:quiz]['links']['assignment_group']).to eq(
|
import ActiveModel::Serializers port and convert quizzes api to it
test plan:
- The quiz api should work like it normally does when you don't pass
an 'Accept: application/vnd.api+json' header.
- The quizzes index page and quiz edit page should work like they
always do.
- Testing the Quizzes API for "jsonapi" style:
- For all requests, you MUST have the "Accept" header set to
"application/vnd.api+json"
- Test all the endpoints (PUT, POST, GET, INDEX, DELETE) like you
normally would, except you'll need to format the data according to
the next few steps:
- For "POST" and "PUT" (create and update) requests, you should send
the data like: { "quizzes": [ { id: 1, title: "blah" } ]
- For all requests (except DELETE), you should get back a response
that looks like: { "quizzes": [ { quiz you requested } ]
- For the "delete" action, you should get a "no content" response
and the request should be successful
Change-Id: Ie91deaeb6772cbe52a0fc46a28ab93a4e3036061
Reviewed-on: https://gerrit.instructure.com/25997
Reviewed-by: Jacob Fugal <jacob@instructure.com>
Tested-by: Jenkins <jenkins@instructure.com>
QA-Review: Caleb Guanzon <cguanzon@instructure.com>
Product-Review: Stanley Stuart <stanley@instructure.com>
2013-12-05 03:06:32 +08:00
|
|
|
controller.send(:api_v1_course_assignment_group_url, course.id,
|
|
|
|
assignment_group.id)
|
2014-10-14 02:04:33 +08:00
|
|
|
)
|
import ActiveModel::Serializers port and convert quizzes api to it
test plan:
- The quiz api should work like it normally does when you don't pass
an 'Accept: application/vnd.api+json' header.
- The quizzes index page and quiz edit page should work like they
always do.
- Testing the Quizzes API for "jsonapi" style:
- For all requests, you MUST have the "Accept" header set to
"application/vnd.api+json"
- Test all the endpoints (PUT, POST, GET, INDEX, DELETE) like you
normally would, except you'll need to format the data according to
the next few steps:
- For "POST" and "PUT" (create and update) requests, you should send
the data like: { "quizzes": [ { id: 1, title: "blah" } ]
- For all requests (except DELETE), you should get back a response
that looks like: { "quizzes": [ { quiz you requested } ]
- For the "delete" action, you should get a "no content" response
and the request should be successful
Change-Id: Ie91deaeb6772cbe52a0fc46a28ab93a4e3036061
Reviewed-on: https://gerrit.instructure.com/25997
Reviewed-by: Jacob Fugal <jacob@instructure.com>
Tested-by: Jenkins <jenkins@instructure.com>
QA-Review: Caleb Guanzon <cguanzon@instructure.com>
Product-Review: Stanley Stuart <stanley@instructure.com>
2013-12-05 03:06:32 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't serialize the assignment group's url if not present" do
|
2014-10-14 02:04:33 +08:00
|
|
|
expect(serializer.as_json[:quiz]).not_to have_key(:links)
|
import ActiveModel::Serializers port and convert quizzes api to it
test plan:
- The quiz api should work like it normally does when you don't pass
an 'Accept: application/vnd.api+json' header.
- The quizzes index page and quiz edit page should work like they
always do.
- Testing the Quizzes API for "jsonapi" style:
- For all requests, you MUST have the "Accept" header set to
"application/vnd.api+json"
- Test all the endpoints (PUT, POST, GET, INDEX, DELETE) like you
normally would, except you'll need to format the data according to
the next few steps:
- For "POST" and "PUT" (create and update) requests, you should send
the data like: { "quizzes": [ { id: 1, title: "blah" } ]
- For all requests (except DELETE), you should get back a response
that looks like: { "quizzes": [ { quiz you requested } ]
- For the "delete" action, you should get a "no content" response
and the request should be successful
Change-Id: Ie91deaeb6772cbe52a0fc46a28ab93a4e3036061
Reviewed-on: https://gerrit.instructure.com/25997
Reviewed-by: Jacob Fugal <jacob@instructure.com>
Tested-by: Jenkins <jenkins@instructure.com>
QA-Review: Caleb Guanzon <cguanzon@instructure.com>
Product-Review: Stanley Stuart <stanley@instructure.com>
2013-12-05 03:06:32 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "controller doesn't accept jsonapi" do
|
|
|
|
|
|
|
|
it "serialized the assignment_group as assignment_group_id" do
|
|
|
|
controller.expects(:accepts_jsonapi?).at_least_once.returns false
|
2014-10-14 02:04:33 +08:00
|
|
|
expect(serializer.as_json[:quiz]['assignment_group_id']).to be_nil
|
import ActiveModel::Serializers port and convert quizzes api to it
test plan:
- The quiz api should work like it normally does when you don't pass
an 'Accept: application/vnd.api+json' header.
- The quizzes index page and quiz edit page should work like they
always do.
- Testing the Quizzes API for "jsonapi" style:
- For all requests, you MUST have the "Accept" header set to
"application/vnd.api+json"
- Test all the endpoints (PUT, POST, GET, INDEX, DELETE) like you
normally would, except you'll need to format the data according to
the next few steps:
- For "POST" and "PUT" (create and update) requests, you should send
the data like: { "quizzes": [ { id: 1, title: "blah" } ]
- For all requests (except DELETE), you should get back a response
that looks like: { "quizzes": [ { quiz you requested } ]
- For the "delete" action, you should get a "no content" response
and the request should be successful
Change-Id: Ie91deaeb6772cbe52a0fc46a28ab93a4e3036061
Reviewed-on: https://gerrit.instructure.com/25997
Reviewed-by: Jacob Fugal <jacob@instructure.com>
Tested-by: Jenkins <jenkins@instructure.com>
QA-Review: Caleb Guanzon <cguanzon@instructure.com>
Product-Review: Stanley Stuart <stanley@instructure.com>
2013-12-05 03:06:32 +08:00
|
|
|
|
|
|
|
group = quiz.assignment_group = AssignmentGroup.new
|
quiz index optimizations
Closes CNVS-15109, CNVS-15173
CHANGES
-------
- "auto-grading" of due submissions that was previously done
synchronously in the index action is now done in a DJ
- when viewing the index page, you don't get to see due/available
dates on load, instead the dates are fetched on the client-side and
load progressively
- new API endpoint for retrieving assignment overrides for a bunch of
quizzes at [GET] /courses/:course_id/quizzes/assignment_overrides
- we now cache the user's quiz permissions
- Canvas AMS API serializer now accepts a new option, see docs
- QuizSerializer behavior changed radically:
- "takeable", "submitted_students", "unsubmitted_students" disabled
- all associations disabled including the submission, assignment
group, and any student participants
- it can now utilize preloaded permissions
Rationale behind disabling things in the serializer is that these were
exclusive for the "show" action, so the next step forwards is to
allow the serializer to recognize different "modes" for output (e.g, for
index and one for show) and tailor the associations/fields accordingly.
Using "#filter" right now isn't cutting it, because assocs get loaded
anyway.
REFACTORING
-----------
- broke down index into three actions for visibility:
1. default, Draft-State version
2. legacy non-DS version that's not reachable in the UI, kept around
until we upgrade the tests
3. ember version
- legacy non-DS ERB code goes into its own file
- moved code that used to grade due submissions inside index to
SubmissionGrader in preparation to remove it from there entirely
- cleaned up internal docs for the Canvas AMS api serializer
TEST PLAN
---- ----
- create ~30 quizzes
+ make one of them have many questions
+ make a good number of submissions (i tested with 420 and 20
students)
- create multiple sections
+ specify date overrides for certain sections, and have at least one
student enrolled in that section
- as a teacher and/or an observer, go to quizzes index
+ verify the page renders fine
+ verify that you see "loading indicators" in the due/available
field which get replaced with actual dates when they're loaded
+ verify it's faster than the version in master (should be at least
60% faster)
- as a student in the general section, go to quizzes index
+ verify the page renders
+ verify you see the same loading behavior for dates as in teacher
view
- as a student in one of the section with overrides, go to index:
+ verify you see the overridden date
Change-Id: I741d89625da1b858148baa95e881fcc75c1802e5
Reviewed-on: https://gerrit.instructure.com/40350
Reviewed-by: Derek DeVries <ddevries@instructure.com>
Tested-by: Jenkins <jenkins@instructure.com>
QA-Review: Trevor deHaan <tdehaan@instructure.com>
Product-Review: Ahmad Amireh <ahmad@instructure.com>
2014-08-31 15:20:52 +08:00
|
|
|
group.id = quiz.assignment_group_id = 1
|
2014-10-14 02:04:33 +08:00
|
|
|
expect(serializer.as_json[:quiz][:assignment_group_id]).to eq 1
|
import ActiveModel::Serializers port and convert quizzes api to it
test plan:
- The quiz api should work like it normally does when you don't pass
an 'Accept: application/vnd.api+json' header.
- The quizzes index page and quiz edit page should work like they
always do.
- Testing the Quizzes API for "jsonapi" style:
- For all requests, you MUST have the "Accept" header set to
"application/vnd.api+json"
- Test all the endpoints (PUT, POST, GET, INDEX, DELETE) like you
normally would, except you'll need to format the data according to
the next few steps:
- For "POST" and "PUT" (create and update) requests, you should send
the data like: { "quizzes": [ { id: 1, title: "blah" } ]
- For all requests (except DELETE), you should get back a response
that looks like: { "quizzes": [ { quiz you requested } ]
- For the "delete" action, you should get a "no content" response
and the request should be successful
Change-Id: Ie91deaeb6772cbe52a0fc46a28ab93a4e3036061
Reviewed-on: https://gerrit.instructure.com/25997
Reviewed-by: Jacob Fugal <jacob@instructure.com>
Tested-by: Jenkins <jenkins@instructure.com>
QA-Review: Caleb Guanzon <cguanzon@instructure.com>
Product-Review: Stanley Stuart <stanley@instructure.com>
2013-12-05 03:06:32 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2014-02-25 04:42:19 +08:00
|
|
|
|
2014-05-08 05:23:56 +08:00
|
|
|
describe "student_quiz_submissions" do
|
2014-10-14 02:04:33 +08:00
|
|
|
before { skip }
|
2014-05-23 01:55:31 +08:00
|
|
|
context "when user may grade" do
|
|
|
|
|
|
|
|
it "sends the url for all submissions" do
|
2016-12-06 06:06:14 +08:00
|
|
|
course_with_teacher(active_all: true)
|
2014-05-23 01:55:31 +08:00
|
|
|
quiz_with_graded_submission([], course: @course)
|
|
|
|
serializer = quiz_serializer(scope: @teacher)
|
2014-10-14 02:04:33 +08:00
|
|
|
expect(serializer.as_json[:quiz]['links']['student_quiz_submissions']).to eq(
|
2014-05-23 01:55:31 +08:00
|
|
|
controller.send(:api_v1_course_quiz_submissions_url, @quiz.context.id, @quiz.id)
|
2014-10-14 02:04:33 +08:00
|
|
|
)
|
2014-05-23 01:55:31 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "sends the url when no student_quiz_submissions are present" do
|
2016-12-06 06:06:14 +08:00
|
|
|
course_with_teacher(active_all: true)
|
2014-05-23 01:55:31 +08:00
|
|
|
serializer = quiz_serializer(scope: @teacher)
|
2014-10-14 02:04:33 +08:00
|
|
|
expect(serializer.as_json[:quiz]['links']['student_quiz_submissions']).to eq(
|
2014-05-23 01:55:31 +08:00
|
|
|
controller.send(:api_v1_course_quiz_submissions_url, @quiz.context.id, @quiz.id)
|
2014-10-14 02:04:33 +08:00
|
|
|
)
|
2014-05-23 01:55:31 +08:00
|
|
|
end
|
|
|
|
|
2014-02-25 04:42:19 +08:00
|
|
|
end
|
|
|
|
|
2014-05-23 01:55:31 +08:00
|
|
|
context "when user may not grade" do
|
|
|
|
|
|
|
|
it "sends nil" do
|
2016-12-06 06:06:14 +08:00
|
|
|
course_with_student(active_all: true)
|
2014-05-23 01:55:31 +08:00
|
|
|
quiz_with_graded_submission([], user: @student, course: @course)
|
|
|
|
serializer = quiz_serializer(scope: @student)
|
2014-10-14 02:04:33 +08:00
|
|
|
expect(serializer.as_json[:quiz]['links']['student_quiz_submissions']).to be_nil
|
2014-05-23 01:55:31 +08:00
|
|
|
end
|
|
|
|
|
2014-02-25 04:42:19 +08:00
|
|
|
end
|
2014-05-23 01:55:31 +08:00
|
|
|
|
2014-05-08 05:23:56 +08:00
|
|
|
end
|
2014-02-25 04:42:19 +08:00
|
|
|
|
2014-05-08 05:23:56 +08:00
|
|
|
describe "quiz_submission" do
|
2014-10-14 02:04:33 +08:00
|
|
|
before { skip }
|
2014-05-08 05:23:56 +08:00
|
|
|
it "includes the quiz_submission in the response if it is present" do
|
2016-12-06 06:06:14 +08:00
|
|
|
course_with_student(active_all: true)
|
2014-05-08 05:23:56 +08:00
|
|
|
quiz_with_graded_submission([], user: @student, course: @course)
|
2014-03-05 00:33:05 +08:00
|
|
|
serializer = quiz_serializer(scope: @student)
|
2014-05-08 05:23:56 +08:00
|
|
|
json = serializer.as_json
|
2014-10-14 02:04:33 +08:00
|
|
|
expect(json['quiz_submissions'].length).to eq 1
|
|
|
|
expect(json[:quiz]['links']['quiz_submission']).to eq @quiz_submission.id.to_s
|
2014-02-25 04:42:19 +08:00
|
|
|
end
|
|
|
|
end
|
Quiz Reports API - Index
An endpoint for retrieving all quiz reports for a given quiz.
Closes CNVS-12172
CHANGES
-------
The biggest effort in this patch was to normalize the way QuizReport
objects are interfaced with, and the generation of their CSV attachments
in particular:
- Quiz#current_statistics_for() now ALWAYS returns a persisted object
while still considering the freshness of the stats
- Quiz#statistics_csv() is no longer responsible for testing whether
the attachment should be generated or not, but instead ensures
that the CSV will be generated ASAP
- QuizStatistics#generate_csv() now guards against generating multiple
attachments
- QuizStatistics#generate_csv_in_background() now guards against
queueing multiple generation jobs (by testing the status of the
Progress object)
QuizReport API changes:
- new property: "generatable"
- new property: "readable_type"
- new property: "url"
- now accepts JSON-API format for all endpoints:
- JSON-API allows you to embed file and progress objects directly in
the QuizReport document, just pass ?include=file,progress
Quizzes API changes:
- new property (JSON): "quiz_reports_url"
- new property (JSON-API): "links.quiz_reports"
Some AMS changes:
- added support for accepting side-loading requests from controllers
by passing an :includes array to the serializer initializer
- added support for embedding objects in root, using `embed: :object
and embed_in_root: true` for has_one associations
- also, in that same scenario, AMS's default behavior is to wrap
single objects (has_one) in an array, which didn't work for me, so I
added a new option called "wrap_in_array" which you can set to false
when defining the association to override this behavior
Other changes:
- covered the front-end/javascript that utilizes the reports and
allows teachers to generate them
- QuizReport in the front-end no longer relies on magical course_id
exposed in window.ENV, but instead uses its URL to construct the
generation URL (see QuizReport#baseURL)
- Attachment now has a shallow-AMSerializer that proxies to the legacy
one in lib/api/v1 which allows us to at least side-load them
- Progress now has an AMS
- QuizReport legacy serializer in lib/api/v1 removed entirely,
replaced by the new AMS one
TEST PLAN
---- ----
Endpoint: [GET] /api/v1/courses/:course_id/quizzes/:quiz_id/reports
- as a teacher, make a request to the endpoint above:
- it should return a set of two quiz report objects
- add a parameter "includes_all_versions=true" to the query parameters
and verify that the "student_analysis" report in the returned set
now reflects the new value (the reports have a field called
"includes_all_versions" which should be true in this case, false
otherwise)
- as a student, make the request and verify that it rejects you
Endpoint: [GET] /api/v1/courses/:course_id/quizzes/:quiz_id/reports/:id
- turn on JSON-API mode
- as a teacher:
- don't generate the report from the UI yet
- make the request, and verify that you get only the report
- generate
- repeat the request, verify that you still get only the report
- add a ?include=file query parameter
- you should read the file document now
- add a ?include=progress query parameter
- you should read the progress document now
- turn off JSON-API mode
- as a teacher:
- make the request, and verify you get the "progress_url" field and
that the file document is embedded automatically without having to
specify the ?include= parameter
Front-end testing:
- go to the statistics page
- generate all reports:
- verify that the progress bar updates
- verify that you can download them
- verify that auto-download occurs unless you refresh the page
before the report is generated
- toggle on the "Count All Attempts" button and repeat the above:
- verify that Item Analysis is not generatable anymore since it's
not affected by that parameter
Please note that "item_analysis" reports will always have
"includes_all_versions" as true.
Change-Id: I0dc6d5108cbcef78b2fa17ba0476f470d33d402d
Reviewed-on: https://gerrit.instructure.com/32731
Tested-by: Jenkins <jenkins@instructure.com>
Reviewed-by: Derek DeVries <ddevries@instructure.com>
QA-Review: Caleb Guanzon <cguanzon@instructure.com>
Product-Review: Derek DeVries <ddevries@instructure.com>
2014-04-02 12:52:00 +08:00
|
|
|
|
|
|
|
describe 'quiz_reports' do
|
|
|
|
it 'sends the url' do
|
2016-01-07 13:00:57 +08:00
|
|
|
quiz.stubs(context: Account.default.courses.new.tap { |c| c.id = 3 })
|
2014-10-14 02:04:33 +08:00
|
|
|
expect(serializer.as_json[:quiz]['links']['quiz_reports']).to eq(
|
Quiz Reports API - Index
An endpoint for retrieving all quiz reports for a given quiz.
Closes CNVS-12172
CHANGES
-------
The biggest effort in this patch was to normalize the way QuizReport
objects are interfaced with, and the generation of their CSV attachments
in particular:
- Quiz#current_statistics_for() now ALWAYS returns a persisted object
while still considering the freshness of the stats
- Quiz#statistics_csv() is no longer responsible for testing whether
the attachment should be generated or not, but instead ensures
that the CSV will be generated ASAP
- QuizStatistics#generate_csv() now guards against generating multiple
attachments
- QuizStatistics#generate_csv_in_background() now guards against
queueing multiple generation jobs (by testing the status of the
Progress object)
QuizReport API changes:
- new property: "generatable"
- new property: "readable_type"
- new property: "url"
- now accepts JSON-API format for all endpoints:
- JSON-API allows you to embed file and progress objects directly in
the QuizReport document, just pass ?include=file,progress
Quizzes API changes:
- new property (JSON): "quiz_reports_url"
- new property (JSON-API): "links.quiz_reports"
Some AMS changes:
- added support for accepting side-loading requests from controllers
by passing an :includes array to the serializer initializer
- added support for embedding objects in root, using `embed: :object
and embed_in_root: true` for has_one associations
- also, in that same scenario, AMS's default behavior is to wrap
single objects (has_one) in an array, which didn't work for me, so I
added a new option called "wrap_in_array" which you can set to false
when defining the association to override this behavior
Other changes:
- covered the front-end/javascript that utilizes the reports and
allows teachers to generate them
- QuizReport in the front-end no longer relies on magical course_id
exposed in window.ENV, but instead uses its URL to construct the
generation URL (see QuizReport#baseURL)
- Attachment now has a shallow-AMSerializer that proxies to the legacy
one in lib/api/v1 which allows us to at least side-load them
- Progress now has an AMS
- QuizReport legacy serializer in lib/api/v1 removed entirely,
replaced by the new AMS one
TEST PLAN
---- ----
Endpoint: [GET] /api/v1/courses/:course_id/quizzes/:quiz_id/reports
- as a teacher, make a request to the endpoint above:
- it should return a set of two quiz report objects
- add a parameter "includes_all_versions=true" to the query parameters
and verify that the "student_analysis" report in the returned set
now reflects the new value (the reports have a field called
"includes_all_versions" which should be true in this case, false
otherwise)
- as a student, make the request and verify that it rejects you
Endpoint: [GET] /api/v1/courses/:course_id/quizzes/:quiz_id/reports/:id
- turn on JSON-API mode
- as a teacher:
- don't generate the report from the UI yet
- make the request, and verify that you get only the report
- generate
- repeat the request, verify that you still get only the report
- add a ?include=file query parameter
- you should read the file document now
- add a ?include=progress query parameter
- you should read the progress document now
- turn off JSON-API mode
- as a teacher:
- make the request, and verify you get the "progress_url" field and
that the file document is embedded automatically without having to
specify the ?include= parameter
Front-end testing:
- go to the statistics page
- generate all reports:
- verify that the progress bar updates
- verify that you can download them
- verify that auto-download occurs unless you refresh the page
before the report is generated
- toggle on the "Count All Attempts" button and repeat the above:
- verify that Item Analysis is not generatable anymore since it's
not affected by that parameter
Please note that "item_analysis" reports will always have
"includes_all_versions" as true.
Change-Id: I0dc6d5108cbcef78b2fa17ba0476f470d33d402d
Reviewed-on: https://gerrit.instructure.com/32731
Tested-by: Jenkins <jenkins@instructure.com>
Reviewed-by: Derek DeVries <ddevries@instructure.com>
QA-Review: Caleb Guanzon <cguanzon@instructure.com>
Product-Review: Derek DeVries <ddevries@instructure.com>
2014-04-02 12:52:00 +08:00
|
|
|
controller.send(:api_v1_course_quiz_reports_url, 3, quiz.id)
|
2014-10-14 02:04:33 +08:00
|
|
|
)
|
Quiz Reports API - Index
An endpoint for retrieving all quiz reports for a given quiz.
Closes CNVS-12172
CHANGES
-------
The biggest effort in this patch was to normalize the way QuizReport
objects are interfaced with, and the generation of their CSV attachments
in particular:
- Quiz#current_statistics_for() now ALWAYS returns a persisted object
while still considering the freshness of the stats
- Quiz#statistics_csv() is no longer responsible for testing whether
the attachment should be generated or not, but instead ensures
that the CSV will be generated ASAP
- QuizStatistics#generate_csv() now guards against generating multiple
attachments
- QuizStatistics#generate_csv_in_background() now guards against
queueing multiple generation jobs (by testing the status of the
Progress object)
QuizReport API changes:
- new property: "generatable"
- new property: "readable_type"
- new property: "url"
- now accepts JSON-API format for all endpoints:
- JSON-API allows you to embed file and progress objects directly in
the QuizReport document, just pass ?include=file,progress
Quizzes API changes:
- new property (JSON): "quiz_reports_url"
- new property (JSON-API): "links.quiz_reports"
Some AMS changes:
- added support for accepting side-loading requests from controllers
by passing an :includes array to the serializer initializer
- added support for embedding objects in root, using `embed: :object
and embed_in_root: true` for has_one associations
- also, in that same scenario, AMS's default behavior is to wrap
single objects (has_one) in an array, which didn't work for me, so I
added a new option called "wrap_in_array" which you can set to false
when defining the association to override this behavior
Other changes:
- covered the front-end/javascript that utilizes the reports and
allows teachers to generate them
- QuizReport in the front-end no longer relies on magical course_id
exposed in window.ENV, but instead uses its URL to construct the
generation URL (see QuizReport#baseURL)
- Attachment now has a shallow-AMSerializer that proxies to the legacy
one in lib/api/v1 which allows us to at least side-load them
- Progress now has an AMS
- QuizReport legacy serializer in lib/api/v1 removed entirely,
replaced by the new AMS one
TEST PLAN
---- ----
Endpoint: [GET] /api/v1/courses/:course_id/quizzes/:quiz_id/reports
- as a teacher, make a request to the endpoint above:
- it should return a set of two quiz report objects
- add a parameter "includes_all_versions=true" to the query parameters
and verify that the "student_analysis" report in the returned set
now reflects the new value (the reports have a field called
"includes_all_versions" which should be true in this case, false
otherwise)
- as a student, make the request and verify that it rejects you
Endpoint: [GET] /api/v1/courses/:course_id/quizzes/:quiz_id/reports/:id
- turn on JSON-API mode
- as a teacher:
- don't generate the report from the UI yet
- make the request, and verify that you get only the report
- generate
- repeat the request, verify that you still get only the report
- add a ?include=file query parameter
- you should read the file document now
- add a ?include=progress query parameter
- you should read the progress document now
- turn off JSON-API mode
- as a teacher:
- make the request, and verify you get the "progress_url" field and
that the file document is embedded automatically without having to
specify the ?include= parameter
Front-end testing:
- go to the statistics page
- generate all reports:
- verify that the progress bar updates
- verify that you can download them
- verify that auto-download occurs unless you refresh the page
before the report is generated
- toggle on the "Count All Attempts" button and repeat the above:
- verify that Item Analysis is not generatable anymore since it's
not affected by that parameter
Please note that "item_analysis" reports will always have
"includes_all_versions" as true.
Change-Id: I0dc6d5108cbcef78b2fa17ba0476f470d33d402d
Reviewed-on: https://gerrit.instructure.com/32731
Tested-by: Jenkins <jenkins@instructure.com>
Reviewed-by: Derek DeVries <ddevries@instructure.com>
QA-Review: Caleb Guanzon <cguanzon@instructure.com>
Product-Review: Derek DeVries <ddevries@instructure.com>
2014-04-02 12:52:00 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'sends the url as quiz_reports_url' do
|
|
|
|
controller.expects(:accepts_jsonapi?).at_least_once.returns false
|
2016-01-07 13:00:57 +08:00
|
|
|
quiz.stubs(context: Account.default.courses.new.tap { |c| c.id = 3 })
|
2014-10-14 02:04:33 +08:00
|
|
|
expect(serializer.as_json[:quiz][:quiz_reports_url]).to eq(
|
Quiz Reports API - Index
An endpoint for retrieving all quiz reports for a given quiz.
Closes CNVS-12172
CHANGES
-------
The biggest effort in this patch was to normalize the way QuizReport
objects are interfaced with, and the generation of their CSV attachments
in particular:
- Quiz#current_statistics_for() now ALWAYS returns a persisted object
while still considering the freshness of the stats
- Quiz#statistics_csv() is no longer responsible for testing whether
the attachment should be generated or not, but instead ensures
that the CSV will be generated ASAP
- QuizStatistics#generate_csv() now guards against generating multiple
attachments
- QuizStatistics#generate_csv_in_background() now guards against
queueing multiple generation jobs (by testing the status of the
Progress object)
QuizReport API changes:
- new property: "generatable"
- new property: "readable_type"
- new property: "url"
- now accepts JSON-API format for all endpoints:
- JSON-API allows you to embed file and progress objects directly in
the QuizReport document, just pass ?include=file,progress
Quizzes API changes:
- new property (JSON): "quiz_reports_url"
- new property (JSON-API): "links.quiz_reports"
Some AMS changes:
- added support for accepting side-loading requests from controllers
by passing an :includes array to the serializer initializer
- added support for embedding objects in root, using `embed: :object
and embed_in_root: true` for has_one associations
- also, in that same scenario, AMS's default behavior is to wrap
single objects (has_one) in an array, which didn't work for me, so I
added a new option called "wrap_in_array" which you can set to false
when defining the association to override this behavior
Other changes:
- covered the front-end/javascript that utilizes the reports and
allows teachers to generate them
- QuizReport in the front-end no longer relies on magical course_id
exposed in window.ENV, but instead uses its URL to construct the
generation URL (see QuizReport#baseURL)
- Attachment now has a shallow-AMSerializer that proxies to the legacy
one in lib/api/v1 which allows us to at least side-load them
- Progress now has an AMS
- QuizReport legacy serializer in lib/api/v1 removed entirely,
replaced by the new AMS one
TEST PLAN
---- ----
Endpoint: [GET] /api/v1/courses/:course_id/quizzes/:quiz_id/reports
- as a teacher, make a request to the endpoint above:
- it should return a set of two quiz report objects
- add a parameter "includes_all_versions=true" to the query parameters
and verify that the "student_analysis" report in the returned set
now reflects the new value (the reports have a field called
"includes_all_versions" which should be true in this case, false
otherwise)
- as a student, make the request and verify that it rejects you
Endpoint: [GET] /api/v1/courses/:course_id/quizzes/:quiz_id/reports/:id
- turn on JSON-API mode
- as a teacher:
- don't generate the report from the UI yet
- make the request, and verify that you get only the report
- generate
- repeat the request, verify that you still get only the report
- add a ?include=file query parameter
- you should read the file document now
- add a ?include=progress query parameter
- you should read the progress document now
- turn off JSON-API mode
- as a teacher:
- make the request, and verify you get the "progress_url" field and
that the file document is embedded automatically without having to
specify the ?include= parameter
Front-end testing:
- go to the statistics page
- generate all reports:
- verify that the progress bar updates
- verify that you can download them
- verify that auto-download occurs unless you refresh the page
before the report is generated
- toggle on the "Count All Attempts" button and repeat the above:
- verify that Item Analysis is not generatable anymore since it's
not affected by that parameter
Please note that "item_analysis" reports will always have
"includes_all_versions" as true.
Change-Id: I0dc6d5108cbcef78b2fa17ba0476f470d33d402d
Reviewed-on: https://gerrit.instructure.com/32731
Tested-by: Jenkins <jenkins@instructure.com>
Reviewed-by: Derek DeVries <ddevries@instructure.com>
QA-Review: Caleb Guanzon <cguanzon@instructure.com>
Product-Review: Derek DeVries <ddevries@instructure.com>
2014-04-02 12:52:00 +08:00
|
|
|
controller.send(:api_v1_course_quiz_reports_url, 3, quiz.id)
|
2014-10-14 02:04:33 +08:00
|
|
|
)
|
Quiz Reports API - Index
An endpoint for retrieving all quiz reports for a given quiz.
Closes CNVS-12172
CHANGES
-------
The biggest effort in this patch was to normalize the way QuizReport
objects are interfaced with, and the generation of their CSV attachments
in particular:
- Quiz#current_statistics_for() now ALWAYS returns a persisted object
while still considering the freshness of the stats
- Quiz#statistics_csv() is no longer responsible for testing whether
the attachment should be generated or not, but instead ensures
that the CSV will be generated ASAP
- QuizStatistics#generate_csv() now guards against generating multiple
attachments
- QuizStatistics#generate_csv_in_background() now guards against
queueing multiple generation jobs (by testing the status of the
Progress object)
QuizReport API changes:
- new property: "generatable"
- new property: "readable_type"
- new property: "url"
- now accepts JSON-API format for all endpoints:
- JSON-API allows you to embed file and progress objects directly in
the QuizReport document, just pass ?include=file,progress
Quizzes API changes:
- new property (JSON): "quiz_reports_url"
- new property (JSON-API): "links.quiz_reports"
Some AMS changes:
- added support for accepting side-loading requests from controllers
by passing an :includes array to the serializer initializer
- added support for embedding objects in root, using `embed: :object
and embed_in_root: true` for has_one associations
- also, in that same scenario, AMS's default behavior is to wrap
single objects (has_one) in an array, which didn't work for me, so I
added a new option called "wrap_in_array" which you can set to false
when defining the association to override this behavior
Other changes:
- covered the front-end/javascript that utilizes the reports and
allows teachers to generate them
- QuizReport in the front-end no longer relies on magical course_id
exposed in window.ENV, but instead uses its URL to construct the
generation URL (see QuizReport#baseURL)
- Attachment now has a shallow-AMSerializer that proxies to the legacy
one in lib/api/v1 which allows us to at least side-load them
- Progress now has an AMS
- QuizReport legacy serializer in lib/api/v1 removed entirely,
replaced by the new AMS one
TEST PLAN
---- ----
Endpoint: [GET] /api/v1/courses/:course_id/quizzes/:quiz_id/reports
- as a teacher, make a request to the endpoint above:
- it should return a set of two quiz report objects
- add a parameter "includes_all_versions=true" to the query parameters
and verify that the "student_analysis" report in the returned set
now reflects the new value (the reports have a field called
"includes_all_versions" which should be true in this case, false
otherwise)
- as a student, make the request and verify that it rejects you
Endpoint: [GET] /api/v1/courses/:course_id/quizzes/:quiz_id/reports/:id
- turn on JSON-API mode
- as a teacher:
- don't generate the report from the UI yet
- make the request, and verify that you get only the report
- generate
- repeat the request, verify that you still get only the report
- add a ?include=file query parameter
- you should read the file document now
- add a ?include=progress query parameter
- you should read the progress document now
- turn off JSON-API mode
- as a teacher:
- make the request, and verify you get the "progress_url" field and
that the file document is embedded automatically without having to
specify the ?include= parameter
Front-end testing:
- go to the statistics page
- generate all reports:
- verify that the progress bar updates
- verify that you can download them
- verify that auto-download occurs unless you refresh the page
before the report is generated
- toggle on the "Count All Attempts" button and repeat the above:
- verify that Item Analysis is not generatable anymore since it's
not affected by that parameter
Please note that "item_analysis" reports will always have
"includes_all_versions" as true.
Change-Id: I0dc6d5108cbcef78b2fa17ba0476f470d33d402d
Reviewed-on: https://gerrit.instructure.com/32731
Tested-by: Jenkins <jenkins@instructure.com>
Reviewed-by: Derek DeVries <ddevries@instructure.com>
QA-Review: Caleb Guanzon <cguanzon@instructure.com>
Product-Review: Derek DeVries <ddevries@instructure.com>
2014-04-02 12:52:00 +08:00
|
|
|
end
|
|
|
|
end
|
2014-03-03 21:00:35 +08:00
|
|
|
|
|
|
|
describe "quiz_statistics" do
|
|
|
|
it "sends the url" do
|
2016-01-07 13:00:57 +08:00
|
|
|
quiz.stubs(context: Account.default.courses.new.tap { |c| c.id = 3 })
|
2014-10-14 02:04:33 +08:00
|
|
|
expect(serializer.as_json[:quiz]['links']['quiz_statistics']).to eq(
|
2014-03-03 21:00:35 +08:00
|
|
|
controller.send(:api_v1_course_quiz_statistics_url, 3, quiz.id)
|
2014-10-14 02:04:33 +08:00
|
|
|
)
|
2014-03-03 21:00:35 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "sends the url in non-JSONAPI too" do
|
|
|
|
controller.expects(:accepts_jsonapi?).at_least_once.returns false
|
2016-01-07 13:00:57 +08:00
|
|
|
quiz.stubs(context: Account.default.courses.new.tap { |c| c.id = 3 })
|
2014-10-14 02:04:33 +08:00
|
|
|
expect(serializer.as_json[:quiz][:quiz_statistics_url]).to eq(
|
2014-03-03 21:00:35 +08:00
|
|
|
controller.send(:api_v1_course_quiz_statistics_url, 3, quiz.id)
|
2014-10-14 02:04:33 +08:00
|
|
|
)
|
2014-03-03 21:00:35 +08:00
|
|
|
end
|
|
|
|
end
|
2014-03-05 00:33:05 +08:00
|
|
|
|
|
|
|
describe "submitted_students" do
|
2014-10-14 02:04:33 +08:00
|
|
|
before { skip }
|
2014-03-05 00:33:05 +08:00
|
|
|
it "sends nil if user can't grade" do
|
2016-12-06 06:06:14 +08:00
|
|
|
course_with_student(active_all: true)
|
2014-06-11 07:05:13 +08:00
|
|
|
@quiz.unstub(:check_right?)
|
2014-03-05 00:33:05 +08:00
|
|
|
@quiz.unstub(:grants_right?)
|
|
|
|
serializer = quiz_serializer(scope: @student)
|
2014-10-14 02:04:33 +08:00
|
|
|
expect(serializer.as_json[:quiz]['links']).not_to have_key 'unsubmitted_students'
|
2014-03-05 00:33:05 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "sends a url if there are submissions and user can grade" do
|
2016-12-06 06:06:14 +08:00
|
|
|
course_with_teacher(active_all: true)
|
|
|
|
course_with_student(active_all: true, course: @course)
|
2014-03-05 00:33:05 +08:00
|
|
|
quiz_with_graded_submission([], user: @student, course: @course)
|
|
|
|
serializer = quiz_serializer(scope: @teacher)
|
2014-10-14 02:04:33 +08:00
|
|
|
expect(serializer.as_json[:quiz]['links']['submitted_students']).
|
|
|
|
to eq controller.send(:api_v1_course_quiz_submission_users_url,
|
2014-03-05 00:33:05 +08:00
|
|
|
@quiz.context,
|
|
|
|
@quiz,
|
|
|
|
submitted: true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "unsubmitted_students" do
|
2014-10-14 02:04:33 +08:00
|
|
|
before { skip }
|
2014-03-05 00:33:05 +08:00
|
|
|
it "sends nil if user can't grade" do
|
2014-06-11 07:05:13 +08:00
|
|
|
@quiz.unstub(:check_right?)
|
2014-03-05 00:33:05 +08:00
|
|
|
@quiz.unstub(:grants_right?)
|
2016-12-06 06:06:14 +08:00
|
|
|
course_with_student(active_all: true)
|
2014-03-05 00:33:05 +08:00
|
|
|
serializer = quiz_serializer(scope: @student)
|
2014-10-14 02:04:33 +08:00
|
|
|
expect(serializer.as_json[:quiz]['links']).not_to have_key 'unsubmitted_students'
|
2014-03-05 00:33:05 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "sends a url if there are submissions and user can grade" do
|
2016-12-06 06:06:14 +08:00
|
|
|
course_with_teacher(active_all: true)
|
|
|
|
course_with_student(active_all: true, course: @course)
|
|
|
|
course_with_student(active_all: true, course: @course)
|
2014-03-05 00:33:05 +08:00
|
|
|
quiz_with_graded_submission([], user: @student, course: @course)
|
|
|
|
serializer = quiz_serializer(scope: @teacher)
|
2014-10-14 02:04:33 +08:00
|
|
|
expect(serializer.as_json[:quiz]['links']['unsubmitted_students']).
|
|
|
|
to eq controller.send(:api_v1_course_quiz_submission_users_url,
|
2014-03-05 00:33:05 +08:00
|
|
|
@quiz.context,
|
|
|
|
@quiz,
|
|
|
|
submitted: 'false')
|
|
|
|
end
|
|
|
|
end
|
import ActiveModel::Serializers port and convert quizzes api to it
test plan:
- The quiz api should work like it normally does when you don't pass
an 'Accept: application/vnd.api+json' header.
- The quizzes index page and quiz edit page should work like they
always do.
- Testing the Quizzes API for "jsonapi" style:
- For all requests, you MUST have the "Accept" header set to
"application/vnd.api+json"
- Test all the endpoints (PUT, POST, GET, INDEX, DELETE) like you
normally would, except you'll need to format the data according to
the next few steps:
- For "POST" and "PUT" (create and update) requests, you should send
the data like: { "quizzes": [ { id: 1, title: "blah" } ]
- For all requests (except DELETE), you should get back a response
that looks like: { "quizzes": [ { quiz you requested } ]
- For the "delete" action, you should get a "no content" response
and the request should be successful
Change-Id: Ie91deaeb6772cbe52a0fc46a28ab93a4e3036061
Reviewed-on: https://gerrit.instructure.com/25997
Reviewed-by: Jacob Fugal <jacob@instructure.com>
Tested-by: Jenkins <jenkins@instructure.com>
QA-Review: Caleb Guanzon <cguanzon@instructure.com>
Product-Review: Stanley Stuart <stanley@instructure.com>
2013-12-05 03:06:32 +08:00
|
|
|
end
|
|
|
|
|
2014-04-18 03:54:20 +08:00
|
|
|
describe "quiz_submission_html_url" do
|
|
|
|
it "includes a url to the quiz_submission html only if JSONAPI request" do
|
2014-10-14 02:04:33 +08:00
|
|
|
expect(serializer.as_json[:quiz][:quiz_submission_html_url]).to eq(
|
2014-04-18 03:54:20 +08:00
|
|
|
controller.send(:course_quiz_submission_html_url, context.id, quiz.id)
|
2014-10-14 02:04:33 +08:00
|
|
|
)
|
2014-04-18 03:54:20 +08:00
|
|
|
controller.expects(:accepts_jsonapi?).at_least_once.returns false
|
2014-10-14 02:04:33 +08:00
|
|
|
expect(serializer.as_json[:quiz]).not_to have_key :quiz_submission_html_url
|
2014-04-18 03:54:20 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-05-19 16:20:50 +08:00
|
|
|
describe "quiz_submissions_zip_url" do
|
|
|
|
it "includes a url to download all files" do
|
|
|
|
controller.expects(:accepts_jsonapi?).at_least_once.returns true
|
|
|
|
serializer.expects(:user_may_grade?).at_least_once.returns true
|
|
|
|
serializer.expects(:has_file_uploads?).at_least_once.returns true
|
2014-10-14 02:04:33 +08:00
|
|
|
expect(serializer.as_json[:quiz][:quiz_submissions_zip_url]).to eq(
|
2014-05-19 16:20:50 +08:00
|
|
|
'http://example.com/courses/1/quizzes/1/submissions?zip=1'
|
2014-10-14 02:04:33 +08:00
|
|
|
)
|
2014-05-19 16:20:50 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't if it's not a JSON-API request" do
|
|
|
|
controller.expects(:accepts_jsonapi?).at_least_once.returns false
|
|
|
|
serializer.expects(:user_may_grade?).at_least_once.returns true
|
2014-10-14 02:04:33 +08:00
|
|
|
expect(serializer.as_json[:quiz]).not_to have_key :quiz_submissions_zip_url
|
2014-05-19 16:20:50 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't if the user may not grade" do
|
|
|
|
controller.expects(:accepts_jsonapi?).at_least_once.returns true
|
|
|
|
serializer.expects(:user_may_grade?).at_least_once.returns false
|
2014-10-14 02:04:33 +08:00
|
|
|
expect(serializer.as_json[:quiz]).not_to have_key :quiz_submissions_zip_url
|
2014-05-19 16:20:50 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't if the quiz has no file upload questions" do
|
|
|
|
controller.expects(:accepts_jsonapi?).at_least_once.returns true
|
|
|
|
serializer.expects(:user_may_grade?).at_least_once.returns true
|
|
|
|
serializer.expects(:has_file_uploads?).at_least_once.returns false
|
2014-10-14 02:04:33 +08:00
|
|
|
expect(serializer.as_json[:quiz]).not_to have_key :quiz_submissions_zip_url
|
2014-05-19 16:20:50 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-01-24 00:23:26 +08:00
|
|
|
describe "permissions" do
|
|
|
|
it "serializes permissions" do
|
2014-10-14 02:04:33 +08:00
|
|
|
expect(serializer.as_json[:quiz][:permissions]).to eq({
|
2014-01-24 00:23:26 +08:00
|
|
|
read: true,
|
|
|
|
submit: true,
|
|
|
|
review_grades: true,
|
|
|
|
create: true,
|
|
|
|
update: true,
|
|
|
|
read_statistics: true,
|
QLA - Table view / answer matrix
A table view that lists all the answers to all questions with lots of
options. The view is restricted to Support SiteAdmins only.
Closes CNVS-17165
Backend/API Changes:
- QuizSubmissionEvents#index is now paginated
- Added a new account-level permission :view_quiz_answer_audits to
control the visiblity of the answer matrix. You can test this on the
quiz using "quiz.grants_right?(user, :view_answer_audits)"
Client app changes:
- Fixed a race issue when loading environment-specific config;
sometimes would cause the tests to fail because the test suite would
run before the test config was loaded
- Moved the decoration of QUESTION_ANSWERED events to a separate
module and now it is done only once at fetch-time, instead of once
per render
- Simplified a lot of book-keeping that was done in the Events store
by using query & URL parameters
- A global loading indicator prop "isLoading" which is managed by the
root route in routes/app.jsx - if you want to create a nicer loading
indicator, this would be the place to edit
- Moved all "devDependencies" into "dependencies" in package.json so
now we can just do "npm shrinkwrap" without any flags to generate
the shrinkwrap.
- grunt watch task is now smart enough to pick up the current app
we're working on. Doing `grunt server:events` will watch all the
files in /apps/events and run the test suite only for that app. :)
Doc changes:
- Defined a new JSDuck tag @seed that allows us to inspect React
components in real-time in the docs! Every @seed tag you define will
accept a JSON construct (or a file that contains JSON) and will
inject that into the rendered component, so you can show off
different states and usages in the documentation itself.
TEST PLAN
---- ----
- create a large quiz with a lot of questions and multiple attempts
- take it a few times, do many things like answering questions,
tabbing out and back in, flagging/unflagging questions, etc.
- go to the log view
+ make sure you enable the new permission for your user from the
"Manage Permissions" page in the SiteAdmin settings
+ verify you see the "View Table" button
+ click it, and verify the table works as expected
- go back to the Stream View
- click on a question link
+ in the question page, verify that the answers are rendered in a
friendly version (e.g, MultipleChoice answers are shown as radio
buttons, with the student's answer selected)
+ hop to other questions/types and verify the same thing
Change-Id: I0529b08becbf7dead86c959254faab55761db8df
Reviewed-on: https://gerrit.instructure.com/45883
Reviewed-by: Derek DeVries <ddevries@instructure.com>
Tested-by: Jenkins <jenkins@instructure.com>
QA-Review: Trevor deHaan <tdehaan@instructure.com>
Product-Review: Derek DeVries <ddevries@instructure.com>
2014-12-03 01:59:53 +08:00
|
|
|
view_answer_audits: true,
|
2014-01-24 00:23:26 +08:00
|
|
|
manage: true,
|
|
|
|
delete: true,
|
2016-07-26 03:54:11 +08:00
|
|
|
grade: true,
|
|
|
|
preview: true
|
2014-10-14 02:04:33 +08:00
|
|
|
})
|
2014-01-24 00:23:26 +08:00
|
|
|
end
|
|
|
|
end
|
2014-02-13 17:23:06 +08:00
|
|
|
|
|
|
|
it 'displays overridden dates for students' do
|
2016-12-06 06:06:14 +08:00
|
|
|
course_with_student(active_all: true)
|
2014-02-12 06:11:25 +08:00
|
|
|
course_quiz(true)
|
|
|
|
serializer = quiz_serializer(scope: @student)
|
2014-02-13 17:23:06 +08:00
|
|
|
student_overrides = {
|
|
|
|
due_at: 5.minutes.from_now,
|
|
|
|
lock_at: nil,
|
|
|
|
unlock_at: 3.minutes.from_now
|
|
|
|
}
|
|
|
|
|
2014-02-12 06:11:25 +08:00
|
|
|
serializer.stubs(:due_dates).returns [student_overrides]
|
2014-02-13 17:23:06 +08:00
|
|
|
|
|
|
|
output = serializer.as_json[:quiz]
|
2014-10-14 02:04:33 +08:00
|
|
|
expect(output).not_to have_key :all_dates
|
2014-02-13 17:23:06 +08:00
|
|
|
|
|
|
|
[ :due_at, :lock_at, :unlock_at ].each do |key|
|
2014-10-14 02:04:33 +08:00
|
|
|
expect(output[key]).to eq student_overrides[key]
|
2014-02-13 17:23:06 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'displays quiz dates for students if not overridden' do
|
2014-02-12 06:11:25 +08:00
|
|
|
student_overrides = []
|
|
|
|
|
2014-02-13 17:23:06 +08:00
|
|
|
quiz.expects(:due_at).at_least_once.returns 5.minutes.from_now
|
|
|
|
quiz.expects(:lock_at).at_least_once.returns nil
|
|
|
|
quiz.expects(:unlock_at).at_least_once.returns 3.minutes.from_now
|
2014-02-12 06:11:25 +08:00
|
|
|
serializer.stubs(:due_dates).returns student_overrides
|
2014-02-13 17:23:06 +08:00
|
|
|
|
|
|
|
output = serializer.as_json[:quiz]
|
|
|
|
|
|
|
|
[ :due_at, :lock_at, :unlock_at ].each do |key|
|
2014-10-14 02:04:33 +08:00
|
|
|
expect(output[key]).to eq quiz.send(key)
|
2014-02-13 17:23:06 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'includes all_dates for teachers and observers' do
|
|
|
|
quiz.due_at = 1.hour.from_now
|
|
|
|
|
|
|
|
teacher_overrides = [{
|
|
|
|
due_at: quiz.due_at,
|
|
|
|
lock_at: nil,
|
|
|
|
unlock_at: nil,
|
|
|
|
base: true
|
|
|
|
}, {
|
|
|
|
due_at: 30.minutes.from_now,
|
|
|
|
lock_at: 1.hour.from_now,
|
|
|
|
unlock_at: 10.minutes.from_now,
|
|
|
|
title: 'Some Section'
|
|
|
|
}]
|
|
|
|
|
|
|
|
quiz.expects(:due_at).at_least_once
|
2014-02-12 06:11:25 +08:00
|
|
|
serializer.stubs(:all_dates).returns teacher_overrides
|
|
|
|
serializer.stubs(:include_all_dates?).returns true
|
2014-02-13 17:23:06 +08:00
|
|
|
|
|
|
|
output = serializer.as_json[:quiz]
|
2014-10-14 02:04:33 +08:00
|
|
|
expect(output).to have_key :all_dates
|
|
|
|
expect(output[:all_dates].length).to eq 2
|
|
|
|
expect(output[:all_dates].detect { |e| e[:base] }).to eq teacher_overrides[0]
|
|
|
|
expect(output[:all_dates].detect { |e| !e[:base] }).to eq teacher_overrides[1]
|
|
|
|
expect(output[:due_at]).to eq quiz.due_at
|
2014-02-13 17:23:06 +08:00
|
|
|
end
|
|
|
|
|
2014-05-01 03:21:05 +08:00
|
|
|
describe "only_visible_to_overrides" do
|
|
|
|
context "as a teacher" do
|
|
|
|
before :once do
|
2016-12-06 06:06:14 +08:00
|
|
|
course_with_teacher(active_all: true)
|
2014-05-01 03:21:05 +08:00
|
|
|
course_quiz(true)
|
|
|
|
end
|
|
|
|
|
2016-02-26 23:44:19 +08:00
|
|
|
it "returns the value for DA" do
|
2014-05-01 03:21:05 +08:00
|
|
|
@quiz.only_visible_to_overrides = true
|
|
|
|
json = quiz_serializer(scope: @teacher).as_json
|
2014-10-14 02:04:33 +08:00
|
|
|
expect(json[:quiz][:only_visible_to_overrides]).to be_truthy
|
2014-05-01 03:21:05 +08:00
|
|
|
|
|
|
|
@quiz.only_visible_to_overrides = false
|
|
|
|
json = quiz_serializer(scope: @teacher).as_json
|
2014-10-14 02:04:33 +08:00
|
|
|
expect(json[:quiz]).to have_key :only_visible_to_overrides
|
|
|
|
expect(json[:quiz][:only_visible_to_overrides]).to be_falsey
|
2014-05-01 03:21:05 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "as a student" do
|
|
|
|
before :once do
|
2016-12-06 06:06:14 +08:00
|
|
|
course_with_student(active_all: true)
|
2014-05-01 03:21:05 +08:00
|
|
|
course_quiz(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "is not in the hash" do
|
|
|
|
@quiz.only_visible_to_overrides = true
|
|
|
|
json = quiz_serializer(scope: @student).as_json
|
2014-10-14 02:04:33 +08:00
|
|
|
expect(json[:quiz]).not_to have_key :only_visible_to_overrides
|
2014-05-01 03:21:05 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
import ActiveModel::Serializers port and convert quizzes api to it
test plan:
- The quiz api should work like it normally does when you don't pass
an 'Accept: application/vnd.api+json' header.
- The quizzes index page and quiz edit page should work like they
always do.
- Testing the Quizzes API for "jsonapi" style:
- For all requests, you MUST have the "Accept" header set to
"application/vnd.api+json"
- Test all the endpoints (PUT, POST, GET, INDEX, DELETE) like you
normally would, except you'll need to format the data according to
the next few steps:
- For "POST" and "PUT" (create and update) requests, you should send
the data like: { "quizzes": [ { id: 1, title: "blah" } ]
- For all requests (except DELETE), you should get back a response
that looks like: { "quizzes": [ { quiz you requested } ]
- For the "delete" action, you should get a "no content" response
and the request should be successful
Change-Id: Ie91deaeb6772cbe52a0fc46a28ab93a4e3036061
Reviewed-on: https://gerrit.instructure.com/25997
Reviewed-by: Jacob Fugal <jacob@instructure.com>
Tested-by: Jenkins <jenkins@instructure.com>
QA-Review: Caleb Guanzon <cguanzon@instructure.com>
Product-Review: Stanley Stuart <stanley@instructure.com>
2013-12-05 03:06:32 +08:00
|
|
|
end
|