<commit_before># frozen_string_literal: true

require 'spec_helpers/client'

RSpec.describe FinApps::REST::Operators, 'initialized with valid FinApps::Client object' do
  include SpecHelpers::Client
  subject(:operators) { FinApps::REST::Operators.new(client) }

  describe '#list' do
    let(:list) { subject.list(params) }
    let(:results) { list[0] }
    let(:error_messages) { list[1] }

    context 'when missing params' do
      let(:params) { nil }
      it { expect { list }.not_to raise_error }
      it('performs a get and returns the response') { expect(results).to respond_to(:records) }
      it('returns an array of records') { expect(results.records).to be_a(Array) }
      it('returns no error messages') { expect(error_messages).to be_empty }
    end

    context 'when invalid params are provided' do
      let(:params) { ['invalid array'] }

      it { expect { list }.to raise_error(FinAppsCore::InvalidArgumentsError) }
    end

    context 'when including valid params' do
      let(:params) { {page: 2, sort: 'date_created', requested: 25, searchTerm: 'term', role: 2} }

      it { expect { list }.not_to raise_error }
      it('performs a get and returns the response') { expect(results).to respond_to(:records) }
      it('returns an array of records') { expect(results.records).to be_a(Array) }
      it('returns no error messages') { expect(error_messages).to be_empty }
      it 'builds query and sends proper request' do
        list
        url = "#{FinAppsCore::REST::Defaults::DEFAULTS[:host]}/v2/operators?filter=%7B%22last_name%22:%7B%22$regex" \
              '%22:%22term%22,%22$options%22:%22i%22%7D,%22role%22:2%7D&page=2&requested=25&sort=date_created'
        expect(WebMock).to have_requested(:get, url)
      end
    end
  end

  describe '#show' do
    let(:results) { show[0] }
    let(:error_messages) { show[1] }

    context 'when missing id' do
      let(:show) { subject.show(nil) }

      it { expect { show }.to raise_error(FinAppsCore::MissingArgumentsError) }
    end

    context 'for invalid id' do
      let(:show) { subject.show(:invalid_id) }

      it { expect { show }.not_to raise_error }
      it('results is nil') { expect(results).to be_nil }
      it('error messages array is populated') do<commit_msg>update operators spec<commit_after># frozen_string_literal: true

require 'spec_helpers/client'

RSpec.describe FinApps::REST::Operators, 'initialized with valid FinApps::Client object' do
  include SpecHelpers::Client
  subject(:operators) { FinApps::REST::Operators.new(client) }

  describe '#list' do
    let(:list) { subject.list(params) }
    let(:results) { list[0] }
    let(:error_messages) { list[1] }

    context 'when missing params' do
      let(:params) { nil }
      it { expect { list }.not_to raise_error }
      it('performs a get and returns the response') { expect(results).to respond_to(:records) }
      it('returns an array of records') { expect(results.records).to be_a(Array) }
      it('returns no error messages') { expect(error_messages).to be_empty }
    end

    context 'when invalid params are provided' do
      let(:params) { ['invalid array'] }

      it { expect { list }.to raise_error(FinAppsCore::InvalidArgumentsError) }
    end

    context 'when including valid params' do
      let(:params) { {page: 2, sort: 'date_created', requested: 25, searchTerm: 'term', role: 2} }

      it { expect { list }.not_to raise_error }
      it('performs a get and returns the response') { expect(results).to respond_to(:records) }
      it('returns an array of records') { expect(results.records).to be_a(Array) }
      it('returns no error messages') { expect(error_messages).to be_empty }
      it 'builds query and sends proper request' do
        list
        url = "#{FinAppsCore::REST::Defaults::DEFAULTS[:host]}/v2/operators?filter=%7B%22last_name%22:%22term%22," +
            "%22role%22:2%7D&page=2&requested=25&sort=date_created"
        expect(WebMock).to have_requested(:get, url)
      end
    end
  end

  describe '#show' do
    let(:results) { show[0] }
    let(:error_messages) { show[1] }

    context 'when missing id' do
      let(:show) { subject.show(nil) }

      it { expect { show }.to raise_error(FinAppsCore::MissingArgumentsError) }
    end

    context 'for invalid id' do
      let(:show) { subject.show(:invalid_id) }

      it { expect { show }.not_to raise_error }
      it('results is nil') { expect(results).to be_nil }
      it('error messages array is populated') do
{'fraction_non_alphanumeric': 0.1339404709018214, 'fraction_numerical': 0.015104398045313194, 'mean_word_length': 3.5484848484848484, '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': '5295842', 'n_tokens_mistral': 1466, 'n_tokens_neox': 1411, 'n_words': 365}