require 'helper' describe Bearcat::Client::ContentMigrations do before do @client = Bearcat::Client.new(prefix: "http://canvas.instructure.com", token: "test_token") end it 'uploads a file' do stub_post(@client, "/my/upload/path"). to_return(json_response('content_migration_files/response.json')) stub_request(:post, "http://host/files_api"). to_return(status: 302, headers: {'Location' => 'https://confirm-upload.invalid/confirm?param=true'}) stub_get(@client, '/confirm').with(:query => {"param" => ["true"]}).to_return(json_response('content_migration_files/upload_success.json')) opts = {migration_type: 'canvas_cartridge_importer', pre_attachment: {name: 'cc.imscc', size: '2034'}} response = @client.upload_content_package('my/upload/path', fixture('cc.imscc'), opts) expect(response['id']).to eq 293 end describe 'get_group_content_migration' do it "gets a content_migration" do stub_get(@client, "/api/v1/accounts/3/content_migrations/1").to_return(json_response("content_migration_files/content_migration.json")) account = @client.get_account_content_migration(3, 1) account['migration_type'].should == 'common_cartridge_importer' account['migration_type_title'].should == "Canvas Cartridge Importer" end end describe 'get_course_content_migration' do it "gets a content_migration" do stub_get(@client, "/api/v1/courses/3/content_migrations/1").to_return(json_response("content_migration_files/content_migration.json")) course = @client.get_course_content_migration(3, 1) course['migration_type'].should == 'common_cartridge_importer' course['migration_type_title'].should == "Canvas Cartridge Importer" end end describe 'get_group_content_migration' do it "gets a content_migration" do stub_get(@client, "/api/v1/groups/3/content_migrations/1").to_return(json_response("content_migration_files/content_migration.json")) group = @client.get_group_content_migration(3, 1) group['migration_type'].should == 'common_cartridge_importer' group['migration_type_title'].should == "Canvas Cartridge Importer" end end describe 'get_user_content_migration' do it "gets a content_migration" do stub_get(@client, "/api/v1/users/3/content_migrations/1").to_return(json_response("content_migration_files/content_migration.json")) user = @client.get_user_content_migration(3, 1) user['migration_type'].should == 'common_cartridge_importer' user['migration_type_title'].should == "Canvas Cartridge Importer" end end describe 'create_account_content_migration' do it "creates a account migration" do stub_post(@client, "/api/v1/accounts/3/content_migrations").to_return(json_response('content_migration_files/content_migration.json')) account = @client.create_account_content_migration(3) account['migration_type'].should == 'common_cartridge_importer' account['migration_type_title'].should == "Canvas Cartridge Importer" end end describe 'create_course_content_migration' do it "creates a course migration" do stub_post(@client, "/api/v1/courses/3/content_migrations").to_return(json_response('content_migration_files/content_migration.json')) course = @client.create_course_content_migration(3) course['migration_type'].should == 'common_cartridge_importer' course['migration_type_title'].should == "Canvas Cartridge Importer" end end describe 'create_group_content_migration' do it "creates a group migration" do stub_post(@client, "/api/v1/groups/3/content_migrations").to_return(json_response('content_migration_files/content_migration.json')) group = @client.create_group_content_migration(3) group['migration_type'].should == 'common_cartridge_importer' group['migration_type_title'].should == "Canvas Cartridge Importer" end end describe 'create_user_content_migration' do it "creates a user migration" do stub_post(@client, "/api/v1/users/3/content_migrations").to_return(json_response('content_migration_files/content_migration.json')) user = @client.create_user_content_migration(3) user['migration_type'].should == 'common_cartridge_importer' user['migration_type_title'].should == "Canvas Cartridge Importer" end end end