Sha256: d2a91d034b40e5b698d295e1872e93cea7683b162f8bf1d47cb1e72c3f9fbb0e

Contents?: true

Size: 1.28 KB

Versions: 1

Compression:

Stored size: 1.28 KB

Contents

require 'helper'

describe Bearcat::Client::CanvasFiles 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").
      with(:body => {"name" => "bearcat.jpg", "size" => "121363"}).
      to_return(json_response('canvas_files', 'declare_file.json'))

    stub_request(:post, "https://upload-url.invalid/").
      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('canvas_files', 'upload_success.json'))

    response = @client.upload_file('my/upload/path', fixture('bearcat.jpg'))
    expect(response['id']).to eq 123
  end

  it 'throws an error on a failed file upload' do
    stub_post(@client, "/my/upload/path").
      with(:body => {"name" => "bearcat.jpg", "size" => "121363"}).
      to_return(json_response('canvas_files', 'declare_file.json'))

    stub_request(:post, "https://upload-url.invalid/").
      to_return(status: 400, headers: {'Location' => 'https://confirm-upload.invalid/confirm?param=true'})

    expect { @client.upload_file('my/upload/path', fixture('bearcat.jpg')) }.to raise_exception
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
bearcat-1.4.13 spec/bearcat/client/canvas_files_spec.rb