Skip to content

Commit 14bd0c3

Browse files
committed
fix: email permission validations
1 parent d59e915 commit 14bd0c3

2 files changed

Lines changed: 5 additions & 5 deletions

File tree

src/Model/SQS/MarketingPreference.model.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -466,14 +466,13 @@ export default class MarketingPreference extends Model {
466466
&& this.getPermissionEmail() !== ''
467467
&& this.getPermissionEmail() !== '0')
468468
|| this.getEmail() !== '') {
469-
if (this.getEmail() !== '') {
469+
if (this.getEmail() !== '' && this.getEmail() !== null) {
470470
requestConstraintsClone.email = { email: true };
471471
} else {
472-
requestConstraintsClone.email = { presence: { allowEmpty: false } };
472+
requestConstraintsClone.email = { presence: { allowEmpty: false }, email: true };
473473
}
474474
}
475475
// Update constraints if fields are not empty
476-
477476
requestConstraintsClone.firstname = this.getFirstName() !== null && this.getFirstName() !== '' ? { format: { pattern: "[a-zA-Z.'-_ ]+", flags: 'i', message: 'can only contain alphabetical characters' } } : '';
478477
requestConstraintsClone.lastname = this.getLastName() !== null && this.getLastName() !== '' ? { format: { pattern: "[a-zA-Z.'-_ ]+", flags: 'i', message: 'can only contain alphabetical characters' } } : '';
479478
requestConstraintsClone.phone = this.getPhone() !== null && this.getPhone() !== '' ? { format: { pattern: '[0-9 ]+', flags: 'i', message: 'can only contain numerical characters' } } : '';

tests/unit/Model/SQS/MarketingPreferences.model.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,7 @@ describe('Model/MarketingPreferencesModel', () => {
168168
transSource: 'giftaid-sportrelief',
169169
transSourceUrl: 'https://giftaid.sportrelief.com/',
170170
transType: 'prefs',
171-
email: '',
172-
permissionEmail: 1,
171+
permissionEmail: 0,
173172
permissionPost: 0,
174173
permissionPhone: 0,
175174
permissionSMS: 0,
@@ -185,6 +184,8 @@ describe('Model/MarketingPreferencesModel', () => {
185184
done();
186185
})
187186
.catch((error) => {
187+
console.log('Error: ', error);
188+
188189
expect(error instanceof ResponseModel).to.eql(true);
189190
expect(error.getCode()).to.eql(400);
190191
expect(error.body.validation_errors.email[0]).to.eql('Email can\'t be blank');

0 commit comments

Comments
 (0)