Removed invalid and duplicate email validations in members importer

This commit is contained in:
Nazar Gargol 2020-07-09 17:55:40 +12:00
parent 3086ac1439
commit bcfc3792cd
2 changed files with 4 additions and 34 deletions

View File

@ -61,14 +61,7 @@ export default Service.extend({
})); }));
} else { } else {
// check can be done on whole set as it won't be too slow // check can be done on whole set as it won't be too slow
const {invalidCount, emptyCount, duplicateCount} = this._checkEmails(data, mapping); const {emptyCount} = this._checkEmails(data, mapping);
if (invalidCount) {
// @TODO: Remove error from displayed errors
validationErrors.push(new MemberImportError({
message: `Invalid email address (${formatNumber(invalidCount)})`,
type: 'warning'
}));
}
if (emptyCount) { if (emptyCount) {
validationErrors.push(new MemberImportError({ validationErrors.push(new MemberImportError({
@ -76,14 +69,6 @@ export default Service.extend({
type: 'warning' type: 'warning'
})); }));
} }
if (duplicateCount) {
// @TODO: Remove error from displayed errors
validationErrors.push(new MemberImportError({
message: `Duplicate email address (${formatNumber(duplicateCount)})`,
type: 'warning'
}));
}
} }
return {validationErrors, mapping}; return {validationErrors, mapping};
@ -184,29 +169,15 @@ export default Service.extend({
_checkEmails(validatedSet, mapping) { _checkEmails(validatedSet, mapping) {
let emptyCount = 0; let emptyCount = 0;
let invalidCount = 0;
let duplicateCount = 0;
let emailMap = {};
validatedSet.forEach((member) => { validatedSet.forEach((member) => {
let emailValue = member[mapping.email]; let emailValue = member[mapping.email];
if (!emailValue) { if (!emailValue) {
emptyCount += 1; emptyCount += 1;
} }
if (emailValue && !validator.isEmail(emailValue)) {
invalidCount += 1;
} else if (emailValue) {
if (emailMap[emailValue]) {
emailMap[emailValue] += 1;
duplicateCount += 1;
} else {
emailMap[emailValue] = 1;
}
}
}); });
return {invalidCount, emptyCount, duplicateCount}; return {emptyCount};
}, },
_countStripeRecors(validatedSet, mapping) { _countStripeRecors(validatedSet, mapping) {

View File

@ -77,7 +77,7 @@ describe('Integration: Service: member-import-validator', function () {
expect(validationErrors[0].message).to.equal('No email addresses found in the uploaded CSV.'); expect(validationErrors[0].message).to.equal('No email addresses found in the uploaded CSV.');
}); });
it('returns validation error for invalid email', async function () { it('ignores validation for invalid email', async function () {
this.owner.register('service:membersUtils', Service.extend({ this.owner.register('service:membersUtils', Service.extend({
isStripeEnabled: false isStripeEnabled: false
})); }));
@ -90,8 +90,7 @@ describe('Integration: Service: member-import-validator', function () {
email: 'email@example.com' email: 'email@example.com'
}]); }]);
expect(validationErrors.length).to.equal(1); expect(validationErrors.length).to.equal(0);
expect(validationErrors[0].message).to.equal('Invalid email address (1)');
}); });
describe('data sampling method', function () { describe('data sampling method', function () {