require 'helper' describe Bearcat::Client::Modules do before do @client = Bearcat::Client.new(prefix: "http://canvas.instructure.com", token: "test_token") end it "returns course modules" do stub_get(@client, "/api/v1/courses/1/modules").to_return(json_response("modules.json")) modules = @client.course_modules(1) modules.count.should == 3 modules.first['id'].should == 1 end it "returns a course items module sequence" do query = {"asset_type" => "assignment", "asset_id" => '22'} stub_get(@client, "/api/v1/courses/1/module_item_sequence").with(query: query).to_return(json_response("module_item_sequence.json")) item_sequence = @client.course_module_item_sequence("1", query) items = item_sequence["modules"] items.count.should == 3 items.last["id"].should == 3 end describe "#course_module" do it "returns a course module" do stub_get(@client, "/api/v1/courses/1/modules/2").to_return(json_response("module.json")) context_module = @client.course_module(1, 2) expect(context_module['id']).to eq(2) end end describe "#create_module" do it "creates a new module" do name = "new module" stub_request(:post, "http://canvas.instructure.com/api/v1/courses/1/modules") .with(body: {"name"=> name}) .to_return(json_response("created_module.json")) course_module = @client.create_module(1, { name: name }) course_module["name"].should == name course_module["id"].should == 1 end end describe "#update_module" do it "updates a module" do stub_request(:put, "http://canvas.instructure.com/api/v1/courses/3/modules/2") .to_return(json_response("module.json")) updated_module = @client.update_module(3, 2, {}) expect(updated_module['name']).to eq("Second Module") expect(updated_module['id']).to eq(2) end end describe "#delete_module" do it "deletes a module" do stub_delete(@client, "/api/v1/courses/3/modules/2").to_return(json_response("module.json")) course_module = @client.delete_module(3, 2) expect(course_module["id"]).to eq(2) end end end