require 'helper' describe Bearcat::Client::ModuleItems do before do @client = Bearcat::Client.new(prefix: "http://canvas.instructure.com", token: "test_token") end it 'returns all items for a module' do stub_get(@client, '/api/v1/courses/1/modules/1/items').to_return(json_response('module_items.json')) items = @client.list_module_items(1,1) items.count.should == 3 items.members[0]['id'].should == 1358 items.members[0]['type'].should == 'Page' end describe '#module_item' do it 'returns a module' do stub_get(@client, '/api/v1/courses/1/modules/1/items/2').to_return(json_response('module_item.json')) item = @client.module_item(1, 1, 2) expect(item['id']).to eq(2) end end describe '#create_module_item' do it 'creates a module item' do params = { module_item: { title: 'Test Page', content_id: '1-dot-1-intro-to-disease', type: 'Page' }} stub_request(:post, "http://canvas.instructure.com/api/v1/courses/1/modules/1/items") .with(body: params) .to_return(json_response("module_item.json")) module_item = @client.create_module_item(1, 1, params) expect(module_item['title']).to eq('Test Page') expect(module_item['page_url']).to eq('1-dot-1-intro-to-disease') end end describe '#update_module_item' do it 'updates a module item' do params = { module_item: { title: 'Test Page', content_id: '1-dot-1-intro-to-disease', type: 'Page' }} stub_request(:put, "http://canvas.instructure.com/api/v1/courses/1/modules/1/items/2") .with(body: params) .to_return(json_response("module_item.json")) module_item = @client.update_module_item(1, 1, 2, params) expect(module_item['title']).to eq('Test Page') expect(module_item['page_url']).to eq('1-dot-1-intro-to-disease') end end describe '#delete_module_item' do it 'deletes a module item' do stub_request(:delete, "http://canvas.instructure.com/api/v1/courses/1/modules/1/items/2") .to_return(json_response('module_item.json')) module_item = @client.delete_module_item(1, 1, 2) expect(module_item["id"]).to eq(2) end end end