require 'test_helper'

class RemoteEuplatescTest < Test::Unit::TestCase
  def setup
    @gateway = EuplatescGateway.new(fixtures(:euplatesc))

    @amount = 100
    @credit_card = credit_card('4000640000000005', month: '01', year: '23')
    @failed_card = credit_card('4111111111111111', month: '01', year: '23')

    @options = {
      billing_address: address,
      description: 'Store Purchase',
      invoice_id: SecureRandom.uuid,
      first_name: 'Jon',
      last_name: 'Doe',
      email: 'jondoe@email.com',
      mobile_phone: '0000000000',
      phone: '0000000',
      ip: '127.0.0.1'
    }

    @remote_options =
      @options.merge({
        recurrent: true,
        interval_days: 30,
        expiration: (Date.today + 1.year).strftime("%Y%m%d")
      })
  end

  def test_successful_purchase
    response = @gateway.purchase(@amount, @credit_card, @options)

    assert_success response
    assert_includes JSON.parse(response.message).symbolize_keys.keys, :cart_id
    assert_includes JSON.parse(response.message).symbolize_keys.keys, :url
  end

  def test_successful_recurring_purchase
    response = @gateway.purchase(@amount, @credit_card, @remote_options)

    assert_success response
    assert_includes JSON.parse(response.message).symbolize_keys.keys, :cart_id
    assert_includes JSON.parse(response.message).symbolize_keys.keys, :url
  end

  # def test_check_status
  #   ep_id = '2217C3E2D507A5BF42527B3EF44E7C0B909B357F'
  #   invoice_id = '1236'
  #   response = @gateway.transaction_status(ep_id, invoice_id)

  #   assert_success response
  # end

  def test_transcript_scrubbing
    transcript = capture_transcript(@gateway) do
      @gateway.purchase(@amount, @credit_card, @options)
    end
    transcript = @gateway.scrub(transcript)

    assert_scrubbed(@credit_card.number, transcript)
    assert_scrubbed(@credit_card.verification_value, transcript)
  end
end
