<commit_before>RSpec.describe FinApps::Middleware::TenantAuthentication do
  describe '#call' do
    fake_app = proc {|env| env }
    valid_credentials = {company_identifier: 'id', company_token: 'token'}

    context 'when company credentials were provided' do
      let(:middleware) { FinApps::Middleware::TenantAuthentication.new fake_app, valid_credentials }
      let(:request_env) { {request_headers: {}} }
      let(:expected_header_value) { "#{valid_credentials[:company_identifier]}=#{valid_credentials[:company_token]}" }

      subject(:result) { middleware.call(request_env) }

      it 'should generate the X-FinApps-Token header' do
        header = result[:request_headers][FinApps::Middleware::TenantAuthentication::KEY]
        expect(header).to eq(expected_header_value)
      end
    end
  end
end<commit_msg>tests for tenant auth middleware<commit_after>RSpec.describe FinApps::Middleware::TenantAuthentication do
  describe '#call' do
    fake_app = proc {|env| env }
    valid_credentials = {company_identifier: 'id', company_token: 'token'}

    context 'when company credentials were provided' do
      let(:middleware) { FinApps::Middleware::TenantAuthentication.new fake_app, valid_credentials }
      let(:generated_header) { "#{valid_credentials[:company_identifier]}=#{valid_credentials[:company_token]}" }

      context 'when header was not previously set' do
        let(:request_env) { {request_headers: {}} }
        subject(:header) do
          middleware.call(request_env)[:request_headers][FinApps::Middleware::TenantAuthentication::KEY]
        end

        it('generates a Tenant Authentication header') { expect(header).to eq(generated_header) }
      end

      context 'when header was previously set' do
        let(:existing_header) { {FinApps::Middleware::TenantAuthentication::KEY => 'foo'} }
        let(:request_env) { {request_headers: existing_header} }
        subject(:header) do
          middleware.call(request_env)[:request_headers][FinApps::Middleware::TenantAuthentication::KEY]
        end

        it('does not override existing Tenant Authentication header') { expect(header).to eq('foo') }
        it('does not generate a Tenant Authentication header') { expect(header).to_not eq(generated_header) }
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.11572052401746726, 'fraction_numerical': 0.0, 'mean_word_length': 4.428909952606635, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '2264833', 'n_tokens_mistral': 644, 'n_tokens_neox': 643, 'n_words': 139}