require 'helper' describe Bearcat::Client::Discussions do before do @client = Bearcat::Client.new(prefix: "http://canvas.instructure.com", token: "test_token") end it "creates a new group discussion" do title = "This is a group discussion" stub_post(@client, "/api/v1/groups/2/discussion_topics").with(body: {"title" => title}).to_return(json_response("create_group_discussion.json")) discussion = @client.create_group_discussion(2, {'title' => title}) discussion['title'].should == 'This is a group discussion' end it 'creates a new course discussion' do title = "This is a course discussion" stub_post(@client, "/api/v1/courses/2/discussion_topics").with(body: {"title" => title}).to_return(json_response("create_course_discussion.json")) discussion = @client.create_course_discussion(2, {'title' => title}) discussion['title'].should == 'This is a course discussion' end it 'returns course discussion topics' do stub_get(@client, "/api/v1/courses/1/discussion_topics").to_return(json_response("discussion_topics.json")) discussions = @client.course_discussions('1') discussions.class.should eq(Bearcat::ApiArray) discussions.count.should == 1 discussions[0].class.should eq(Hash) discussions[0]['id'].should == 1 end it 'returns group discussion topics' do stub_get(@client, "/api/v1/groups/1/discussion_topics").to_return(json_response("discussion_topics.json")) discussions = @client.group_discussions('1') discussions.class.should eq(Bearcat::ApiArray) discussions.count.should == 1 discussions[0].class.should eq(Hash) discussions[0]['id'].should == 1 end it 'returns course discussion entries' do stub_get(@client, "/api/v1/courses/1/discussion_topics/1/entries").to_return(json_response("discussion_entries.json")) discussions = @client.course_discussion_entries('1', '1') discussions.class.should eq(Bearcat::ApiArray) discussions.count.should == 1 discussions[0].class.should eq(Hash) discussions[0]['id'].should == 1 end it 'returns group discussion entries' do stub_get(@client, "/api/v1/groups/1/discussion_topics/1/entries").to_return(json_response("discussion_entries.json")) discussions = @client.group_discussion_entries('1', '1') discussions.class.should eq(Bearcat::ApiArray) discussions.count.should == 1 discussions[0].class.should eq(Hash) discussions[0]['id'].should == 1 end end