<commit_before># frozen_string_literal: true

require 'rails_helper'
require 'slack_helper'

RSpec.describe Slack::Commands::Help, type: :model do

  describe '#execute!' do

    let(:login) { 'github-login' }
    let(:id) { 100_000 + Random.rand(100_000) }
    let(:github_user_data) do
      JSON.dump(
        id: id,
        login: login
      )
    end
    let(:scopes) { 'repo,user' }

    context 'with valid access token' do
      subject { Github::Operations::FetchUser.new('valid_access_token').execute! }

      before :each do
        stub_request(:get, 'https://api.github.com/user')
          .with(
            headers: {
              'Authorization' => 'token valid_access_token'
            }
          )
          .to_return(
            status: 200,
            body: github_user_data,
            headers: {
              'X-OAuth-Scopes': scopes,
              'Content-Type': 'applicatin/json'
            }
          )
      end

      it 'fetches user' do
        expect(subject.user).not_to be_nil
        expect(subject.user.login).to eq(login)
        expect(subject.user.id).to eq(id)
      end

      it 'grabs scopes' do
        expect(subject.scopes).to eq(%w(repo user))
      end
    end

    context 'with invalid access token' do
      subject { Github::Operations::FetchUser.new('invalid_access_token') }

      before :each do
        stub_request(:get, 'https://api.github.com/user')
          .with(
            headers: {
              'Authorization' => 'token invalid_access_token'
            }
          )
          .to_return(
            status: 401,
            body: '{}',
            headers: {
              'Content-Type': 'applicatin/json'
            }
          )
      end

      it 'raises correct error' do
        expect do
          subject.execute!
        end.to raise_error(Github::ErrUnauthorized)
      end
    end
  end
end
<commit_msg>Test correct class<commit_after># frozen_string_literal: true

require 'rails_helper'
require 'slack_helper'

RSpec.describe Github::Operations::FetchUser, type: :model do

  describe '#execute!' do

    let(:login) { 'github-login' }
    let(:id) { 100_000 + Random.rand(100_000) }
    let(:github_user_data) do
      JSON.dump(
        id: id,
        login: login
      )
    end
    let(:scopes) { 'repo,user' }

    context 'with valid access token' do
      subject { Github::Operations::FetchUser.new('valid_access_token').execute! }

      before :each do
        stub_request(:get, 'https://api.github.com/user')
          .with(
            headers: {
              'Authorization' => 'token valid_access_token'
            }
          )
          .to_return(
            status: 200,
            body: github_user_data,
            headers: {
              'X-OAuth-Scopes': scopes,
              'Content-Type': 'applicatin/json'
            }
          )
      end

      it 'fetches user' do
        expect(subject.user).not_to be_nil
        expect(subject.user.login).to eq(login)
        expect(subject.user.id).to eq(id)
      end

      it 'grabs scopes' do
        expect(subject.scopes).to eq(%w(repo user))
      end
    end

    context 'with invalid access token' do
      subject { Github::Operations::FetchUser.new('invalid_access_token') }

      before :each do
        stub_request(:get, 'https://api.github.com/user')
          .with(
            headers: {
              'Authorization' => 'token invalid_access_token'
            }
          )
          .to_return(
            status: 401,
            body: '{}',
            headers: {
              'Content-Type': 'applicatin/json'
            }
          )
      end

      it 'raises correct error' do
        expect do
          subject.execute!
        end.to raise_error(Github::ErrUnauthorized)
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.11370186009955463, 'fraction_numerical': 0.009431490699502228, 'mean_word_length': 1.7058823529411764, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 4, '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': '6606769', 'n_tokens_mistral': 1184, 'n_tokens_neox': 1137, 'n_words': 240}