require 'helper' describe Bearcat::Client::CustomGradebookColumns do before do @client = Bearcat::Client.new(prefix:"http://canvas.instructure.com", token: "test_token") end context 'custom_gradebook_columns' do it "lists custom gradebook columns" do stub_get(@client, '/api/v1/courses/1/custom_gradebook_columns').to_return(json_response('custom_gradebook_columns', 'custom_gradebook_columns.json')) response = @client.custom_gradebook_columns(1) response.first['id'].should == 1 response.last['id'].should == 2 end it "creates custom gradebook column" do params = {"title": "Third", "position": 3, "hidden": false} stub_post(@client, '/api/v1/courses/1/custom_gradebook_columns').to_return(json_response('custom_gradebook_columns', 'custom_gradebook_column.json')) response = @client.create_gradebook_columns(1, params) expect(response['id']).to eq 3 expect(response['title']).to eq 'Third' end it "deletes custom gradebook column" do stub_delete(@client, '/api/v1/courses/1/custom_gradebook_columns/3').to_return(json_response('custom_gradebook_columns', 'custom_gradebook_column.json')) response = @client.delete_gradebook_columns(1, 3) expect(response['id']).to eq 3 expect(response['title']).to eq 'Third' end end context 'custom_gradebook_column_data' do it "lists data for custom gradebook column" do stub_get(@client, '/api/v1/courses/1/custom_gradebook_columns/1/data').to_return(json_response('custom_gradebook_columns', 'column_data.json')) response = @client.gradebook_columns_data(1, 1) response['content'].should == 'Nut allergy' response['user_id'].should == 1 end it "lists data for custom gradebook column" do params = {"content": "Nut allergy", "user_id": 1} stub_put(@client, '/api/v1/courses/1/custom_gradebook_columns/1/data/1').to_return(json_response('custom_gradebook_columns', 'column_data.json')) response = @client.update_gradebook_columns_data(1, 1, 1, params) response['content'].should == 'Nut allergy' response['user_id'].should == 1 end end context 'update_gradebook_columns_data' do it 'bulk updates gradebook columns data' do params = {'column_data': [ { 'column_id': 1, 'user_id': 2, 'content': 'user2 content' }, { 'column_id': 1, 'user_id': 3, 'content': 'user3 content' } ]} stub_put(@client, '/api/v1/courses/1/custom_gradebook_column_data').to_return(json_response('custom_gradebook_columns', 'gradebook_column_progress.json')) response = @client.bulk_update_gradebook_columns_data(1, params) expect(response['context_id']).to eq 1 end end end