Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EP-2378 Require amount to be submitted for recurring self-service #987

Open
wants to merge 6 commits into
base: ep-upgrade
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import giftListItem from 'common/components/giftViews/giftListItem/giftListItem.
import giftUpdateView from 'common/components/giftViews/giftUpdateView/giftUpdateView.component'

import donationsService from 'common/services/api/donations.service'
import { allGiftsValid } from 'common/services/giftHelpers/giftValidator.service'

import template from './editRecurringGifts.tpl.html'

Expand Down Expand Up @@ -38,8 +39,8 @@ class EditRecurringGiftsController {
}
}

allPaymentMethodsValid () {
return every(this.recurringGifts, gift => gift.paymentMethod)
allGiftsValid () {
return allGiftsValid(this.recurringGifts)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,26 +50,10 @@ describe('editRecurringGiftsModal', () => {
})
})

describe('allPaymentMethodsValid', () => {
beforeEach(() => {
RecurringGiftModel.paymentMethods = [
{
self: { uri: '/selfservicepaymentinstruments/crugive/giydgnrxgm=' }
}
]
})

it('should return true if all payment methods are valid', () => {
self.controller.recurringGifts = [new RecurringGiftModel({}).setDefaults(), new RecurringGiftModel({}).setDefaults()]

expect(self.controller.allPaymentMethodsValid()).toEqual(true)
})

it('should return false if any payment methods is invalid', () => {
self.controller.recurringGifts = [new RecurringGiftModel({}).setDefaults(), new RecurringGiftModel({}).setDefaults()]
self.controller.recurringGifts[0].paymentMethodId = 'something invalid'

expect(self.controller.allPaymentMethodsValid()).toEqual(false)
describe('allGiftsValid', () => {
it('should call the GiftValidator service', () => {
self.controller.allGiftsValid()
expect(allGiftsValid).toHaveBeenCalled()
})
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ <h3 translate>Make changes to your recurring gifts</h3>
<a class="btn btn-primary" ng-if="$ctrl.loadingError" ng-click="$ctrl.loadGifts()" translate>Retry</a>
<a class="btn btn-primary" ng-if="!$ctrl.loadingError"
ng-click="$ctrl.next({ recurringGifts: $ctrl.recurringGifts })"
ng-disabled="!$ctrl.allPaymentMethodsValid()"
ng-disabled="!$ctrl.allGiftsValid()"
translate>
Continue
</a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@ import angular from 'angular'
import giftListItem from 'common/components/giftViews/giftListItem/giftListItem.component'
import giftUpdateView from 'common/components/giftViews/giftUpdateView/giftUpdateView.component'

import { allGiftsValid } from 'common/services/giftHelpers/giftValidator.service'
import template from './configureRecentRecipients.tpl.html'

const componentName = 'step3ConfigureRecentRecipients'

class ConfigureRecentRecipientsController {
/* @ngInject */
constructor () /* eslint-disable-line no-useless-constructor */ {}

allGiftsValid () {
return allGiftsValid(//Somehow I need to get access to the recurring gifts here??)
}
}

export default angular
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ <h3 translate>Set up your new recurring gifts</h3>
</a>
</div>
<div class="col-xs-6 text-right">
<button class="btn btn-primary" ng-click="$ctrl.next({ additions: $ctrl.additions })" translate>Continue</button>
<button class="btn btn-primary"
ng-click="$ctrl.next({ additions: $ctrl.additions })"
ng-disabled="!$ctrl.allGiftsValid()"
translate>Continue</button>
</div>
</div>
5 changes: 5 additions & 0 deletions src/common/services/giftHelpers/giftValidator.service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

export function allGiftsValid (recurringGifts) {
return every(recurringGifts, gift => gift.paymentMethod) && every(recurringGifts, gift => gift.amount)
}

30 changes: 30 additions & 0 deletions src/common/services/giftHelpers/giftValidator.service.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

import * as giftValidator from './giftValidator.service'
import RecurringGiftModel from 'common/models/recurringGift.model'

describe('giftValidator service', () => {

describe('allGiftsValid', () => {
beforeEach(() => {
RecurringGiftModel.amount = 50
recurringGifts = [new RecurringGiftModel({}).setDefaults(), new RecurringGiftModel({}).setDefaults()]
})

it('should return true if all payment methods and all amounts are valid', () => {
expect(giftValidator.allGiftsValid(recurringGifts)).toEqual(true)
})

it('should return false if any payment method is invalid', () => {

recurringGifts[0].paymentMethodId = 'something invalid'

expect(giftValidator.allGiftsValid(recurringGifts)).toEqual(false)
})

it('should return false if any amount is invalid', () => {
recurringGifts[0].amount = ''

expect(giftValidator.allGiftsValid(recurringGifts)).toEqual(false)
})
})
})