<commit_before>require 'spec_helper'

# https://docs.adyen.com/display/TD/HPP+payment+response
RSpec.describe Spree::AdyenRedirectController, type: :controller do
  let(:order) { create(:order_with_line_items, state: "payment") }
  let(:payment_method) { create :bogus_hpp_gateway }

  before do
    allow(controller).to receive(:current_order).and_return order
    allow(controller).to receive(:check_signature)
    allow(controller).to receive(:payment_method).
      and_return payment_method
  end

  describe "GET confirm" do
    subject(:action) { spree_get :confirm, params }

    let(:psp_reference) { "8813824003752247" }
    let(:params) do
      { merchantReference: order.number,
        skinCode: "xxxxxxxx",
        shopperLocale: "en_GB",
        paymentMethod: "visa",
        authResult: auth_result,
        pspReference:  psp_reference,
        merchantSig: "erewrwerewrewrwer"
      }
    end

    shared_examples "payment is successful" do
      it "changes the order state to completed" do
        expect{ subject }.
          to change{ order.state }.
          from("payment").
          to("complete")
      end

      it "redirects to the order complete page" do
        is_expected.to have_http_status(:redirect).
          and redirect_to order_path(order)
      end

      it "creates a pending payment" do
        expect{ subject }.
          to change{ order.payments.count }.
          from(0).
          to(1)

        expect(order.payments).to all be_pending
      end

      context "and the order cannot complete" do
        before do
          expect(order).to receive(complete).and_return(false)
        end

        it "voids the payment"
      end
    end

    context "when the payment is AUTHORISED" do
      include_examples "payment is successful"
      let(:auth_result) { "AUTHORISED" }
    end

    context "when the payment is PENDING" do
      include_examples "payment is successful"
      let(:auth_result) { "PENDING" }
    end
<commit_msg>Test to expose bug with early notifications<commit_after>require 'spec_helper'

# https://docs.adyen.com/display/TD/HPP+payment+response
RSpec.describe Spree::AdyenRedirectController, type: :controller do
  let(:order) { create(:order_with_line_items, state: "payment") }
  let(:payment_method) { create :bogus_hpp_gateway }

  before do
    allow(controller).to receive(:current_order).and_return order
    allow(controller).to receive(:check_signature)
    allow(controller).to receive(:payment_method).
      and_return payment_method
  end

  describe "GET confirm" do
    subject(:action) { spree_get :confirm, params }

    let(:psp_reference) { "8813824003752247" }
    let(:params) do
      { merchantReference: order.number,
        skinCode: "xxxxxxxx",
        shopperLocale: "en_GB",
        paymentMethod: "visa",
        authResult: auth_result,
        pspReference:  psp_reference,
        merchantSig: "erewrwerewrewrwer"
      }
    end

    shared_examples "payments are pending" do
      it "has pending payments" do
        expect(order.payments).to all be_pending
      end
    end

    shared_examples "payment is successful" do
      it "changes the order state to completed" do
        expect{ subject }.
          to change{ order.state }.
          from("payment").
          to("complete")
      end

      it "redirects to the order complete page" do
        is_expected.to have_http_status(:redirect).
          and redirect_to order_path(order)
      end

      it "creates a payment" do
        expect{ subject }.
          to change{ order.payments.count }.
          from(0).
          to(1)
      end

      context "and the order cannot complete" do
        before do
          expect(order).to receive(complete).and_return(false)
        end

        it "voids the payment"
      end
    end

    context "when the payment is AUTHORISED" do
      include_examples "payment is successful"
      include_examples "payments are pending"
      let(:auth_result) { "AUTHORISED" }

      context "and the authorisation notification has already been received" do
        before { create(:notification, :auth, psp_reference: psp_reference, merchant_reference: order.number) }

        include_examples "payment is successful"
      end
    end

    context "when the payment is PENDING" do
      include_examples "payment is successful"
      include_examples "payments are pending"
      let(:auth_result) { "PENDING" }
    end

{'fraction_non_alphanumeric': 0.08853932584269662, 'fraction_numerical': 0.008089887640449439, 'mean_word_length': 2.6754748142031377, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, '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': '1084018', 'n_tokens_mistral': 1330, 'n_tokens_neox': 1270, 'n_words': 353}