require 'helper' describe Bearcat::Client::Sections do before do @client = Bearcat::Client.new(prefix:"http://canvas.instructure.com", token: "test_token") end it "returns all sections for a course" do stub_get(@client, "/api/v1/courses/3/sections").to_return(json_response("course_sections.json")) sections = @client.course_sections(3) expect(sections.first['name']).to eq('test') expect(sections.first['id']).to eq(70) expect(sections.first['course_id']).to eq(3) end it "returns a section" do stub_get(@client, "/api/v1/sections/72").to_return(json_response("section.json")) section = @client.section(72) expect(section['name']).to eq('Section003') expect(section['id']).to eq(72) expect(section['course_id']).to eq(3) end it "creates a section" do stub_post(@client, "/api/v1/courses/3/sections"). with(:body => {"course_section"=>{"name"=>"Section003"}}).to_return(json_response("create_section.json")) section = @client.create_section(3, {"course_section[name]" => "Section003"}) expect(section['course_id']).to eq(3) expect(section['id']).to eq(72) expect(section['name']).to eq('Section003') end it "updates a section" do stub_put(@client, "/api/v1/sections/72").with(:body => {"course_section"=>{"name"=>"Section003"}}).to_return(json_response("update_section.json")) section = @client.update_section(72, {"course_section[name]" => "Section003"}) expect(section['course_id']).to eq(3) expect(section['id']).to eq(72) expect(section['name']).to eq('Section003') end it "deletes a section" do stub_delete(@client, "/api/v1/sections/72").to_return(json_response("update_section.json")) section = @client.delete_section(72) expect(section['course_id']).to eq(3) expect(section['id']).to eq(72) expect(section['name']).to eq('Section003') end end