Skip to content

Commit

Permalink
fix: catch decimal error and return fail (GoogleCloudPlatform#548)
Browse files Browse the repository at this point in the history
* fix: catch decimal error and return fail

* test: temporarily point to runcible runner

* test: update pylintrc

* lint: make snake case

* fix: remove invalid test

* test: point to new ci

Co-authored-by: Olivier Bourgeois <[email protected]>
Co-authored-by: Christine Kim <[email protected]>
  • Loading branch information
3 people authored Jan 11, 2022
1 parent 980f85e commit 03e91e1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 13 deletions.
10 changes: 0 additions & 10 deletions .github/workflows/ui-tests/cypress/integration/transfer_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,16 +191,6 @@ describe('Transfer is unsuccessful with invalid data', function () {
cy.get('.invalid-feedback').contains(invalidFeedback.payment)
})

// TODO: [issue-182]
it.skip('cannot contain more than 2 decimal digits', function () {
const invalidPayment = `5\.02\.35\.459`

cy.transfer(recipient, invalidPayment)
cy.get('.invalid-feedback').should('be.visible')
cy.get('.invalid-feedback').contains(invalidFeedback.payment)

})

it('cannot reference invalid account', function () {
const invalidRecipient = {
accountNum: randomInt(100,10000000),
Expand Down
2 changes: 1 addition & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ disable=F0401, # import loading
R1732, # consider-using-with
W1514, # unspecified-encoding
C0209, # consider-using-f-string
R1734 # use-list-literal
R1734 # use-list-literal
9 changes: 7 additions & 2 deletions src/frontend/frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import logging
import os
import socket
from decimal import Decimal
from decimal import Decimal, DecimalException

import requests
from requests.exceptions import HTTPError, RequestException
Expand Down Expand Up @@ -206,11 +206,13 @@ def payment():
app.config['LOCAL_ROUTING'],
False)

user_input = request.form['amount']
payment_amount = int(Decimal(user_input) * 100)
transaction_data = {"fromAccountNum": account_id,
"fromRoutingNum": app.config['LOCAL_ROUTING'],
"toAccountNum": recipient,
"toRoutingNum": app.config['LOCAL_ROUTING'],
"amount": int(Decimal(request.form['amount']) * 100),
"amount": payment_amount,
"uuid": request.form['uuid']}
_submit_transaction(transaction_data)
app.logger.info('Payment initiated successfully.')
Expand All @@ -228,6 +230,9 @@ def payment():
msg=msg,
_external=True,
_scheme=app.config['SCHEME']))
except (ValueError, DecimalException) as num_err:
app.logger.error('Error submitting payment: %s', str(num_err))
msg = 'Payment failed: {} is not a valid number'.format(user_input)

return redirect(url_for('home',
msg='Payment failed',
Expand Down

0 comments on commit 03e91e1

Please sign in to comment.