spec/integration/braintree/dispute_search_spec.rb in braintree-2.83.0 vs spec/integration/braintree/dispute_search_spec.rb in braintree-2.84.0

- old
+ new

@@ -1,9 +1,40 @@ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper") require File.expand_path(File.dirname(__FILE__) + "/client_api/spec_helper") describe Braintree::Dispute, "search" do + let(:customer) do + result = Braintree::Customer.create( + :first_name => "Jen", + :last_name => "Smith", + :company => "Braintree", + :email => "jen@example.com", + :phone => "312.555.1234", + :fax => "614.555.5678", + :website => "www.example.com" + ) + + result.customer + end + + let(:transaction) do + result = Braintree::Transaction.sale( + :amount => '10.00', + :credit_card => { + :expiration_date => '01/2020', + :number => Braintree::Test::CreditCardNumbers::Disputes::Chargeback + }, + :customer_id => customer.id, + :merchant_account_id => "14LaddersLLC_instant", + :options => { + :submit_for_settlement => true + } + ) + + result.transaction + end + context "advanced" do it "correctly returns a result with no matches" do collection = Braintree::Dispute.search do |search| search.id.is "non_existent_dispute" end @@ -21,19 +52,57 @@ expect(dispute.id).to eq("open_dispute") expect(dispute.status).to eq(Braintree::Dispute::Status::Open) end + it "correctly returns a single dispute by customer_id" do + collection = Braintree::Dispute.search do |search| + search.customer_id.is transaction.customer_details.id + end + + expect(collection.disputes.count).to eq(1) + dispute = collection.disputes.first + + expect(dispute.id).to eq(transaction.disputes.first.id) + expect(dispute.status).to eq(Braintree::Dispute::Status::Open) + end + it "correctly returns disputes by multiple reasons" do collection = Braintree::Dispute.search do |search| search.reason.in [ Braintree::Dispute::Reason::ProductUnsatisfactory, Braintree::Dispute::Reason::Retrieval ] end expect(collection.disputes.count).to eq(2) dispute = collection.disputes.first + end + + it "correctly returns disputes by effective_date range" do + effective_date = transaction.disputes.first.status_history.first.effective_date + + collection = Braintree::Dispute.search do |search| + search.effective_date.between(effective_date, Date.parse(effective_date).next_day.to_s) + end + + expect(collection.disputes.count).to be >= 1 + + dispute_ids = collection.disputes.map { |d| d.id } + expect(dispute_ids).to include(transaction.disputes.first.id) + end + + it "correctly returns disputes by disbursement_date range" do + disbursement_date = transaction.disputes.first.status_history.first.disbursement_date + + collection = Braintree::Dispute.search do |search| + search.disbursement_date.between(disbursement_date, Date.parse(disbursement_date).next_day.to_s) + end + + expect(collection.disputes.count).to be >= 1 + + dispute_ids = collection.disputes.map { |d| d.id } + expect(dispute_ids).to include(transaction.disputes.first.id) end it "correctly returns disputes by received_date range" do collection = Braintree::Dispute.search do |search| search.received_date.between("03/03/2014", "03/05/2014")