require 'helper' describe Bearcat::Client::Groups do before do @client = Bearcat::Client.new(prefix: "http://canvas.instructure.com", token: "test_token") end it "returns course groups" do stub_get(@client, "/api/v1/courses/1/groups").to_return(json_response("course_groups.json")) groups = @client.course_groups(1) groups.count.should == 2 groups.first['name'].should == 'group 1' groups.last['id'].should == 4 end it "returns account groups" do stub_get(@client, "/api/v1/accounts/1/groups").to_return(json_response("account_groups.json")) groups = @client.account_groups(1) groups.count.should == 2 groups.first['name'].should == '2010' groups.last['id'].should == 3 end it "returns group category groups" do stub_get(@client, "/api/v1/group_categories/1/groups").to_return(json_response("group_category_groups.json")) groups = @client.category_groups(1) groups.count.should == 1 groups.first['name'].should == 'test group in category' groups.first['id'].should == 94 end it "returns a single group" do stub_get(@client, "/api/v1/groups/3").to_return(json_response("group.json")) group = @client.group(3) group['name'].should == 'group 1' group['id'].should == 3 end it "creates a group" do name = 'created group 1' stub_post(@client, "/api/v1/group_categories/2/groups").with(body: { name: name }).to_return(json_response("created_group.json")) created_group = @client.create_group(2, { name: name }) created_group['name'] == 'created group 1' created_group['context_type'] == 'Course' created_group['group_category']['id'] == 2 end it "edits a group" do name = 'edited group 1' description = 'edited group 1 description' stub_put(@client, "/api/v1/groups/1").with(body: { name: name, description: description }).to_return(json_response("edited_group.json")) edited_group = @client.edit_group(1, { name: name, description: description }) edited_group['name'] == name edited_group['description'] == description end it 'deleted a group' do stub_delete(@client, "/api/v1/groups/7").to_return(json_response("deleted_group.json")) deleted_group = @client.delete_group(7) deleted_group['id'] == 7 end end