Skip to content

Commit

Permalink
Do not prematurely error on the invalid input
Browse files Browse the repository at this point in the history
  • Loading branch information
wrandall22 committed Oct 25, 2023
1 parent 4bb966f commit 480eebb
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -315,14 +315,7 @@ class ProductConfigFormController {
const data = this.omitIrrelevantData(this.itemConfig)
const comment = data.DONATION_SERVICES_COMMENTS
const isTestingTransaction = comment ? comment.toLowerCase().includes('test') : false
const transformedAmount = this.transformAmountIfNecessary(data.AMOUNT)
if (transformedAmount === 'error') {
this.submittingGift = false
this.errorSavingGeneric = true
this.onStateChange({ state: 'errorSubmitting' })
return
}
data.AMOUNT = transformedAmount
data.AMOUNT = this.transformAmountIfNecessary(data.AMOUNT)
this.brandedAnalyticsFactory.saveTestingTransaction(isTestingTransaction)
this.analyticsFactory.saveTestingTransaction(this.productData, isTestingTransaction)

Expand Down Expand Up @@ -372,7 +365,7 @@ class ProductConfigFormController {
transformedAmount = amount.replace('$', '')
transformedAmount = parseFloat(transformedAmount)
if (isNaN(transformedAmount)) {
return 'error'
return amount
}
}
return transformedAmount
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -728,17 +728,6 @@ describe('product config form component', function () {
expect($ctrl.errorAlreadyInCart).toEqual(false)
expect($ctrl.errorSavingGeneric).toEqual(false)
})

it('should fail if the amount is invalid', () => {
$ctrl.itemConfig.AMOUNT = 'test'
$ctrl.itemConfigForm.$dirty = true
$ctrl.saveGiftToCart()

expect($ctrl.submittingGift).toEqual(false)
expect($ctrl.onStateChange).toHaveBeenCalledWith({ state: 'errorSubmitting' })
expect($ctrl.errorAlreadyInCart).toEqual(false)
expect($ctrl.errorSavingGeneric).toEqual(true)
})
}
})

Expand Down Expand Up @@ -803,9 +792,9 @@ describe('product config form component', function () {
expect($ctrl.transformAmountIfNecessary(amount)).toEqual(50)
})

it('should return an error', () => {
it('should pass through the original amount', () => {
const amount = 'test'
expect($ctrl.transformAmountIfNecessary(amount)).toEqual('error')
expect($ctrl.transformAmountIfNecessary(amount)).toEqual('test')
})
})
})

0 comments on commit 480eebb

Please sign in to comment.