<commit_before>RSpec.shared_examples 'common advocate litigator validations' do |external_user_type, options|
  context 'when validating external_user' do
    let(:expected_blank_message) do
      { advocate: 'Choose an advocate',
        litigator: 'Choose a litigator' }
    end

    it 'errors if not present, regardless' do
      claim.external_user = nil
      should_error_with(claim, :external_user_id, expected_blank_message[external_user_type])
    end

    it 'errors if does not belong to the same provider as the creator' do
      claim.creator = create(:external_user, external_user_type)
      claim.external_user = create(:external_user, external_user_type)
      should_error_with(claim, :external_user_id, "Creator and #{external_user_type} must belong to the same provider")
    end
  end

  context 'when validating creator' do
    it 'errors if not present, regardless' do
      claim.creator = nil
      should_error_with(claim, :creator, 'blank')
    end
  end

  unless options&.fetch(:case_type, nil) == false
    context 'case_type' do
      it 'errors if not present' do
        claim.case_type = nil
        should_error_with(claim, :case_type_id, 'Choose a case type')
      end
    end
  end

  context 'when validating court' do
    it 'errors if not present' do
      claim.court = nil
      should_error_with(claim, :court_id, 'Choose a court')
    end
  end

  context 'when validating transfer_court_id' do
    context 'with case_transferred_from_another_court not explictly set, but case number set' do
      before { claim.transfer_case_number = 'A20161234' }

      it 'errors if blank' do
        claim.transfer_court = nil
        should_error_with(claim, :transfer_court_id, 'Choose a transfer court')
      end

      it 'errors when the same as the original court' do
        claim.transfer_court = claim.court
        should_error_with(claim, :transfer_court_id, 'Choose a different transfer court')
      end
    end

    context 'with case transferred from another court set' do
      before do
        claim.case_transferred_from_another_court = true
      end

      it 'errors if blank' do
        claim.transfer_court = nil
        should_error_with(claim, :transfer_court_id, 'Choose a transfer court')
      end

      it 'errors when the same as the original court' do
        claim.transfer_court = claim.court
        should_error_with(claim, :transfer_court_id, 'Choose a different transfer court')
      end

      it 'valid when transfer court different to original court' do
        claim.transfer_court = build(:court)
        should_not_error(claim, :transfer_court_id)
      end
    end
  end

  context 'when validating transfer_case_number' do
    before { claim.transfer_court = build(:court) }

    it 'does not error if blank' do
      claim.transfer_case_number = nil
      should_not_error(claim, :transfer_case_number)
    end

    it 'does not error if valid case_number' do
      claim.transfer_case_number = 'A20161234'
      should_not_error(claim, :transfer_case_number)
    end

    it 'does not error if valid URN' do
      claim.transfer_case_number = 'ABCDEFGHIJ1234567890'
      should_not_error(claim, :transfer_case_number)
    end

    it 'errors when format is similar to but invalid case number' do
      claim.transfer_case_number = 'A201612345'
      should_error_with(claim, :transfer_case_number, 'Invalid transfer case number')
    end

    it 'errors when format is invalid case number or urn' do
      claim.transfer_case_number = 'ABC_'
      should_error_with(claim, :transfer_case_number, 'Invalid transfer case number or urn')
    end

    context 'with case transferred from another court' do
      before do
        claim.case_transferred_from_another_court = true
      end

      context 'with transfer court not set' do
        before { claim.transfer_court = nil }

        context 'with transfer case number blank' do
          before { claim.transfer_case_number = '' }

          it 'does not contain errors on transfer case number' do
            should_not_error(claim, :transfer_case_number)
          end
        end

        context 'with transfer case number in invalid format' do
          before { claim.transfer_case_number = 'ABC_' }

          it 'contains an invalid error on transfer case number' do
            should_error_with(claim, :transfer_case_number, 'Invalid transfer case number or urn')
          end
        end
      end
    end
  end
end

