require 'helper' describe Bearcat::Client::Accounts do before do @client = Bearcat::Client.new(prefix: "http://canvas.instructure.com", token: "test_token") end it 'returns a list of all the accounts the user belongs to' do stub_get(@client, "/api/v1/accounts").to_return(json_response("accounts.json")) accounts = @client.list_accounts accounts.count.should == 1 accounts.first['name'].should == 'Local Testing' end it 'returns a list of all of the accounts admins' do stub_get(@client, "/api/v1/accounts/1/admins").to_return(json_response("account_admins.json")) account_admins = @client.account_admins(1) account_admins.count.should == 4 account_admins.first['id'].should == 3 account_admins.last['role'].should == 'Custom Admin' end it "returns a single account" do stub_get(@client, "/api/v1/accounts/1").to_return(json_response("single_account.json")) account = @client.account(1) account["id"].should == 1 account["name"].should == "Local Testing" end it "returns enrollment terms for an account" do stub_get(@client, "/api/v1/accounts/1/terms").to_return(json_response("enrollment_terms.json")) account = @client.terms(1) terms = account.members terms.count.should == 1 terms.first['id'].should == 4 terms.first['name'].should == 'Term 1' end it "returns the roles for an account" do stub_get(@client, "/api/v1/accounts/1/roles").to_return(json_response("account_roles.json")) account = @client.account_roles(1) roles = account.members roles.count.should == 1 roles.first['id'].should == 1 roles.first['role'].should == 'AccountAdmin' roles.first['permissions'].count.should == 4 roles.first['permissions']['manage_catalog']['enabled'].should == true end it 'returns courses for an account' do stub_get(@client, "/api/v1/accounts/1/courses").to_return(json_response("account_courses.json")) courses = @client.account_courses(1) courses.count.should == 2 courses.first['id'].should == 1 courses.first['name'].should == 'Sub1 Course1' end it 'gets account grading_standards' do stub_get(@client, "/api/v1/accounts/1/grading_standards").to_return(json_response("account_grading_standards.json")) grading_standards = @client.account_grading_standards(1) expect(grading_standards['id']).to eq 1 expect(grading_standards['title']).to eq 'account grading scheme' end it 'creates an account admin' do stub_post(@client, "/api/v1/accounts/1/admins").to_return(json_response("account_admin_create.json")) account_admin = @client.create_account_admin(1, {role_id:1, user_id: "sis_user_id:user1_sis_id"}) expect(account_admin['id']).to eq 99 expect(account_admin['role']).to eq 'AccountAdmin' end it 'deletes an account admin' do stub_delete(@client, "/api/v1/accounts/1/admins/sis_user_id:user1_sis_id?role_id=1").to_return(json_response("account_admin_delete.json")) account_admin = @client.delete_account_admin(1, "sis_user_id:user1_sis_id", {role_id:1}) expect(account_admin['id']).to eq 99 expect(account_admin['status']).to eq 'deleted' end it 'returns a list of sis_imports' do stub_get(@client, "/api/v1/accounts/1/sis_imports").to_return(json_response("account_sis_imports.json")) sis_imports = @client.account_sis_imports(1)['sis_imports'] expect(sis_imports.first['id']).to eq 30 expect(sis_imports.first['workflow_state']).to eq 'imported' end end