Skip to content

Commit

Permalink
Test updates.
Browse files Browse the repository at this point in the history
  • Loading branch information
wjames111 committed Nov 22, 2024
1 parent e469dad commit 08b686e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ const componentName = 'checkoutExistingPaymentMethods'

class ExistingPaymentMethodsController {
/* @ngInject */
constructor ($log, $scope, orderService, cartService, $uibModal) {
constructor ($log, $scope, orderService, cartService, $uibModal, $window) {
this.$log = $log
this.$scope = $scope
this.orderService = orderService
this.cartService = cartService
this.$uibModal = $uibModal
this.paymentFormResolve = {}
this.validPaymentMethod = validPaymentMethod
this.sessionStorage = $window.sessionStorage

this.$scope.$on(SignInEvent, () => {
this.$onInit()
Expand All @@ -37,6 +38,7 @@ class ExistingPaymentMethodsController {
this.enableContinue({ $event: false })
this.loadPaymentMethods()
this.addCvvValidators()
console.log(this.sessionStorage)
}

$onChanges (changes) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ describe('checkout', () => {
expect(self.controller.orderService.storeCoverFeeDecision).not.toHaveBeenCalled()
})

it('should reset securityCode viewValue on switch payment', () => {
it('should reset securityCode viewValue', () => {
self.controller.creditCardPaymentForm.securityCode.$viewValue = '123'
self.controller.selectedPaymentMethod = { 'card-type': 'Visa', self: { type: 'cru.creditcards.named-credit-card', uri: 'selected uri' }, selectAction: 'some uri' }
self.controller.switchPayment()
Expand All @@ -356,30 +356,28 @@ describe('checkout', () => {

describe('addCvvValidators', () => {
it('should add validator functions to creditCardPaymentForm.securityCode', () => {
self.controller.addCvvValidators()

expect(Object.keys(self.controller.creditCardPaymentForm.securityCode.$validators).length).toEqual(2)
expect(typeof self.controller.creditCardPaymentForm.securityCode.$validators.minLength).toBe('function')
expect(typeof self.controller.creditCardPaymentForm.securityCode.$validators.maxLength).toBe('function')
})

it('should call enableContinue when validity state is true', () => {
it('should call enableContinue when cvv is valid', () => {
self.controller.creditCardPaymentForm.securityCode.$viewValue = '123'
self.controller.addCvvValidators()
self.controller.$scope.$apply()

expect(self.controller.enableContinue).toHaveBeenCalledWith({ $event: true })
})

it('should call enableContinue when validity state is too long', () => {
it('should call enableContinue when cvv is too long', () => {
self.controller.creditCardPaymentForm.securityCode.$viewValue = '12345'
self.controller.addCvvValidators()
self.controller.$scope.$apply()

expect(self.controller.enableContinue).toHaveBeenCalledWith({ $event: false })
})

it('should call enableContinue when validity state is too short', () => {
it('should call enableContinue when cvv is too short', () => {
self.controller.creditCardPaymentForm.securityCode.$viewValue = '1'
self.controller.addCvvValidators()
self.controller.$scope.$apply()
Expand Down
16 changes: 8 additions & 8 deletions src/app/checkout/step-2/step-2.component.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,61 +309,61 @@ describe('checkout', () => {
expect(self.controller.getContinueDisabled()).toBe(false)
})

it('should return true when cvv validity is false and card type is credit card', () => {
it('should return true when cvv is invalid and credit card is used', () => {
self.controller.handleExistingPaymentLoading(true, true)
self.controller.isCvvValid = false
self.controller.handlePaymentChange({'card-type': 'visa'})

expect(self.controller.getContinueDisabled()).toBe(true)
})

it('should return true when cvv validity is true and card type is credit card', () => {
it('should return true when cvv is valid and credit card is used', () => {
self.controller.handleExistingPaymentLoading(true, true)
self.controller.isCvvValid = true
self.controller.handlePaymentChange({'card-type': 'visa'})

expect(self.controller.getContinueDisabled()).toBe(false)
})

it('should return true when cvv validity is undefined and card type is credit card', () => {
it('should return true when cvv validity is undefined and credit card is used', () => {
self.controller.handleExistingPaymentLoading(true, true)
self.controller.isCvvValid = undefined
self.controller.handlePaymentChange({'card-type': 'visa'})

expect(self.controller.getContinueDisabled()).toBe(false)
})

it('should return false when cvv validity is false and card type is not credit card', () => {
it('should return false when cvv is invalid and credit card is used', () => {
self.controller.handleExistingPaymentLoading(true, true)
self.controller.isCvvValid = false
self.controller.handlePaymentChange({'account-type': 'checking'})

expect(self.controller.getContinueDisabled()).toBe(false)
})

it('should return false when cvv validity is undefined and card type is not credit card', () => {
it('should return false when cvv validity is undefined and EFT is used', () => {
self.controller.handleExistingPaymentLoading(true, true)
self.controller.isCvvValid = undefined
self.controller.handlePaymentChange({'account-type': 'checking'})

expect(self.controller.getContinueDisabled()).toBe(false)
})

it('should return false when cvv validity is true and card type is not credit card', () => {
it('should return false when cvv is valid and EFT is used', () => {
self.controller.handleExistingPaymentLoading(true, true)
self.controller.isCvvValid = true
self.controller.handlePaymentChange({'account-type': 'checking'})

expect(self.controller.getContinueDisabled()).toBe(false)
})

it('should return false when cvv is invalid and new payment type is credit card', () => {
it('should return false when cvv is invalid and new credit card payment is added', () => {
self.controller.handlePaymentChange({'card-type': 'visa'})
self.controller.isCvvValid = false
expect(self.controller.getContinueDisabled()).toBe(true)
})

it('should return false when cvv is invalid and new payment type is bankAccount', () => {
it('should return false when cvv is invalid and new EFT is added', () => {
self.controller.handlePaymentChange({'account-type': 'checking'})
self.controller.isCvvValid = false
expect(self.controller.getContinueDisabled()).toBe(false)
Expand Down

0 comments on commit 08b686e

Please sign in to comment.