Skip to content

Commit caec64a

Browse files
committed
fix: updated validation when email permission is no
1 parent 2095b76 commit caec64a

2 files changed

Lines changed: 44 additions & 2 deletions

File tree

src/Model/SQS/MarketingPreference.model.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,8 @@ export default class MarketingPreference extends Model {
464464
const requestConstraintsClone = Object.assign({}, requestConstraints);
465465
if ((this.getPermissionEmail() !== null
466466
&& this.getPermissionEmail() !== ''
467-
&& this.getPermissionEmail() !== '0')
467+
&& this.getPermissionEmail() !== '0'
468+
&& this.getPermissionEmail() !== 0)
468469
|| (this.getEmail())) {
469470
if (this.getEmail()) {
470471
requestConstraintsClone.email = { email: true };

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

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ describe('Model/MarketingPreferencesModel', () => {
168168
transSource: 'giftaid-sportrelief',
169169
transSourceUrl: 'https://giftaid.sportrelief.com/',
170170
transType: 'prefs',
171-
permissionEmail: 0,
171+
permissionEmail: 1,
172172
permissionPost: 0,
173173
permissionPhone: 0,
174174
permissionSMS: 0,
@@ -279,6 +279,47 @@ describe('Model/MarketingPreferencesModel', () => {
279279
});
280280

281281

282+
describe('Ensure validation passes when email permission is NO', () => {
283+
const mockedData = {
284+
firstname: 'Kelvin',
285+
lastname: 'James',
286+
phone: '0208 254 3062',
287+
mobile: '07425253522',
288+
address1: 'COMIC RELIEF',
289+
address2: 'CAMELFORD HOUSE 87-90',
290+
address3: 'ALBERT EMBANKMENT',
291+
town: 'LONDON',
292+
postcode: 'SE1 7TP',
293+
country: 'GB',
294+
campaign: 'RND19',
295+
transactionId: 'AN129MNDJDJ',
296+
transSource: 'RND19_GiftAid',
297+
transSourceUrl: 'https://giftaid.sportrelief.com/',
298+
transType: 'prefs',
299+
confirm: 1,
300+
permissionEmail: 0,
301+
permissionPost: null,
302+
permissionPhone: null,
303+
permissionSMS: null,
304+
timestamp: '1562165588',
305+
};
306+
307+
const model = new MarketingPreferencesModel(mockedData);
308+
309+
it('should validate the model', (done) => {
310+
model.validate()
311+
.then(() => {
312+
expect(true).to.eql(true);
313+
done();
314+
})
315+
.catch((error) => {
316+
console.log('Error: ', error);
317+
expect(true).to.eql(false);
318+
done();
319+
});
320+
});
321+
});
322+
282323
describe('Ensure generating of timestamp when not set', () => {
283324

284325
const mockedData = {

0 commit comments

Comments
 (0)