-
Notifications
You must be signed in to change notification settings - Fork 0
HW#7_Khyzhniak #24
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
Open
dmytro-khyzhniak
wants to merge
6
commits into
master
Choose a base branch
from
HW#7_Khyzhniak
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
HW#7_Khyzhniak #24
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7682516
Added MVP of HW
dmytro-khyzhniak 93be4fc
Added mock for async function that is fetching third-party API
dmytro-khyzhniak 4e182d1
Removed old files
dmytro-khyzhniak 64db8b2
Destination of the package.json was changed, dependencies was frozen.
dmytro-khyzhniak 56c2ea1
Removed old package
dmytro-khyzhniak ff0dafe
Fixed all issues
dmytro-khyzhniak 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| node_modules/ |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| async function getUsers() { | ||
| return (await fetch('https://jsonplaceholder.typicode.com/users')).json(); | ||
| } | ||
|
|
||
| exports.getUsers = getUsers; |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| function validateEmail(email) { | ||
| return /^\s*\w{5,}@[a-z]+\.[a-z]+\s*$/i.test(email); | ||
| } | ||
|
|
||
| class User { | ||
| constructor (firstName = 'Homer', lastName = 'Simpson') { | ||
| this.firstName = firstName; | ||
| this.lastName = lastName; | ||
| } | ||
|
|
||
| getFullName() { | ||
| return `${this.firstName} ${this.lastName}`; | ||
| } | ||
| } | ||
|
|
||
| function getUsersEmails(users) { | ||
| return users.map(user => user.email); | ||
| } | ||
|
|
||
| module.exports = { validateEmail, User, getUsersEmails}; |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,136 @@ | ||
| const {describe, test, expect, beforeAll} = require('@jest/globals'); | ||
| const {validateEmail, User, getUsersEmails} = require('./Functions.js'); | ||
| const {getUsers} = require('./Async-functions.js'); | ||
|
|
||
| const validEmailsToCheck = [ | ||
| 'example@gmail.com', | ||
| 'EXAMPLE@GMAIL.COM', | ||
| 'ExAmPlE@mail.ru', | ||
| ' example@gmail.com ', | ||
| ' example@gmail.com', | ||
| 'example@gmail.com ', | ||
| 'exmpl@mail.ru', | ||
| 'example12@gmail.com', | ||
| '12example@gmail.com', | ||
| ]; | ||
|
|
||
| const invalidEmailsToCheck = [ | ||
| 'exmp@gmail.ru', | ||
| 'exm@mail.ru', | ||
| 'example @gmail.com', | ||
| 'example@gmail. com', | ||
| 'example@mailru', | ||
| 'exmple@mailru.', | ||
| '.example@mailru', | ||
| 'exm@.mailru', | ||
| 'exm@.', | ||
| 'examplemail.ua', | ||
| '@examplemail.ua', | ||
| 'examplemail.ua@', | ||
| 'example@12gmail.com', | ||
| 'example@gmail.12', | ||
| 'ex!ample@gmail.com', | ||
| 'ex?ample@gmail.com', | ||
| 'ex,ample@gmail.com', | ||
| 'ex@..a@mple@gmail.com', | ||
| 'ex.ample@gmail.com' | ||
| ]; | ||
|
|
||
| describe('Testing function validateEmail with different emails.', () => { | ||
| describe('Should return true with valid emails.', () => { | ||
| test('Returns true for valid emails.', () => { | ||
| for (const email of validEmailsToCheck) { | ||
| expect(validateEmail(email)).toBe(true); | ||
| } | ||
| }); | ||
| }); | ||
|
|
||
| describe('Should return false with invalid emails.', () => { | ||
| test('Returns false for invalid emails.', () => { | ||
| for (const email of invalidEmailsToCheck) { | ||
| expect(validateEmail(email)).toBe(false); | ||
| } | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe('Testing class User.', () => { | ||
| describe('Passing both arguments to the User constructor.', () => { | ||
| const user = new User('Dmytro', 'Khyzhniak'); | ||
|
|
||
| test('Returned object properties and values are correct.', () => { | ||
| expect(user).toEqual({ | ||
| firstName: 'Dmytro', | ||
| lastName: 'Khyzhniak' | ||
| }); | ||
| }); | ||
|
|
||
| test('Method getFullName() returns correct result.', () => { | ||
| expect(user.getFullName()).toBe('Dmytro Khyzhniak'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('Passing only one argument to the User constructor. Checking default values.', () => { | ||
| const user = new User('Dmytro'); | ||
|
|
||
| test('Returned object properties and values are correct.', () => { | ||
| expect(user).toEqual({ | ||
| firstName: 'Dmytro', | ||
| lastName: 'Simpson' | ||
| }); | ||
| }); | ||
|
|
||
| test('Method getFullName() returns correct result.', () => { | ||
| expect(user.getFullName()).toBe('Dmytro Simpson'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('Passing no arguments to the User constructor. Checking default values.', () => { | ||
| const user = new User(); | ||
|
|
||
| test('Returned object properties and values are correct.', () => { | ||
| expect(user).toEqual({ | ||
| firstName: 'Homer', | ||
| lastName: 'Simpson' | ||
| }); | ||
| }); | ||
|
|
||
| test('Method getFullName() returns correct result.', () => { | ||
| expect(user.getFullName()).toBe('Homer Simpson'); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| jest.mock('./Async-functions.js') | ||
|
|
||
| describe('Testing function getUsersEmails()', () => { | ||
| let users, usersEmails; | ||
|
|
||
| beforeAll(async () => { | ||
| await getUsers().then(response => { | ||
| users = response; | ||
| }); | ||
|
|
||
| usersEmails = getUsersEmails(users); | ||
| }); | ||
|
|
||
| test('Returned value is an Array and it`s length > 0', () => { | ||
| expect(Array.isArray(usersEmails)).toBe(true); | ||
| expect(usersEmails.length).toBeGreaterThan(0); | ||
| }); | ||
|
|
||
| test('Returned array contains only strings and it`s length > 0', () => { | ||
| for (const email of usersEmails) { | ||
| expect(typeof email === "string").toBe(true); | ||
| expect(email.length).toBeGreaterThan(0); | ||
| } | ||
| }); | ||
|
|
||
| test('Returned strings matching RegExp for validating emails', () => { | ||
| for (const email of usersEmails) { | ||
| expect(email).toEqual( | ||
| expect.stringMatching(/^\s*[\w\.]{5,}@[a-z]+\.[a-z]+\s*$/i) | ||
| ); | ||
| } | ||
| }) | ||
| }); | ||
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.
better store name in common constant