require 'helper' describe Bearcat::Client::Submissions do before do @client = Bearcat::Client.new(prefix:"http://canvas.instructure.com", token: "test_token") end it "returns all submissions for a course" do stub_get(@client, "/api/v1/courses/3/students/submissions").to_return(json_response('submissions', "submission.json")) submissions = @client.course_submissions(3) submissions['assignment_id'].should == 2353405 submissions['id'].should == 8444510 submissions['score'].should == 1 submissions['grade'].should == '1' submissions['user_id'].should == 682285 submissions['workflow_state'].should =='unsubmitted' submissions['late'].should == false submissions['preview_url'].should =='https://canvas.instructure.com/courses/218274/assignments/2353405/submissions/682285?preview=1' submissions['workflow_state'].should =='unsubmitted' submissions['workflow_state'].should =='unsubmitted' submissions['workflow_state'].should =='unsubmitted' end it "returns all submissions for a course, user, submission" do stub_get(@client, "/api/v1/courses/3/assignments/2353405/submissions/682285").to_return(json_response('submissions', "submission.json")) submissions = @client.user_course_assignment_submission(3, 2353405, 682285) submissions['assignment_id'].should == 2353405 submissions['id'].should == 8444510 submissions['score'].should == 1 submissions['grade'].should == '1' submissions['user_id'].should == 682285 submissions['workflow_state'].should =='unsubmitted' submissions['late'].should == false submissions['preview_url'].should =='https://canvas.instructure.com/courses/218274/assignments/2353405/submissions/682285?preview=1' submissions['workflow_state'].should =='unsubmitted' submissions['workflow_state'].should =='unsubmitted' submissions['workflow_state'].should =='unsubmitted' end context 'course' do it "submits a file" do @client.stub(:upload_file).and_return({}) stub_post(@client, '/api/v1/courses/1/assignments/2/submissions').to_return(json_response('submissions', 'submission.json')) response = @client.course_file_upload_submission(1, 2, 3, fixture('bearcat.jpg')) response['id'].should == 8444510 end it "submits multiple files" do @client.stub(:upload_file).and_return({}) stub_post(@client, '/api/v1/courses/1/assignments/2/submissions').to_return(json_response('submissions', 'submission.json')) response = @client.course_file_upload_submission(1, 2, 3, [fixture('bearcat.jpg'), fixture('file.csv')]) response['id'].should == 8444510 end it "updates grades" do params = {"grade_data[123]" => "19"} stub_post(@client, "/api/v1/courses/1/assignments/1/submissions/update_grades").with(body: {"grade_data"=>["19"]}).to_return(json_response("progress.json")) response = @client.course_update_grades(1, 1, params) expect(response['user_id']).to eq 123 expect(response['workflow_state']).to eq 'completed' end end context 'section' do it "submits a file" do @client.stub(:upload_file).and_return({}) stub_post(@client, '/api/v1/sections/1/assignments/2/submissions').to_return(json_response('submissions', 'submission.json')) response = @client.section_file_upload_submission(1, 2, 3, [fixture('bearcat.jpg'), fixture('file.csv')]) response['id'].should == 8444510 end it "submits multiple files" do @client.stub(:upload_file).and_return({}) stub_post(@client, '/api/v1/sections/1/assignments/2/submissions').to_return(json_response('submissions', 'submission.json')) response = @client.section_file_upload_submission(1, 2, 3, fixture('bearcat.jpg')) response['id'].should == 8444510 end it "updates grades" do params = {"grade_data[123]" => "19"} stub_post(@client, "/api/v1/sections/9/assignments/1/submissions/update_grades").with(body: {"grade_data"=>["19"]}).to_return(json_response("progress.json")) response = @client.section_update_grades(9, 1, params) expect(response['user_id']).to eq 123 expect(response['workflow_state']).to eq 'completed' end end end