<commit_before>require 'spec_helper'

describe Mailroute::EmailAccount, :vcr => true do
  before { configure_mailroute }

  describe '.get' do
    context 'by id' do
      it 'should return an account' do
        account = Mailroute::EmailAccount.get(25396)
        account.attributes[:domain].should == '/api/v1/domain/1198/'
        account.localpart.should == '2bill'
      end
    end

    context 'by localpart and domain' do
      let(:domain) { Mailroute::Domain.get(1198) }

      it 'should return an account' do
        account = Mailroute::EmailAccount.get('2bill', domain)
        account.id.should == 25396
      end
    end

    context 'by localpart and domain id' do
      it 'should return an account' do
        account = Mailroute::EmailAccount.get('2bill', 1198)
        account.id.should == 25396
      end
    end

    context 'by localpart and domain name' do
      it 'should return an account' do
        account = Mailroute::EmailAccount.get('2bill', 'mailroute.net')
        account.id.should == 25396
      end
    end
  end

  describe '#create' do
    context 'when domain exists' do
      let(:existing_domain) { Mailroute::Domain.get('example.com') }
      
      context 'creating an email account by email address' do
        subject(:email_account) { Mailroute::EmailAccount.create('<EMAIL>') }

        it 'should be created successfully' do
          email_account.id.should_not be_nil
        end

        its(:domain) { should == existing_domain }
        its(:localpart) { should == 'admin' }
      end
    end

    context "when domain doesn't exist" do
      context 'creating an email account by email address' do
        let(:email_account) { Mailroute::EmailAccount.create('<EMAIL>') }

        it 'should raise ResourceNotFound error' do
          expect { email_account }.to raise_error ActiveResource::ResourceNotFound
        end
      end
    end
  end

  describe '#regenerate_api_key' do
    context 'an email account' do<commit_msg>Removing trailing whitespace<commit_after>require 'spec_helper'

describe Mailroute::EmailAccount, :vcr => true do
  before { configure_mailroute }

  describe '.get' do
    context 'by id' do
      it 'should return an account' do
        account = Mailroute::EmailAccount.get(25396)
        account.attributes[:domain].should == '/api/v1/domain/1198/'
        account.localpart.should == '2bill'
      end
    end

    context 'by localpart and domain' do
      let(:domain) { Mailroute::Domain.get(1198) }

      it 'should return an account' do
        account = Mailroute::EmailAccount.get('2bill', domain)
        account.id.should == 25396
      end
    end

    context 'by localpart and domain id' do
      it 'should return an account' do
        account = Mailroute::EmailAccount.get('2bill', 1198)
        account.id.should == 25396
      end
    end

    context 'by localpart and domain name' do
      it 'should return an account' do
        account = Mailroute::EmailAccount.get('2bill', 'mailroute.net')
        account.id.should == 25396
      end
    end
  end

  describe '#create' do
    context 'when domain exists' do
      let(:existing_domain) { Mailroute::Domain.get('example.com') }

      context 'creating an email account by email address' do
        subject(:email_account) { Mailroute::EmailAccount.create('<EMAIL>') }

        it 'should be created successfully' do
          email_account.id.should_not be_nil
        end

        its(:domain) { should == existing_domain }
        its(:localpart) { should == 'admin' }
      end
    end

    context "when domain doesn't exist" do
      context 'creating an email account by email address' do
        let(:email_account) { Mailroute::EmailAccount.create('<EMAIL>') }

        it 'should raise ResourceNotFound error' do
          expect { email_account }.to raise_error ActiveResource::ResourceNotFound
        end
      end
    end
  end

  describe '#regenerate_api_key' do
    context 'an email account' do
{'fraction_non_alphanumeric': 0.09801457652676551, 'fraction_numerical': 0.01859763759738628, 'mean_word_length': 2.6413540713632204, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '5758153', 'n_tokens_mistral': 1188, 'n_tokens_neox': 1106, 'n_words': 341}