<commit_before>require 'test_helper'

describe Supercharged::GatewayNotificationsController do
  describe "create" do
    let(:charge) { Charge.create!({user_id: 1, amount: 10}, without_protection: true) }

    context "authorized" do
      let(:fake_user) { stub(id: 1) }

      before do
        GatewayNotification.any_instance.stubs(:current_user).returns(fake_user)
      end

      context "correct conditions" do
        it "works with good notification" do
          adapter = stub(item_id: 1, "complete?" => true, acknowledge: true, charge: charge)

          GatewayNotification.any_instance.stubs(:adapter).returns(adapter)

          post :create, gateway: "webmoney", amount: 100

          charge.reload
          charge.state_name.must_equal :ok

          assert_response :redirect, "/"
        end
      end

      context "bad conditions" do
        it "completed = false" do
          adapter = stub(item_id: 1, "complete?" => false, acknowledge: true, charge: charge)

          GatewayNotification.any_instance.stubs(:adapter).returns(adapter)

          post :create, gateway: "webmoney", amount: 100

          charge.reload
          charge.state_name.must_equal :error
          charge.error.must_equal "not_completed"

          assert_response :bad_request
        end

        it "acknowledge = false" do
          adapter = stub(item_id: 1, "complete?" => true, acknowledge: false, charge: charge)

          GatewayNotification.any_instance.stubs(:adapter).returns(adapter)

          post :create, gateway: "webmoney", amount: 100

          charge.reload
          charge.state_name.must_equal :error
          charge.error.must_equal "acknowledge_failed"

          assert_response :bad_request
        end
      end
    end

    context "without any payload params" do
      it "returns bad_request" do
        post :create, gateway: "paypal"

        assert_response :bad_request
      end
    end
  end
end<commit_msg>fix response test<commit_after>require 'test_helper'

describe Supercharged::GatewayNotificationsController do
  describe "create" do
    let(:charge) { Charge.create!({user_id: 1, amount: 10}, without_protection: true) }

    context "authorized" do
      let(:fake_user) { stub(id: 1) }

      before do
        GatewayNotification.any_instance.stubs(:current_user).returns(fake_user)
      end

      context "correct conditions" do
        it "works with good notification" do
          adapter = stub(item_id: 1, "complete?" => true, acknowledge: true, charge: charge)

          GatewayNotification.any_instance.stubs(:adapter).returns(adapter)

          post :create, gateway: "webmoney", amount: 100

          charge.reload
          charge.state_name.must_equal :ok

          assert_response :redirect, "/"
        end
      end

      context "bad conditions" do
        it "completed = false" do
          adapter = stub(item_id: 1, "complete?" => false, acknowledge: true, charge: charge)

          GatewayNotification.any_instance.stubs(:adapter).returns(adapter)

          post :create, gateway: "webmoney", amount: 100

          charge.reload
          charge.state_name.must_equal :error
          charge.error.must_equal "not_completed"

          assert_response :found
        end

        it "acknowledge = false" do
          adapter = stub(item_id: 1, "complete?" => true, acknowledge: false, charge: charge)

          GatewayNotification.any_instance.stubs(:adapter).returns(adapter)

          post :create, gateway: "webmoney", amount: 100

          charge.reload
          charge.state_name.must_equal :error
          charge.error.must_equal "acknowledge_failed"

          assert_response :found
        end
      end
    end

    context "without any payload params" do
      it "returns bad_request" do
        post :create, gateway: "paypal"

        assert_response :bad_request
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.0917948717948718, 'fraction_numerical': 0.008205128205128205, 'mean_word_length': 2.5431425976385102, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '1374416', 'n_tokens_mistral': 1139, 'n_tokens_neox': 1046, 'n_words': 281}