Sha256: 1d8745a64f18ee83ebe470b7a33efdc693c54e1be5d03fde3a4edc98d0d296e0

Contents?: true

Size: 1.78 KB

Versions: 2

Compression:

Stored size: 1.78 KB

Contents

require "slidepay"
require "spec_helper"

def example_search_filter
  return { field: "created", condition: "equals", value: "12/01/2013"}
end

describe SlidePay::Report do
  it "should accept an array on instantiation" do
    b = SlidePay::Report.new([])
    expect(b.sfa).to eq([])
  end

  it "should accept a hash on instantiation" do
    b = SlidePay::Report.new(example_search_filter)
    expect(b.sfa).to eq([example_search_filter])
  end

  describe "retrieve" do
    it "should make a put request if report_type is :put" do
      b = SlidePay::Report.new(example_search_filter)
      b.report_type = :put

      SlidePay.should_receive(:put).and_return(a_response_object)
      b.retrieve()
    end

    it "should make a post request if report_type is :post" do
      b = SlidePay::Report.new(example_search_filter)
      b.report_type = :post

      SlidePay.should_receive(:post).and_return(a_response_object)
      b.retrieve()
    end

    it "should pass the report url and search filter array to the request method" do
      b = SlidePay::Report.new(example_search_filter)
      b.report_type = :put
      b.url = "EXAMPLE_URL"

      retrieve_params = { path: "EXAMPLE_URL", data: [example_search_filter].to_json, token: nil, api_key: nil, endpoint: nil }

      SlidePay.should_receive(:put).with(retrieve_params).and_return(a_response_object)
      b.retrieve()
    end

    it "should populate the report object from the response" do
      b = SlidePay::Report.new([])
      b.report_type = :put
      b.url = "DOG_REPORT_URL"

      retrieve_params = { path: "EXAMPLE_URL", data: [].to_json, options: {} }

      SlidePay.should_receive(:put).and_return(a_response_object)
      b.retrieve()

      expect(b["id"]).to eq("1")
      expect(b["name"]).to eq("Dog the Bounty Hunter")
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
slidepay-0.0.13 spec/report_spec.rb
slidepay-0.0.12 spec/report_spec.rb