<commit_before>describe Bank::Routes::User do
  let(:user) { Bank::Models::User.new({id: '123b', email: '<EMAIL>'}) }
  let(:token) { Bank::Support::Token.encode(user) }

  before do
    allow(Bank::Models::User).to receive(:find_by).and_return(user)
  end

  describe 'POST create' do
    context 'with valid params' do
      let(:params) { { name: 'Foo', user_id: '123b' } }
      let(:account) { Bank::Models::Account.new(params) }

      before do
        allow(Bank::Models::Account).to receive(:open).and_return(account)
      end

      it 'has a created account json' do
        header 'Authorization', "Bearer #{token}"
        post '/v1/accounts', params.to_json, provides: 'json'
        body = JSON.parse last_response.body
        expect(last_response.status).to eq 201
        expect(body['name']).to eq 'Foo'
      end
    end

    context 'with invalid params' do
      let(:without_name) { { password: '<PASSWORD>' } }

      it 'validates presence of name attribute' do
        header 'Authorization', "Bearer #{token}"
        post '/v1/accounts', without_name.to_json, provides: 'json'
        body = JSON.parse last_response.body
        expect(body['errors']).to eq "The following errors were found: Name can't be blank"
        expect(last_response.status).to eq 442
      end
    end
  end
end<commit_msg>Cover all specs for account endpoint<commit_after>describe Bank::Routes::User do
  let(:user) { Bank::Models::User.new({id: '123b', email: '<EMAIL>'}) }
  let(:token) { Bank::Support::Token.encode(user) }

  before do
    allow(Bank::Models::User).to receive(:find_by).and_return(user)
  end

  describe 'POST create' do
    context 'with valid params' do
      let(:params) { { name: 'Foo', user_id: '123b' } }
      let(:account) { Bank::Models::Account.new(params) }

      before do
        allow(Bank::Models::Account).to receive(:open).and_return(account)
      end

      it 'has a created account json' do
        header 'Authorization', "Bearer #{token}"
        post '/v1/accounts', params.to_json, provides: 'json'
        body = JSON.parse last_response.body
        expect(last_response.status).to eq 201
        expect(body['name']).to eq 'Foo'
      end
    end

    context 'with invalid params' do
      let(:without_name) { { password: '<PASSWORD>' } }

      it 'validates presence of name attribute' do
        header 'Authorization', "Bearer #{token}"
        post '/v1/accounts', without_name.to_json, provides: 'json'
        body = JSON.parse last_response.body
        expect(body['errors']).to eq "The following errors were found: Name can't be blank"
        expect(last_response.status).to eq 442
      end
    end
  end

  describe 'POST deposit' do
    context 'with valid params' do
      let(:id) { '123b' }
      let(:params) { { amount: 9.99 } }

      before do
        allow(Bank::Models::Account).to receive(:deposit).with(id, params[:amount])
      end

      it 'has a deposited json attribute' do
        header 'Authorization', "Bearer #{token}"
        post "/v1/accounts/#{id}/deposit", params.to_json, provides: 'json'
        body = JSON.parse last_response.body
        expect(body['deposited']).to eq true
      end
    end
  end

  describe 'POST withdraw' do
    context 'with valid params' do
      let(:id) { '123b' }
      let(:params) { { amount: 9.99 } }

      before do
        allow(Bank::Models::Account).to receive(:withdraw).with(id, params[:amount])
      end

      it 'has a deposited json attribute' do
        header 'Authorization', "Bearer #{token}"
        post "/v1/accounts/#{id}/withdraw", params.to_json, provides: 'json'
        body = JSON.parse last_response.body
        expect(body['withdrawn']).to eq true
      end
    end
  end

  describe 'POST transfer' do
    context 'with valid params' do
      let(:id) { '123b' }
      let(:params) { { to: '133c', amount: '9.99' } }

      before do
        allow(Bank::Models::Account).to receive(:transfer).with(id, params[:to], params[:amount])
      end

      it 'has a deposited json attribute' do
        header 'Authorization', "Bearer #{token}"
        post "/v1/accounts/#{id}/transfer", params.to_json, provides: 'json'
        body = JSON.parse last_response.body
        expect(body['transfered']).to eq true
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.13910211677134218, 'fraction_numerical': 0.012095836240986277, 'mean_word_length': 2.8290293855743545, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '4794579', 'n_tokens_mistral': 1375, 'n_tokens_neox': 1304, 'n_words': 358}