<commit_before>require 'spec_helper'

module Spree::Admin
  describe EndpointMessagesController do
    render_views
    stub_authorization!

    before do
      stub_authentication!
    end

    describe "#index" do
      it "returns endpoint messages" do
        em1, em2 = create(:endpoint_message), create(:endpoint_message)
        spree_get :index
        expect(assigns(:endpoint_messages)).to match_array([em1, em2])
      end

      it "searches by query" do
        em1, em2 = create(:endpoint_message, payload: %Q{{"message":"test:search"}}, uri: "spreecommerce.com"), create(:endpoint_message)
        spree_get :index, q: { message_eq: "test:search", uri_cont: "spree" }
        expect(assigns(:endpoint_messages)).to match_array([em1])
      end
    end
  end<commit_msg>Adds regression tests<commit_after>require 'spec_helper'

module Spree::Admin
  describe EndpointMessagesController do
    render_views
    stub_authorization!

    before do
      stub_authentication!
    end

    describe "#index" do
      it "returns endpoint messages" do
        em1, em2 = create(:endpoint_message), create(:endpoint_message)
        spree_get :index
        expect(assigns(:endpoint_messages)).to match_array([em1, em2])
      end

      context "search" do
        it "filter by message" do
          em1, em2 = create(:endpoint_message, payload: %Q{{"message":"test:search"}}, uri: "spreecommerce.com"), create(:endpoint_message)
          spree_get :index, q: { message_eq: "test:search" }
          expect(assigns(:endpoint_messages)).to match_array([em1])
        end

        it "filter by uri" do
          em1, em2 = create(:endpoint_message, payload: %Q{{"message":"test:search"}}, uri: "spreecommerce.com"), create(:endpoint_message)
          spree_get :index, q: { uri_cont: "spree" }
          expect(assigns(:endpoint_messages)).to match_array([em1])
        end
      end
    end

    describe "#create" do
      before do
        Spree::Admin::ApiRequest.stub post: {}
      end

      it "creates a new message" do
        expect {
          spree_post :create, endpoint_message: attributes_for(:endpoint_message),
            new_parameter_pairs: { "1" => { "name" => "super.token", "value" => "ABC" } }
        }.to change(Spree::EndpointMessage, :count).by 1
      end

      context "parameters is empty" do
        it "creates a new message" do
          expect {
            spree_post :create, endpoint_message: attributes_for(:endpoint_message), new_parameter_pairs: nil
          }.to change(Spree::EndpointMessage, :count).by 1
        end
      end
    end
  end
{'fraction_non_alphanumeric': 0.11320754716981132, 'fraction_numerical': 0.007701193685021178, 'mean_word_length': 2.9603658536585367, 'pattern_counts': {'":': 3, '<': 3, '<?xml version=': 0, '>': 6, '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': '2653078', 'n_tokens_mistral': 780, 'n_tokens_neox': 768, 'n_words': 191}