require 'helper' describe Bearcat::Client::Quizzes do before do @client = Bearcat::Client.new(prefix: "http://canvas.instructure.com", token: "test_token") end it "updates a single quiz" do stub_put(@client, "/api/v1/courses/1/quizzes/38").to_return(json_response("quizzes/course_quiz.json")) course_quiz = @client.edit_quiz('1', '38') course_quiz.class.should eq(Hash) course_quiz['id'].should == 38 end it "returns a courses quizzes" do stub_get(@client, "/api/v1/courses/1/quizzes").to_return(json_response("quizzes/course_quizzes.json")) course_quizzes = @client.list_course_quizzes('1') course_quizzes.class.should eq(Bearcat::ApiArray) course_quizzes.count.should == 2 course_quizzes.first['id'].should == 37 course_quizzes.last['id'].should == 38 end it "returns a single quiz" do stub_get(@client, "/api/v1/courses/1/quizzes/38").to_return(json_response("quizzes/course_quiz.json")) course_quiz = @client.quiz('1', '38') course_quiz.class.should eq(Hash) course_quiz['id'].should == 38 end it 'sets extensions on a quiz' do stub_post(@client, "/api/v1/courses/1/quizzes/1/extensions").to_return(json_response("quizzes/quiz_extension.json")) quiz_extension = @client.quiz_extensions('1', '1', {quiz_extensions: [{user_id: 1}, {extra_time: 30}]}) quiz_extension.class.should eq(Hash) quiz_extension['quiz_extensions'].first['extra_time'].should eq(30) end it 'returns a quiz assignment override' do stub_get(@client, "/api/v1/courses/1/quizzes/assignment_overrides?quiz_assignment_overrides%5B%5D%5Bquiz_ids%5D=13").to_return(json_response("quizzes/quiz_assignment_override.json")) quiz_overrides = @client.quiz_assignment_overrides('1',{:quiz_assignment_overrides => [{ :quiz_ids => 13 }] }) quiz_overrides.class.should eq(Hash) quiz_overrides['quiz_assignment_overrides'].first['quiz_id'].should eq(1014) end it 'creates a new quiz' do name = "test quiz" stub_post(@client, "/api/v1/courses/1/quizzes").with(body: {"quiz" => {"title" => name}}).to_return(json_response("quizzes/course_quiz.json")) quiz = @client.create_quiz(1, {"quiz" => {"title" => name}}) quiz["title"].should == 'Second Quiz' quiz["id"].should == 38 end it 'returns quiz questions' do stub_get(@client, "/api/v1/courses/1/quizzes/1/questions").to_return(json_response("quizzes/course_quiz_questions.json")) course_quiz_questions = @client.quiz_questions('1', '1') course_quiz_questions.class.should eq(Bearcat::ApiArray) course_quiz_questions.count.should == 1 course_quiz_questions[0].class.should eq(Hash) course_quiz_questions[0]['id'].should == 1 end end