<commit_before>require 'spec_helper'

describe Killbill::Cybersource::PaymentPlugin do

  include ::Killbill::Plugin::ActiveMerchant::RSpec

  before(:each) do
    Dir.mktmpdir do |dir|
      file = File.new(File.join(dir, 'cybersource.yml'), 'w+')
      file.write(<<-eos)
:cybersource:
  :test: true
# As defined by spec_helper.rb
:database:
  :adapter: 'sqlite3'
  :database: 'test.db'
      eos
      file.close

      @plugin = build_plugin(::Killbill::Cybersource::PaymentPlugin, 'cybersource', File.dirname(file))

      # Start the plugin here - since the config file will be deleted
      @plugin.start_plugin
    end
  end

  let(:expected_successful_params) do
    {
        :params_merchant_reference_code => 'b0a6cf9aa07f1a8495f89c364bbd6a9a',
        :params_request_id => '2004333231260008401927',
        :params_decision => 'ACCEPT',
        :params_reason_code => '100',
        :params_request_token => '<KEY>',
        :params_currency => 'USD',
        :params_amount => '1.00',
        :params_authorization_code => '123456',
        :params_avs_code => 'Y',
        :params_avs_code_raw => 'Y',
        :params_cv_code => 'M',
        :params_authorized_date_time => '2008-01-15T21:42:03Z',
        :params_processor_response => '00',
        :params_reconciliation_id => 'ABCDEF',
        :params_subscription_id => 'XXYYZZ'
    }
  end

  it 'should start and stop correctly' do
    @plugin.stop_plugin
  end

  it 'should detect when to credit refunds' do
    context = build_call_context
    kb_payment_id = SecureRandom.uuid

    @plugin.should_credit?(SecureRandom.uuid, context).should be_false

    with_transaction(kb_payment_id, :AUTHORIZE, 60.days.ago, build_call_context(SecureRandom.uuid)) { @plugin.should_credit?(kb_payment_id, context).should be_false }
    with_transaction(kb_payment_id, :AUTHORIZE, 59.days.ago, context) { @plugin.should_credit?(kb_payment_id, context).should be_false }
    with_transaction(kb_payment_id, :VOID, 60.days.ago, context) { @plugin.should_credit?(kb_payment_id, context).should be_false }
    with_transaction(SecureRandom.uuid, :AUTHORIZE, 60.days.ago, context) { @plugin.should_credit?(kb_payment_id, context).should be_false }

    with_transaction(kb_payment_id, :AUTHORIZE, 61.days.ago, context) do
      @plugin.should_credit?(kb_payment_id, context, {:disable_auto_credit => true}).should be_false
      @plugin.should_credit?(kb_payment_id, context, {:auto_credit_threshold => 61 * 86400 + 10}).should be_false
      @plugin.should_credit?(kb_payment_id, context).should be_true
    end
  end
<commit_msg>spec: fix flaky assertion (DST change)<commit_after>require 'spec_helper'

describe Killbill::Cybersource::PaymentPlugin do

  include ::Killbill::Plugin::ActiveMerchant::RSpec

  before(:each) do
    Dir.mktmpdir do |dir|
      file = File.new(File.join(dir, 'cybersource.yml'), 'w+')
      file.write(<<-eos)
:cybersource:
  :test: true
# As defined by spec_helper.rb
:database:
  :adapter: 'sqlite3'
  :database: 'test.db'
      eos
      file.close

      @plugin = build_plugin(::Killbill::Cybersource::PaymentPlugin, 'cybersource', File.dirname(file))

      # Start the plugin here - since the config file will be deleted
      @plugin.start_plugin
    end
  end

  let(:expected_successful_params) do
    {
        :params_merchant_reference_code => 'b0a6cf9aa07f1a8495f89c364bbd6a9a',
        :params_request_id => '2004333231260008401927',
        :params_decision => 'ACCEPT',
        :params_reason_code => '100',
        :params_request_token => '<KEY>',
        :params_currency => 'USD',
        :params_amount => '1.00',
        :params_authorization_code => '123456',
        :params_avs_code => 'Y',
        :params_avs_code_raw => 'Y',
        :params_cv_code => 'M',
        :params_authorized_date_time => '2008-01-15T21:42:03Z',
        :params_processor_response => '00',
        :params_reconciliation_id => 'ABCDEF',
        :params_subscription_id => 'XXYYZZ'
    }
  end

  it 'should start and stop correctly' do
    @plugin.stop_plugin
  end

  it 'should detect when to credit refunds' do
    context = build_call_context
    kb_payment_id = SecureRandom.uuid

    @plugin.should_credit?(SecureRandom.uuid, context).should be_false

    with_transaction(kb_payment_id, :AUTHORIZE, 60.days.ago, build_call_context(SecureRandom.uuid)) { @plugin.should_credit?(kb_payment_id, context).should be_false }
    with_transaction(kb_payment_id, :AUTHORIZE, 59.days.ago, context) { @plugin.should_credit?(kb_payment_id, context).should be_false }
    with_transaction(kb_payment_id, :VOID, 60.days.ago, context) { @plugin.should_credit?(kb_payment_id, context).should be_false }
    with_transaction(SecureRandom.uuid, :AUTHORIZE, 60.days.ago, context) { @plugin.should_credit?(kb_payment_id, context).should be_false }

    with_transaction(kb_payment_id, :AUTHORIZE, 61.days.ago, context) do
      @plugin.should_credit?(kb_payment_id, context, {:disable_auto_credit => true}).should be_false
      @plugin.should_credit?(kb_payment_id, context, {:auto_credit_threshold => 61 * 86400 + 3600 + 10}).should be_false
      @plugin.should_credit?(kb_payment_id, context).should be_true
    end
  end

{'fraction_non_alphanumeric': 0.12221368178324366, 'fraction_numerical': 0.03420445810914681, 'mean_word_length': 4.073099415204679, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3088044', 'n_tokens_mistral': 1914, 'n_tokens_neox': 1744, 'n_words': 318}