RSpec.shared_examples 'common litigator validations' do |*flags|
  let(:advocate)      { build(:external_user, :advocate) }
  let(:offence)       { build(:offence) }
  let(:offence_class) { build(:offence_class, class_letter: 'X', description: 'Offences of dishonesty in Class F where the value in is in excess of £100,000') }<commit_msg>Amend wording of context blocks<commit_after>RSpec.shared_examples 'common advocate litigator validations' do |external_user_type, options|
  context 'when validating external_user' do
    let(:expected_blank_message) do
      { advocate: 'Choose an advocate',
        litigator: 'Choose a litigator' }
    end

    it 'errors if not present, regardless' do
      claim.external_user = nil
      should_error_with(claim, :external_user_id, expected_blank_message[external_user_type])
    end

    it 'errors if does not belong to the same provider as the creator' do
      claim.creator = create(:external_user, external_user_type)
      claim.external_user = create(:external_user, external_user_type)
      should_error_with(claim, :external_user_id, "Creator and #{external_user_type} must belong to the same provider")
    end
  end

  context 'when validating creator' do
    it 'errors if not present, regardless' do
      claim.creator = nil
      should_error_with(claim, :creator, 'blank')
    end
  end

  unless options&.fetch(:case_type, nil) == false
    context 'case_type' do
      it 'errors if not present' do
        claim.case_type = nil
        should_error_with(claim, :case_type_id, 'Choose a case type')
      end
    end
  end

  context 'when validating court' do
    it 'errors if not present' do
      claim.court = nil
      should_error_with(claim, :court_id, 'Choose a court')
    end
  end


  context 'when validating transfer_court' do
    before { claim.transfer_case_number = 'A20161234' }

      it 'errors if blank' do
        claim.transfer_court = nil
        should_error_with(claim, :transfer_court_id, 'Choose a transfer court')
      end

      it 'errors when the same as the original court' do
        claim.transfer_court = claim.court
        should_error_with(claim, :transfer_court_id, 'Choose a different transfer court')
      end
    end

    context 'with case transferred from another court' do
      before do
        claim.case_transferred_from_another_court = true
      end

      it 'errors if blank' do
        claim.transfer_court = nil
        should_error_with(claim, :transfer_court_id, 'Choose a transfer court')
      end

      it 'errors when the same as the original court' do
        claim.transfer_court = claim.court
        should_error_with(claim, :transfer_court_id, 'Choose a different transfer court')
      end

      it 'valid when transfer court different to original court' do
        claim.transfer_court = build(:court)
        should_not_error(claim, :transfer_court_id)
      end
    end
  end

  context 'when validating transfer_case_number' do
    before { claim.transfer_court = build(:court) }

    it 'does not error if blank' do
      claim.transfer_case_number = nil
      should_not_error(claim, :transfer_case_number)
    end

    it 'does not error if valid case_number' do
      claim.transfer_case_number = 'A20161234'
      should_not_error(claim, :transfer_case_number)
    end

    it 'does not error if valid URN' do
      claim.transfer_case_number = 'ABCDEFGHIJ1234567890'
      should_not_error(claim, :transfer_case_number)
    end

    it 'errors when format is similar to but invalid case number' do
      claim.transfer_case_number = 'A201612345'
      should_error_with(claim, :transfer_case_number, 'Invalid transfer case number')
    end

    it 'errors when format is invalid case number or urn' do
      claim.transfer_case_number = 'ABC_'
      should_error_with(claim, :transfer_case_number, 'Invalid transfer case number or urn')
    end

    context 'with case transferred from another court' do
      before do
        claim.case_transferred_from_another_court = true
      end

      context 'with transfer court not set' do
        before do
          claim.transfer_court = nil
        end

        context 'with transfer case number blank' do
          before do
            claim.transfer_case_number = ''
          end

          it 'does not contain errors on transfer case number' do
            should_not_error(claim, :transfer_case_number)
          end
        end

        context 'with transfer case number in invalid format' do
          before do
            claim.transfer_case_number = 'ABC_'
          end

          it 'contains an invalid error on transfer case number' do
            should_error_with(claim, :transfer_case_number, 'Invalid transfer case number or urn')
          end
        end
      end
    end
  end
end

RSpec.shared_examples 'common litigator validations' do |*flags|
  let(:advocate)      { build(:external_user, :advocate) }
  let(:offence)       { build(:offence) }
  let(:offence_class) { build(:offence_class, class_letter: 'X', description: 'Offences of dishonesty in Class F where the value in is in excess of £100,000') }
{'fraction_non_alphanumeric': 0.06675692564049157, 'fraction_numerical': 0.008539887523432618, 'mean_word_length': 2.9714640198511164, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '531662', 'n_tokens_mistral': 2843, 'n_tokens_neox': 2695, 'n_words': 906}