<commit_before>shared_context "mock adyen client" do |success:, fault_message: "", psp_reference: "" |
  before do
    allow(Spree::Adyen::Client).
      to receive(:new).
      and_return(client)
  end

  let(:recurring_details_response) do
    double("recurring details", details: [
      { creation_date: Time.parse("2016-07-29 UTC"),
        recurring_detail_reference: "AWESOMEREFERENCE",
        variant: "amex",
        card_number: "0000",
        card_expiry_month: "10",
        card_expiry_year: "2016",
        card_holder_name: "<NAME>",
    }
    ])
  end
  let(:successful_gateway_response) do
    double("Gateway Response", success?: true, result_code: "Authorised")
  end

  let(:client) do
    api_response = lambda do |gateway_response|
      instance_double(
        "Spree::Adyen::ApiResponse",
        success?: success,
        message: fault_message,
        psp_reference: psp_reference,
        attributes: { "resultCode" => "Authorised" },
        gateway_response: gateway_response,
      )
    end

    instance_double("Spree::Adyen::Client").tap do |double|
      allow(double).
        to receive(:authorise_payment).
        with(
          hash_including(
            :reference,
            :merchant_account,
            :amount,
            :billing_address,
            :shopper_i_p,<commit_msg>Allow request mock to receive and return redirect?<commit_after>shared_context "mock adyen client" do |success:, redirect: false, fault_message: "", psp_reference: "" |
  before do
    allow(Spree::Adyen::Client).
      to receive(:new).
      and_return(client)
  end

  let(:recurring_details_response) do
    double("recurring details", details: [
      { creation_date: Time.parse("2016-07-29 UTC"),
        recurring_detail_reference: "AWESOMEREFERENCE",
        variant: "amex",
        card_number: "0000",
        card_expiry_month: "10",
        card_expiry_year: "2016",
        card_holder_name: "<NAME>",
    }
    ])
  end
  let(:successful_gateway_response) do
    double("Gateway Response", success?: true, result_code: "Authorised")
  end

  let(:client) do
    api_response = lambda do |gateway_response|
      instance_double(
        "Spree::Adyen::ApiResponse",
        success?: success,
        redirect?: redirect,
        message: fault_message,
        psp_reference: psp_reference,
        attributes: { "resultCode" => "Authorised" },
        gateway_response: gateway_response,
      )
    end

    instance_double("Spree::Adyen::Client").tap do |double|
      allow(double).
        to receive(:authorise_payment).
        with(
          hash_including(
            :reference,
            :merchant_account,
            :amount,
            :billing_address,
            :shopper_i_p,
{'fraction_non_alphanumeric': 0.11503458318165272, 'fraction_numerical': 0.013105205678922462, 'mean_word_length': 2.6737967914438503, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '5622239', 'n_tokens_mistral': 869, 'n_tokens_neox': 836, 'n_words': 166}