Act as a spelling corrector, content editor, and text improver. ONLY return the rewritten text and nothing else.

Strictly follow these rules:
- Correct spelling, grammar, and punctuation errors in the given text
- Enhance clarity and conciseness without altering the original meaning
- Use the same language as the original text
- Divide lengthy sentences into shorter, more readable ones
- Eliminate unnecessary repetition while preserving important points
- Prioritize active voice over passive voice for a more engaging tone
- Opt for simpler, more accessible vocabulary when possible
- ALWAYS ensure the original meaning and intention of the given text
- ALWAYS maintain the original language of the text
- ALWAYS maintain the existing tone of voice and style, e.g. formal, casual, polite, etc.
- NEVER surround the improved text with quotes or any additional formatting
- If the text is already well-written and requires no improvement, do not change the given text

Text to improve:

Act as a spelling corrector, content editor, and text improver. ONLY return the rewritten text and nothing else.

Strictly follow these rules:
- Correct spelling, grammar, and punctuation errors in the given text
- Enhance clarity and conciseness without altering the original meaning
- Use the same language as the original text
- Divide lengthy sentences into shorter, more readable ones
- Eliminate unnecessary repetition while preserving important points
- Prioritize active voice over passive voice for a more engaging tone
- Opt for simpler, more accessible vocabulary when possible
- ALWAYS ensure the original meaning and intention of the given text
- ALWAYS maintain the original language of the text
- ALWAYS maintain the existing tone of voice and style, e.g. formal, casual, polite, etc.
- NEVER surround the improved text with quotes or any additional formatting
- If the text is already well-written and requires no improvement, do not change the given text

Text to improve:

# frozen_string_literal: true

require "rails_helper"

RSpec.describe LegalNameUpdate::MessageProcessor do
  subject(:run_processor) { described_class.call(proto_obj:) }

  let(:user_id) { "user123" }
  let(:socure_data) do
    {
      "reference_id" => "socure_ref_123",
      "kyc_plus" => {
        "kycPlus" => {
          "bestMatchedEntity" => { "pii_data" => "sensitive" },
          "otherData" => "value",
        },
      },
    }
  end

  let(:decplat_outcome) { "allow" }

  let(:proto_obj) do
    {
      "user_id" => user_id,
      "request" => {
        "user_update" => {
          "vendor_data" => {
            "socure_data" => socure_data,
          },
        },
      },
      "decision_id" => SecureRandom.uuid,
      "decision" => {
        "outcome" => {
          "outcome" => decplat_outcome,
        },
      },
    }
  end

  describe "#call" do
    context "when socure response exists" do
      context("outcome is allow") do
        let(:outcome) { "allow"}

        it "creates decision and vendor inquiries" do
          expect do
            expect do
              expect do
                run_processor
              end.to change { Decision.all.count }.by(1)
            end.to change { VendorInquiry.all.count }.by(2)
          end.to change { VendorDecision.all.count }.by(1)
        end
      end

      context("outcome is not allow") do
        let(:outcome) { "contact_omx"}
        it "creates decision and vendor inquiries" do
          expect do
            expect do
              expect do
                run_processor
              end.to change { Decision.all.count }.by(1)
            end.to change { VendorInquiry.all.count }.by(2)
          end.to change { VendorDecision.all.count }.by(1)
        end
      end
    end

    context "when socure response does not exist" do
      let(:proto_obj) do
        {
          "user_id" => user_id,
          "user_update" => {
            "request" => {
              "referenceId" => "ref123",
            },
          },
          "request" => {
            "user_update" => {
              "vendor_data" => nil,
            },
          },
          "decision" => {
            "outcome" => {
              "outcome" => "allow",
            },
          },
        }
      end

      it "returns early without creating decision" do
        expect do
          expect do
            expect do
              run_processor
            end.not_to change { Decision.all.count }
          end.not_to change { VendorInquiry.all.count }
        end.not_to change { VendorDecision.all.count }
      end
    end
  end
end