Skip to content

Commit 563e4cf

Browse files
committed
fix validation
1 parent 76a69d5 commit 563e4cf

File tree

4 files changed

+30
-9
lines changed

4 files changed

+30
-9
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "deep-email-validator",
3-
"version": "0.1.9",
3+
"version": "0.1.11",
44
"files": [
55
"dist/**/*"
66
],

src/output/output.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export const createOutput = (
2929
const levelOut: SubOutputFormat = { valid }
3030
if (level === failLevel) {
3131
valid = false
32+
levelOut.valid = false
3233
levelOut.reason = failReason
3334
}
3435
out.validators[level] = levelOut

test/__snapshots__/index.test.ts.snap

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Object {
1616
},
1717
"smtp": Object {
1818
"reason": "The mail address that you specified was not syntactically correct.",
19-
"valid": true,
19+
"valid": false,
2020
},
2121
"typo": Object {
2222
"valid": true,
@@ -35,7 +35,7 @@ Object {
3535
},
3636
"mx": Object {
3737
"reason": "MX record not found",
38-
"valid": true,
38+
"valid": false,
3939
},
4040
"regex": Object {
4141
"valid": true,
@@ -66,7 +66,7 @@ Object {
6666
},
6767
"smtp": Object {
6868
"reason": "Invalid Mailbox",
69-
"valid": true,
69+
"valid": false,
7070
},
7171
"typo": Object {
7272
"valid": true,
@@ -91,7 +91,7 @@ Object {
9191
},
9292
"smtp": Object {
9393
"reason": "Invalid Mailbox",
94-
"valid": true,
94+
"valid": false,
9595
},
9696
"typo": Object {
9797
"valid": true,
@@ -113,7 +113,7 @@ Object {
113113
},
114114
"regex": Object {
115115
"reason": "Invalid regex",
116-
"valid": true,
116+
"valid": false,
117117
},
118118
"smtp": Object {
119119
"valid": false,
@@ -144,7 +144,7 @@ Object {
144144
},
145145
"typo": Object {
146146
"reason": "Likely typo, suggested email: [email protected]",
147-
"valid": true,
147+
"valid": false,
148148
},
149149
},
150150
}
@@ -157,7 +157,7 @@ Object {
157157
"validators": Object {
158158
"disposable": Object {
159159
"reason": "Email was created using a disposable email service",
160-
"valid": true,
160+
"valid": false,
161161
},
162162
"mx": Object {
163163
"valid": false,

test/index.test.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import values from 'lodash/values'
2+
import every from 'lodash/every'
13
import { validate } from '../src/index'
24

35
const elevenSeconds = 11 * 1000
@@ -6,6 +8,8 @@ describe('validation tests', () => {
68
it('fails with bad regex', async () => {
79
const res = await validate('dav [email protected]')
810
expect(res.valid).toBe(false)
11+
expect(res.reason).toBe('regex')
12+
expect(res.validators.regex?.valid).toBe(false)
913
expect(res).toMatchSnapshot()
1014
})
1115

@@ -15,18 +19,25 @@ describe('validation tests', () => {
1519
validateRegex: false,
1620
})
1721
expect(res.valid).toBe(false)
22+
expect(res.reason).toBe('smtp')
23+
expect(res.validators.regex?.valid).toBe(true)
24+
expect(res.validators.smtp?.valid).toBe(false)
1825
expect(res).toMatchSnapshot()
1926
})
2027

2128
it('fails with common typo', async () => {
2229
const res = await validate('[email protected]')
2330
expect(res.valid).toBe(false)
31+
expect(res.reason).toBe('typo')
32+
expect(res.validators.typo?.valid).toBe(false)
2433
expect(res).toMatchSnapshot()
2534
})
2635

2736
it('fails with disposable email', async () => {
2837
const res = await validate('[email protected]')
2938
expect(res.valid).toBe(false)
39+
expect(res.reason).toBe('disposable')
40+
expect(res.validators.disposable?.valid).toBe(false)
3041
expect(res).toMatchSnapshot()
3142
})
3243

@@ -35,6 +46,8 @@ describe('validation tests', () => {
3546
async () => {
3647
const res = await validate('[email protected]')
3748
expect(res.valid).toBe(false)
49+
expect(res.reason).toBe('mx')
50+
expect(res.validators.mx?.valid).toBe(false)
3851
expect(res).toMatchSnapshot()
3952
},
4053
elevenSeconds
@@ -43,6 +56,8 @@ describe('validation tests', () => {
4356
it('fails with bad mailbox', async () => {
4457
const res = await validate('[email protected]')
4558
expect(res.valid).toBe(false)
59+
expect(res.reason).toBe('smtp')
60+
expect(res.validators.smtp?.valid).toBe(false)
4661
expect(res).toMatchSnapshot()
4762
})
4863

@@ -51,6 +66,8 @@ describe('validation tests', () => {
5166
async () => {
5267
const res = await validate('[email protected]')
5368
expect(res.valid).toBe(false)
69+
expect(res.reason).toBe('smtp')
70+
expect(res.validators.smtp?.valid).toBe(false)
5471
expect(res).toMatchSnapshot()
5572
},
5673
elevenSeconds
@@ -63,7 +80,8 @@ describe('validation tests', () => {
6380
6481
validateSMTP: false,
6582
})
66-
83+
expect(res.valid).toBe(true)
84+
expect(every(values(res.validators), x => x && x.valid)).toBe(true)
6785
expect(res).toMatchSnapshot()
6886
},
6987
elevenSeconds
@@ -74,6 +92,7 @@ describe('validation tests', () => {
7492
async () => {
7593
const res = await validate('[email protected]')
7694
expect(res.valid).toBe(true)
95+
expect(every(values(res.validators), x => x && x.valid)).toBe(true)
7796
expect(res).toMatchSnapshot()
7897
},
7998
elevenSeconds
@@ -84,6 +103,7 @@ describe('validation tests', () => {
84103
async () => {
85104
const res = await validate('[email protected]')
86105
expect(res.valid).toBe(true)
106+
expect(every(values(res.validators), x => x && x.valid)).toBe(true)
87107
expect(res).toMatchSnapshot()
88108
},
89109
elevenSeconds

0 commit comments

Comments
 (0)