require 'helper' describe Bearcat::Client::Enrollments do before do @client = Bearcat::Client.new(prefix:"http://canvas.instructure.com", token: "test_token") end it "returns all enrollments for a user" do stub_get(@client, "/api/v1/users/1/enrollments").to_return(json_response("user_enrollments.json")) enrollments = @client.user_enrollments(1) enrollments.first['course_id'].should == 3 enrollments.first['course_section_id'].should == 70 enrollments.first['id'].should == 2 enrollments.first['user']['id'].should == 1 enrollments.first['user']['name'].should == 'test@instructure.com' end it "returns all enrollments for a course" do stub_get(@client, "/api/v1/courses/1/enrollments").to_return(json_response("course_enrollments.json")) enrollments = @client.course_enrollments(1) enrollments.first['course_id'].should == 9 enrollments.first['course_section_id'].should == 11 enrollments.first['id'].should == 27 enrollments.first['user']['id'].should == 7 enrollments.first['user']['name'].should == 'User 1' end it "returns all enrollments for a section" do stub_get(@client, "/api/v1/sections/1/enrollments").to_return(json_response("section_enrollments.json")) enrollments = @client.section_enrollments(1) enrollments.first['course_id'].should == 2 enrollments.first['course_section_id'].should == 2 enrollments.first['id'].should == 6 enrollments.first['user']['id'].should == 8 enrollments.first['user']['name'].should == 'User 2' end it "enrolls a student in a section" do stub_post(@client, "/api/v1/sections/70/enrollments") .with(:body => {"enrollment"=>{"user_id"=>"1", "type"=>"StudentEnrollment"}}) .to_return(json_response("enroll_student.json")) enrollment = @client.enroll_in_section(70, {"enrollment[user_id]" => 1, "enrollment[type]" => "StudentEnrollment"}) enrollment["course_id"].should == 3 enrollment["course_section_id"].should == 70 enrollment["id"].should == 1386 enrollment["role"].should == "StudentEnrollment" enrollment["enrollment_state"].should == "invited" end it "enrolls a student in a course" do stub_post(@client, "/api/v1/courses/3/enrollments") .with(:body => {"enrollment"=>{"user_id"=>"1", "type"=>"StudentEnrollment"}}) .to_return(json_response("enroll_student.json")) enrollment = @client.enroll_in_course(3, {"enrollment[user_id]" => 1, "enrollment[type]" => "StudentEnrollment"}) enrollment["course_id"].should == 3 enrollment["course_section_id"].should == 70 enrollment["id"].should == 1386 enrollment["role"].should == "StudentEnrollment" enrollment["enrollment_state"].should == "invited" end it "concludes a students enrollment" do stub_request(:delete, "http://canvas.instructure.com/api/v1/courses/3/enrollments/1386?task=conclude").to_return(json_response("conclude_enrollment.json")) enrollment = @client.conclude_enrollment(3, 1386, {"task" => "conclude"}) enrollment["course_id"].should == 3 enrollment["course_section_id"].should == 70 enrollment["id"].should == 1386 enrollment["role"].should == "StudentEnrollment" enrollment["enrollment_state"].should == "completed" end end