Skip to content

Commit

Permalink
Merge branch 'master' into hideCvv-flag
Browse files Browse the repository at this point in the history
  • Loading branch information
wjames111 authored Oct 28, 2024
2 parents b5d6941 + 9199bf8 commit 2fff68d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 17 deletions.
17 changes: 9 additions & 8 deletions src/app/checkout/checkout.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,10 @@ class CheckoutController {
changeStep (newStep, replace) {
switch (newStep) {
case 'cart':
this.$window.location.href = `/cart.html${this.buildQueryStringWithoutStep()}`
this.$window.location.href = `/cart.html${this.buildRedirectQueryString()}`
break
case 'thankYou':
this.$location.search('step', null)
this.$window.location.href = `/thank-you.html${this.buildQueryStringWithoutStep()}`
this.$window.location.href = `/thank-you.html${this.buildRedirectQueryString()}`
break
default:
this.$window.scrollTo(0, 0)
Expand All @@ -102,17 +101,19 @@ class CheckoutController {
}
}

buildQueryStringWithoutStep () {
buildRedirectQueryString () {
let queryString = ''
let index = 0
this.$location.search('step', null)
Object.entries(this.$location.search()).forEach(([key, value]) => {
if (index === 0) {
// remove step and email from query string
if (key === 'step' || key === 'e') {
return
}

if (queryString === '') {
queryString += `?${key}=${value}`
} else {
queryString += `&${key}=${value}`
}
index++
})
return queryString
}
Expand Down
13 changes: 4 additions & 9 deletions src/app/checkout/checkout.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ describe('checkout', function () {
it('should watch the url and update the state', () => {
jest.spyOn(self.controller, 'initStepParam').mockImplementation(() => {})
jest.spyOn(self.controller.cartService, 'get').mockReturnValue(Observable.of('cartData'))
jest.spyOn(self.controller.analyticsFactory, 'checkoutStepEvent').mockImplementation(() => {})
jest.spyOn(self.controller.analyticsFactory, 'checkoutStepEvent').mockImplementation(() => {})
self.controller.listenForLocationChange()
self.controller.$location.search('step', 'review')
self.controller.$rootScope.$digest()
Expand Down Expand Up @@ -197,21 +197,16 @@ describe('checkout', function () {
const searchObject = {
one: '1',
two: '2',
step: 'review'
step: 'review',
e: 'bill.bright@cru.org'
}
mockSearch(searchObject)
self.controller.changeStep('thankYou')
expect(self.controller.$window.location.href).toEqual('/thank-you.html?one=1&two=2')
})

const mockSearch = (searchObject) => {
jest.spyOn(self.controller.$location, 'search').mockImplementation((key) => {
if (key === 'step') {
delete searchObject.step
} else if (!key) {
return searchObject
}
})
jest.spyOn(self.controller.$location, 'search').mockReturnValue(searchObject)
}
})

Expand Down

0 comments on commit 2fff68d

Please sign in to comment.