Skip to content

Commit

Permalink
Merge branch 'strip-dollar-sign' into staging
Browse files Browse the repository at this point in the history
  • Loading branch information
wrandall22 committed Oct 25, 2023
2 parents 06822bf + 13c2e86 commit c95ab94
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ class ProductConfigFormController {
const data = this.omitIrrelevantData(this.itemConfig)
const comment = data.DONATION_SERVICES_COMMENTS
const isTestingTransaction = comment ? comment.toLowerCase().includes('test') : false
data.AMOUNT = this.transformAmountIfNecessary(data.AMOUNT)
this.brandedAnalyticsFactory.saveTestingTransaction(isTestingTransaction)
this.analyticsFactory.saveTestingTransaction(this.productData, isTestingTransaction)

Expand Down Expand Up @@ -379,6 +380,13 @@ class ProductConfigFormController {
})
}

transformAmountIfNecessary (amount) {
if (!angular.isNumber(amount)) {
return amount.replace('$', '')
}
return amount
}

displayId () {
if (!this.productData) {
return ''
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,22 @@ describe('product config form component', function () {
$ctrl.saveGiftToCart()
}
})

it('should transform the amount', () => {
$ctrl.itemConfig.AMOUNT = '$85'
$ctrl.itemConfigForm.$dirty = true
const overrideArgs = isEdit
? ['uri', 'items/crugive/<some id>', { AMOUNT: '85' }]
: ['items/crugive/<some id>', { AMOUNT: '85' }, undefined]
$ctrl.saveGiftToCart()

expect($ctrl.submittingGift).toEqual(false)
expect($ctrl.cartService[operation]).toHaveBeenCalledWith(...overrideArgs)
expect($ctrl.$scope.$emit).toHaveBeenCalledWith(cartEvent)
expect($ctrl.onStateChange).toHaveBeenCalledWith({ state: 'submitted' })
expect($ctrl.errorAlreadyInCart).toEqual(false)
expect($ctrl.errorSavingGeneric).toEqual(false)
})
}
})

Expand Down Expand Up @@ -762,4 +778,31 @@ describe('product config form component', function () {
expect($ctrl.$window.location).toEqual('https://example.com')
})
})

describe('transformAmountIfNecessary', () => {
it('should not change the int amount', () => {
const amount = '5'
expect($ctrl.transformAmountIfNecessary(amount)).toEqual(amount)
})

it('should not change the float amount', () => {
const amount = '5.12'
expect($ctrl.transformAmountIfNecessary(amount)).toEqual(amount)
})

it('should remove the $', () => {
const amount = '$50'
expect($ctrl.transformAmountIfNecessary(amount)).toEqual('50')
})

it('should not strip other characters', () => {
const amount = '23,00'
expect($ctrl.transformAmountIfNecessary(amount)).toEqual(amount)
})

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

0 comments on commit c95ab94

Please sign in to comment.