-
-
Notifications
You must be signed in to change notification settings - Fork 215
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
refactor: email test cases #276
Closed
Closed
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
31e2d67
refactor: email test cases
ariskemper 1d408fa
refactor: group passing and rejecting tests
ariskemper f0b4697
refactor: add parse utlity method for tests
ariskemper 0b048d0
refactor: rename utility method due to conflict with schema method
ariskemper 28764fb
refactor: reverted regex, removed tests
ariskemper 73b7fc4
refactor: remove parseValidation, add tests with +
ariskemper 1ae7006
refactor: expectation in email tests
ariskemper 6fdfa67
Merge branch 'main' into refactor-email-test
fabian-hiller 934dd80
Improve tests of email validation action
fabian-hiller File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,60 +2,200 @@ import { describe, expect, test } from 'vitest'; | |
import { email } from './email.ts'; | ||
|
||
describe('email', () => { | ||
test('should pass only emails', () => { | ||
const validate = email(); | ||
|
||
const value1 = '[email protected]'; | ||
expect(validate._parse(value1).output).toBe(value1); | ||
const value2 = '[email protected]'; | ||
expect(validate._parse(value2).output).toBe(value2); | ||
const value3 = '[email protected]'; | ||
expect(validate._parse(value3).output).toBe(value3); | ||
const value4 = '[email protected]'; | ||
expect(validate._parse(value4).output).toBe(value4); | ||
const value5 = '[email protected]'; | ||
expect(validate._parse(value5).output).toBe(value5); | ||
const value6 = '[email protected]'; | ||
expect(validate._parse(value6).output).toBe(value6); | ||
const value7 = '[email protected]'; | ||
expect(validate._parse(value7).output).toBe(value7); | ||
const value8 = '[email protected]'; | ||
expect(validate._parse(value8).output).toBe(value8); | ||
const value9 = '[email protected]'; | ||
expect(validate._parse(value9).output).toBe(value9); | ||
const value10 = '[email protected]'; | ||
expect(validate._parse(value10).output).toBe(value10); | ||
const value11 = '[email protected]'; | ||
expect(validate._parse(value11).output).toBe(value11); | ||
const value12 = '[email protected]'; | ||
expect(validate._parse(value12).output).toBe(value12); | ||
|
||
expect(validate._parse('plainaddress').issues).toBeTruthy(); | ||
expect(validate._parse('#@%^%#$@#$@#.com').issues).toBeTruthy(); | ||
expect(validate._parse('@example.com').issues).toBeTruthy(); | ||
expect( | ||
validate._parse('Joe Smith <[email protected]>').issues | ||
).toBeTruthy(); | ||
expect(validate._parse('email.example.com').issues).toBeTruthy(); | ||
expect(validate._parse('email@[email protected]').issues).toBeTruthy(); | ||
expect(validate._parse('[email protected]').issues).toBeTruthy(); | ||
expect(validate._parse('[email protected]').issues).toBeTruthy(); | ||
expect(validate._parse('[email protected]').issues).toBeTruthy(); | ||
expect(validate._parse('あいうえお@example.com').issues).toBeTruthy(); | ||
expect( | ||
validate._parse('[email protected] (Joe Smith)').issues | ||
).toBeTruthy(); | ||
expect(validate._parse('email@example').issues).toBeTruthy(); | ||
expect(validate._parse('[email protected]').issues).toBeTruthy(); | ||
expect(validate._parse('[email protected]').issues).toBeTruthy(); | ||
expect(validate._parse('[email protected]').issues).toBeTruthy(); | ||
expect(validate._parse('[email protected]').issues).toBeTruthy(); | ||
expect(validate._parse('[email protected]').issues).toBeTruthy(); | ||
describe('should return action object', () => { | ||
test('should contain the default message', () => { | ||
expect(email()).toMatchObject({ | ||
type: 'email', | ||
async: false, | ||
message: 'Invalid email', | ||
requirement: expect.any(RegExp), | ||
_parse: expect.any(Function), | ||
}); | ||
}); | ||
|
||
test('should contain the message argument', () => { | ||
const message = 'Custom message'; | ||
expect(email(message)).toMatchObject({ | ||
type: 'email', | ||
async: false, | ||
message: message, | ||
requirement: expect.any(RegExp), | ||
_parse: expect.any(Function), | ||
}); | ||
}); | ||
}); | ||
|
||
describe('should return action output', () => { | ||
test('should pass standard email', () => { | ||
const value = '[email protected]'; | ||
expect(email()._parse(value)).toEqual({ output: value }); | ||
}); | ||
|
||
test('should pass email with country code top level domain', () => { | ||
const value = '[email protected]'; | ||
expect(email()._parse(value)).toEqual({ output: value }); | ||
}); | ||
|
||
test('should pass email with dot in local part', () => { | ||
const value = '[email protected]'; | ||
expect(email()._parse(value)).toEqual({ output: value }); | ||
}); | ||
|
||
test('should pass email with hyphen in local part', () => { | ||
const value = '[email protected]'; | ||
expect(email()._parse(value)).toEqual({ output: value }); | ||
}); | ||
|
||
test('should pass email with plus in local part', () => { | ||
const value = '[email protected]'; | ||
expect(email()._parse(value)).toEqual({ output: value }); | ||
}); | ||
|
||
test('should pass email with plus in end of local part', () => { | ||
const value = '[email protected]'; | ||
expect(email()._parse(value)).toEqual({ output: value }); | ||
}); | ||
|
||
test('should pass email with plus in begining of local part', () => { | ||
const value = '[email protected]'; | ||
expect(email()._parse(value)).toEqual({ output: value }); | ||
}); | ||
|
||
test('should pass email with hyphen in domain part', () => { | ||
const value = '[email protected]'; | ||
expect(email()._parse(value)).toEqual({ output: value }); | ||
}); | ||
|
||
test('should pass email with long top level domain', () => { | ||
const value = '[email protected]'; | ||
expect(email()._parse(value)).toEqual({ output: value }); | ||
}); | ||
|
||
test('should pass email with numerical local part', () => { | ||
const value = '[email protected]'; | ||
expect(email()._parse(value)).toEqual({ output: value }); | ||
}); | ||
|
||
test('should pass email with numerical local part', () => { | ||
const value = '[email protected]'; | ||
expect(email()._parse(value)).toEqual({ output: value }); | ||
}); | ||
|
||
test('should pass email with subdomain', () => { | ||
const value = '[email protected]'; | ||
expect(email()._parse(value)).toEqual({ output: value }); | ||
}); | ||
|
||
test('should pass email with subdomain and hyphen in domain', () => { | ||
const value = '[email protected]'; | ||
expect(email()._parse(value)).toEqual({ output: value }); | ||
}); | ||
|
||
test('should pass email with subdomain and country code top level domain', () => { | ||
const value = '[email protected]'; | ||
expect(email()._parse(value)).toEqual({ output: value }); | ||
}); | ||
|
||
test('should pass email with short domain and top level domain', () => { | ||
const value = '[email protected]'; | ||
expect(email()._parse(value)).toEqual({ output: value }); | ||
}); | ||
|
||
test('should pass email with numeric domain and top level domain', () => { | ||
const value = '[email protected]'; | ||
expect(email()._parse(value)).toEqual({ output: value }); | ||
}); | ||
}); | ||
|
||
test('should return custom error message', () => { | ||
const error = 'Value is not an email!'; | ||
const validate = email(error); | ||
expect(validate._parse('test').issues?.[0].message).toBe(error); | ||
describe('should return action issue', () => { | ||
test('should reject email with missing @ symbol', () => { | ||
const value = 'example.com'; | ||
expect(email()._parse(value).issues).toBeTruthy(); | ||
}); | ||
|
||
test('should reject email with missing domain', () => { | ||
const value = '[email protected]'; | ||
expect(email()._parse(value).issues).toBeTruthy(); | ||
}); | ||
|
||
test('should reject email with special chars in top level domain', () => { | ||
const value = '#@%^%#$@#$@#.com'; | ||
expect(email()._parse(value).issues).toBeTruthy(); | ||
}); | ||
|
||
test('should reject email with no top-level domain', () => { | ||
const value = 'email@example'; | ||
expect(email()._parse(value).issues).toBeTruthy(); | ||
}); | ||
|
||
test('should reject email with numeric top-level domain', () => { | ||
const value = '[email protected]'; | ||
expect(email()._parse(value).issues).toBeTruthy(); | ||
}); | ||
|
||
test('should reject email with only domain', () => { | ||
const value = '@example.com'; | ||
expect(email()._parse(value).issues).toBeTruthy(); | ||
}); | ||
|
||
test('should reject email with only local part', () => { | ||
const value = 'email@'; | ||
expect(email()._parse(value).issues).toBeTruthy(); | ||
}); | ||
|
||
test('should reject email with spaces', () => { | ||
const value = ' [email protected] '; | ||
expect(email()._parse(value).issues).toBeTruthy(); | ||
}); | ||
|
||
test('should reject email with multiple @ symbols', () => { | ||
const value = ' email@@example.com '; | ||
expect(email()._parse(value).issues).toBeTruthy(); | ||
}); | ||
|
||
test('should reject email where domain consists from numerical values', () => { | ||
const value = '[email protected]'; | ||
expect(email()._parse(value).issues).toBeTruthy(); | ||
}); | ||
|
||
test('should reject email where local part consists of non ASCII chars', () => { | ||
const value = 'あいうえお@example.com'; | ||
expect(email()._parse(value).issues).toBeTruthy(); | ||
}); | ||
|
||
test('should reject email where local part begin with dot', () => { | ||
const value = '[email protected]'; | ||
expect(email()._parse(value).issues).toBeTruthy(); | ||
}); | ||
|
||
test('should reject email where local part end with special char', () => { | ||
const value = '[email protected]'; | ||
expect(email()._parse(value).issues).toBeTruthy(); | ||
}); | ||
|
||
test('should reject email where domain part end with special char', () => { | ||
const value = '[email protected]'; | ||
expect(email()._parse(value).issues).toBeTruthy(); | ||
}); | ||
|
||
test('should reject email where domain part end with special char', () => { | ||
const value = '[email protected]'; | ||
expect(email()._parse(value).issues).toBeTruthy(); | ||
}); | ||
|
||
test('should reject email where two dots separate in local part', () => { | ||
const value = '[email protected]'; | ||
expect(email()._parse(value).issues).toBeTruthy(); | ||
}); | ||
|
||
test('should reject email where name is represented in front of email', () => { | ||
const value = 'Joe Smith <[email protected]>'; | ||
expect(email()._parse(value).issues).toBeTruthy(); | ||
}); | ||
|
||
test('should reject email where name is represented after email', () => { | ||
const value = '[email protected] (Joe Smith)'; | ||
expect(email()._parse(value).issues).toBeTruthy(); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is
.toMatchObject()
less strict than.toEqual()
? Why do you choose it here?