<commit_before>module MockAuthApiHelper
  def mock_auth_api_client
    @old_service = ServiceRegistry.service(:auth_api_client)
    MockClient.reset_mock
    ServiceRegistry.register(:auth_api_client, MockClient)
  end

  def clean_auth_api_client_mock
    ServiceRegistry.register(:auth_api_client, @old_service)
  end

  def mock_auth_api_organisations(organisations)
    MockClient.mock_organisations(organisations)
  end

  class MockClient
    def initialize(token)
    end

    def organisations(params = {})
      @@organisations
    end

    def self.reset_mock
      @@organisations = []
    end

    def self.mock_organisations(organisations)
      @@organisations = organisations.map do |organisation|
        if organisation.is_a?(Hash)
          Drs::AuthClient::Models::Organisation.new(organisation)
        else
          organisation
        end
      end
    end
  end
end

RSpec.configure do |config|
  config.include MockAuthApiHelper, mock_auth_api: true

  config.around(:each, mock_auth_api: true) do |example|
    mock_auth_api_client
    example.run
    clean_auth_api_client_mock
  end

end<commit_msg>Fix Rubocop offences<commit_after>module MockAuthApiHelper
  def mock_auth_api_client
    @old_service = ServiceRegistry.service(:auth_api_client)
    MockClient.reset_mock
    ServiceRegistry.register(:auth_api_client, MockClient)
  end

  def clean_auth_api_client_mock
    ServiceRegistry.register(:auth_api_client, @old_service)
  end

  def mock_auth_api_organisations(organisations)
    MockClient.mock_organisations(organisations)
  end

  class MockClient
    def initialize(token)
    end

    def organisations(params = {})
      self.class.mocked_organisations
    end

    def self.reset_mock
      @mocked_organisations = []
    end

    def self.mock_organisations(organisations)
      @mocked_organisations = organisations.map do |organisation|
        if organisation.is_a?(Hash)
          Drs::AuthClient::Models::Organisation.new(organisation)
        else
          organisation
        end
      end
    end

    def self.mocked_organisations
      @mocked_organisations ||= []
    end
  end
end

RSpec.configure do |config|
  config.include MockAuthApiHelper, mock_auth_api: true

  config.around(:each, mock_auth_api: true) do |example|
    mock_auth_api_client
    example.run
    clean_auth_api_client_mock
  end

end
{'fraction_non_alphanumeric': 0.06796116504854369, 'fraction_numerical': 0.0, 'mean_word_length': 3.5489443378119003, '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': '2475224', 'n_tokens_mistral': 750, 'n_tokens_neox': 717, 'n_words': 135}