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

Adding feature to whitelist domains and disallow as default behavior #12

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

mimil
Copy link

@mimil mimil commented Oct 12, 2023

Adding feature to whitelist domains and disallow as default behavior if no other rule has matched.

A new config option as been added:

  • defaultType (String) Define the default behavior when a domain didn't match any rules, you can choose between valid or invalid (default is valid)

Here are tests added:

describe('Default validation should be configurable', () => {
    const ev = new EmailValidation()
    it('should say domain random.com is invalid because default validation is not set to accept, normally random.com should have been accepted', () => {
      ev.setOptions({ defaultType: 'invalid' })
      const result = ev.check('[email protected]')
      expect(result).to.be.an('object')
      expect(result.valid).eq(false)
      expect(result.errors[0]).eq('invalid')
    })
    it('should say domain random.com is valid because random.com has been whitelisted despite of default validation is not set to accept', () => {
      ev.setOptions({ defaultType: 'invalid', whitelist:['random.com'] })
      const result = ev.check('[email protected]')
      expect(result).to.be.an('object')
      expect(result.valid).eq(true)
    })
  })

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants