require 'helper'

describe Bearcat::Client::GroupCategories do
  before do
    @client = Bearcat::Client.new(prefix: "http://canvas.instructure.com", token: "test_token")
  end

  it "returns group categories" do
    stub_get(@client, "/api/v1/courses/1809/group_categories").to_return(json_response("group_categories.json"))
    categories = @client.list_group_categories('courses', 1809)
    categories.count.should == 2
    categories.first['name'].should == 'mark red'
    categories.last['name'].should == 'test group'
  end

  it 'returns a single group category' do
    stub_get(@client, "/api/v1/group_categories/2").to_return(json_response("group_category.json"))
    category = @client.group_category(2)
    category['name'].should == 'mark red'
    category['id'].should == 5
  end

  it 'creates a new group category' do
    name = "new group category"
    stub_post(@client, "/api/v1/courses/1/group_categories").with(body: {"name" => name}).to_return(json_response("created_group_category.json"))
    group_category = @client.create_group_category('courses', 1, { name: name })
    group_category["name"].should == name
    group_category["id"].should == 1
  end

end