require 'helper' describe Bearcat::Client::Assignments do before do @client = Bearcat::Client.new(prefix: "http://canvas.instructure.com", token: "test_token") end it "returns all assignments for a course" do stub_get(@client, "/api/v1/courses/3/assignments").to_return(json_response("assignments.json")) assignments = @client.assignments(3) assignments.count.should == 2 assignments.first["assignment_group_id"].should == 53 assignments.first["id"].should == 123 assignments.first["due_at"].should == nil end it "returns an individual assignment for a course" do stub_get(@client, "/api/v1/courses/3/assignments/1").to_return(json_response("assignment.json")) assignment = @client.assignment(3, 1) assignment["assignment_group_id"].should == 53 assignment["id"].should == 1 assignment["due_at"].should == nil end it "creates an assignment override for a section" do stub_post(@client, "/api/v1/courses/310/assignments/123/overrides") .with(:body => {"assignment_override"=>{"course_section_id"=>"74", "due_at"=>"2013-06-27T21:08:46Z"}}) .to_return(json_response("assignment_section_override.json")) override = @client.create_assignment_override(310, 123, { "assignment_override[course_section_id]" => 74, "assignment_override[due_at]" => "2013-06-27T21:08:46Z" }) override["all_day"].should == false override["due_at"].should == "2013-06-27T15:08:46-06:00" override["id"].should == 1 override["course_section_id"].should == 74 end it "deletes assignment overrides" do stub_delete(@client, "/api/v1/courses/3/assignments/1/overrides/2").to_return({}) @client.delete_assignment_override(3, 1, 2) end it "creates a new assignment" do name = "new assignment" stub_post(@client, "/api/v1/courses/1/assignments").with(body: {"assignment" => {"name" => name}}).to_return(json_response("created_assignment.json")) assignment = @client.create_assignment(1, {"assignment" => {"name" => name}}) assignment["name"].should == name assignment["id"].should == 1 end it "deletes an assignment" do stub_delete(@client, "/api/v1/courses/3/assignments/1").to_return(json_response("assignment.json")) assignment = @client.delete_assignment(3, 1) assignment["id"].should == 1 end it "allows batch retrieval of all overrides in a course" do stub_get(@client, "/api/v1/courses/3/assignments/overrides").to_return(json_response("assignment_section_override.json")) @client.all_assignment_overrides(3) end it "allows batch creation of assignment overrides" do stub_post(@client, "/api/v1/courses/310/assignments/overrides") .with(:body => {"assignment_override"=>{"course_section_id"=>"74", "due_at"=>"2013-06-27T21:08:46Z"}}) .to_return(json_response("assignment_section_override.json")) @client.batch_create_assignment_overrides(310, { "assignment_override[course_section_id]" => 74, "assignment_override[due_at]" => "2013-06-27T21:08:46Z" }) end it "allows batch updating of assignment overrides" do stub_put(@client, "/api/v1/courses/310/assignments/overrides") .with(:body => {"assignment_override"=>{"course_section_id"=>"74", "due_at"=>"2013-06-27T21:08:46Z"}}) .to_return(json_response("assignment_section_override.json")) @client.batch_update_assignment_overrides(310, { "assignment_override[course_section_id]" => 74, "assignment_override[due_at]" => "2013-06-27T21:08:46Z" }) end end