Sha256: 9818c240574a881576e7df7e536bf5f2df57063f7a0c2532d4095ab926a39371

Contents?: true

Size: 1.79 KB

Versions: 1

Compression:

Stored size: 1.79 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::SailthruClient.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

1 entries across 1 versions & 1 rubygems

Version Path
sailthru-client-3.0.0 test/sailthru/file_upload_test.rb