Skip to content

Commit

Permalink
Merge pull request #973 from CruGlobal/HS-756593-fix-campaign-code-ha…
Browse files Browse the repository at this point in the history
…ndling

HS-756593 - Fix campaign code handling
  • Loading branch information
wrandall22 authored Jun 7, 2022
2 parents 9f1f1c8 + 1e937c7 commit e1dc880
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
nodejs 16.0.0
yarn 1.22.17
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import isArray from 'lodash/isArray'
import productConfigForm from '../productConfigForm/productConfigForm.component'
import { giveGiftParams } from '../giveGiftParams'
import modalStateService from 'common/services/modalState.service'
import designationsService from 'common/services/api/designations.service'
import { mobileBreakpoint } from 'common/app.constants'

import template from './productConfig.modal.tpl.html'
Expand All @@ -12,10 +13,11 @@ const componentName = 'productConfigModal'

class ProductConfigModalController {
/* @ngInject */
constructor ($window, $location, modalStateService) {
constructor ($window, $location, modalStateService, designationsService) {
this.$window = $window
this.$location = $location
this.modalStateService = modalStateService
this.designationsService = designationsService
}

$onInit () {
Expand Down Expand Up @@ -72,6 +74,10 @@ class ProductConfigModalController {
this.itemConfig['recurring-start-month'] = params[giveGiftParams.month]
}

if (Object.prototype.hasOwnProperty.call(params, giveGiftParams.campaignPage) && params[giveGiftParams.campaignPage] !== '') {
this.itemConfig['campaign-page'] = params[giveGiftParams.campaignPage]
}

// If CampaignCode exists in URL, use it, otherwise use default-campaign-code if set.
if (Object.prototype.hasOwnProperty.call(params, giveGiftParams.campaignCode)) {
this.itemConfig['campaign-code'] = isArray(params[giveGiftParams.campaignCode])
Expand All @@ -84,10 +90,12 @@ class ProductConfigModalController {
}
} else if (Object.prototype.hasOwnProperty.call(this.itemConfig, 'default-campaign-code')) {
this.itemConfig['campaign-code'] = this.itemConfig['default-campaign-code']
}

if (Object.prototype.hasOwnProperty.call(params, giveGiftParams.campaignPage) && params[giveGiftParams.campaignPage] !== '') {
this.itemConfig['campaign-page'] = params[giveGiftParams.campaignPage]
} else if (this.itemConfig['campaign-page']) {
// make sure we call the code to pull the default campaign code when going straight to the modal
this.designationsService.suggestedAmounts(this.code, this.itemConfig)
.subscribe(null, null, () => {
this.itemConfig['campaign-code'] = this.itemConfig['default-campaign-code']
})
}
}

Expand All @@ -114,7 +122,8 @@ export default angular
.module(componentName, [
'ordinal',
productConfigForm.name,
modalStateService.name
modalStateService.name,
designationsService.name
])
.component(componentName, {
controller: ProductConfigModalController,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import module from './productConfig.modal.component'
import { giveGiftParams } from '../giveGiftParams'
import 'rxjs/add/observable/of'
import 'rxjs/add/observable/throw'
import { Observable } from 'rxjs/Observable'

describe('product config modal', function () {
beforeEach(angular.mock.module(module.name))
Expand All @@ -21,6 +22,9 @@ describe('product config modal', function () {
},
modalStateService: {
name: jest.fn()
},
designationsService: {
suggestedAmounts: jest.fn()
}
},
{
Expand Down Expand Up @@ -79,6 +83,7 @@ describe('product config modal', function () {
describe('initializeParams', () => {
beforeEach(() => {
jest.spyOn($ctrl, 'updateQueryParam').mockImplementation(() => {})
jest.spyOn($ctrl.designationsService, 'suggestedAmounts').mockReturnValue(Observable.of([]))
$ctrl.itemConfig = {}
})

Expand Down Expand Up @@ -157,6 +162,18 @@ describe('product config modal', function () {
expect($ctrl.itemConfig['campaign-code']).toEqual('DEFAULT')
})

it('sets the campaignCode from default-campaign-code if opening from modal directly', () => {
$ctrl.itemConfig['campaign-page'] = 'some-page'

jest.spyOn($ctrl.designationsService, 'suggestedAmounts').mockImplementation(() => {
$ctrl.itemConfig['default-campaign-code'] = 'DEFAULT'
return Observable.from([])
})
expect($ctrl.itemConfig['campaign-code']).toBeUndefined()
$ctrl.initializeParams()
expect($ctrl.itemConfig['campaign-code']).toEqual('DEFAULT')
})

it('cleans campaignCode if containing invalid characters', () => {
$ctrl.$location.search.mockReturnValue({
[giveGiftParams.campaignCode]: 'LEGACY?vid=3408342..fj039jf08ajs&kdljfi3lniclisgw5DFS4'
Expand Down

0 comments on commit e1dc880

Please sign in to comment.