Sha256: 56d684e827803cd627319a873d01f77edac696042add3a127a15ab1d2bcb7277

Contents?: true

Size: 1.78 KB

Versions: 6

Compression:

Stored size: 1.78 KB

Contents

require 'test_helper'
require 'mocha/setup'

class FileUploadTest < Minitest::Test

  describe "API Call: blast" do

    before do
      @secret = 'my_secret'
      @api_key = 'my_api_key'
      @sailthru_client = Sailthru::Client.new(
        @api_key, @secret, 'http://api.sailthru.com'
      )
      @api_call_url = sailthru_api_call_url(
        'http://api.sailthru.com', 'job'
      )
    end

    it "can upload a file of data" do
      Net::HTTP::Post::Multipart.expects(:new).with(
          instance_of(String),
          has_entries({
            "file" => instance_of(UploadIO)
          })
        )
      Net::HTTP.stubs(:Proxy).returns(Net::HTTP)
      Net::HTTP.any_instance.stubs(
          :request => stub(
            "body" => JSON.unparse({"job_id" => "123"})
          )
        )

      data = {
        "job" => "update",
        "file" => fixture_file_path('user_update_post_valid.json')
      }
      response = @sailthru_client.api_post(
        :job, data, 'file'
      )
      refute_nil response['job_id']
    end

    it "can upload a string of data" do
      Net::HTTP::Post::Multipart.expects(:new).with(
          instance_of(String),
          has_entries({
            "file" => instance_of(UploadIO)
          })
        )
      Net::HTTP.stubs(:Proxy).returns(Net::HTTP)
      Net::HTTP.any_instance.stubs(
          :request => stub(
            "body" => JSON.unparse({"job_id" => "123"})
          )
        )

      email = {
        "email" => "dan.langevin@lifebooker.com",
        "vars" => {
          "first_name" => "Dan"
        }
      }
      data = {
        "job" => "update",
        "file" => StringIO.new(JSON.unparse(email))
      }

      response = @sailthru_client.api_post(
        :job, data, 'file'
      )
      refute_nil response['job_id']
    end

  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
sailthru-client-4.0.7 test/sailthru/file_upload_test.rb
sailthru-client-4.0.6 test/sailthru/file_upload_test.rb
sailthru-client-4.0.3 test/sailthru/file_upload_test.rb
sailthru-client-4.0.2 test/sailthru/file_upload_test.rb
sailthru-client-4.0.1 test/sailthru/file_upload_test.rb
sailthru-client-4.0.0 test/sailthru/file_upload_test.rb