-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
solution 4.4: helper functions and unit tests, step2
- Loading branch information
1 parent
0f1a759
commit 2585dc7
Showing
3 changed files
with
88 additions
and
1 deletion.
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
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 |
---|---|---|
@@ -1,9 +1,85 @@ | ||
const listHelper = require('../utils/list_helper') | ||
|
||
// describe('test arrays', () => { | ||
test('dummy returns one', () => { | ||
const blogs = [] | ||
|
||
const result = listHelper.dummy(blogs) | ||
expect(result).toBe(1) | ||
}) | ||
|
||
describe('total likes', () => { | ||
test('of empty list is zero', () => { | ||
const blogs = [] | ||
const result = listHelper.totalLikes(blogs) | ||
expect(result).toBe(0) | ||
}) | ||
|
||
test('when list has only one blog equals the likes of that', () => { | ||
const blogs = [ | ||
{ | ||
_id: '23234323242dssfsf', | ||
title: 'Test 2nd blog title', | ||
author: 'Test of blog author', | ||
url: 'Test of blog url ', | ||
likes: 6, | ||
}, | ||
] | ||
const result = listHelper.totalLikes(blogs) | ||
expect(result).toBe(6) | ||
}) | ||
|
||
test('of a bigger list is calculated right', () => { | ||
const blogs = [ | ||
{ | ||
_id: '5a422a851b54a676234d17f7', | ||
title: 'React patterns', | ||
author: 'Michael Chan', | ||
url: 'https://reactpatterns.com/', | ||
likes: 7, | ||
__v: 0, | ||
}, | ||
{ | ||
_id: '5a422aa71b54a676234d17f8', | ||
title: 'Go To Statement Considered Harmful', | ||
author: 'Edsger W. Dijkstra', | ||
url: 'http://www.u.arizona.edu/~rubinson/copyright_violations/Go_To_Considered_Harmful.html', | ||
likes: 5, | ||
__v: 0, | ||
}, | ||
{ | ||
_id: '5a422b3a1b54a676234d17f9', | ||
title: 'Canonical string reduction', | ||
author: 'Edsger W. Dijkstra', | ||
url: 'http://www.cs.utexas.edu/~EWD/transcriptions/EWD08xx/EWD808.html', | ||
likes: 12, | ||
__v: 0, | ||
}, | ||
{ | ||
_id: '5a422b891b54a676234d17fa', | ||
title: 'First class tests', | ||
author: 'Robert C. Martin', | ||
url: 'http://blog.cleancoder.com/uncle-bob/2017/05/05/TestDefinitions.htmll', | ||
likes: 10, | ||
__v: 0, | ||
}, | ||
{ | ||
_id: '5a422ba71b54a676234d17fb', | ||
title: 'TDD harms architecture', | ||
author: 'Robert C. Martin', | ||
url: 'http://blog.cleancoder.com/uncle-bob/2017/03/03/TDD-Harms-Architecture.html', | ||
likes: 0, | ||
__v: 0, | ||
}, | ||
{ | ||
_id: '5a422bc61b54a676234d17fc', | ||
title: 'Type wars', | ||
author: 'Robert C. Martin', | ||
url: 'http://blog.cleancoder.com/uncle-bob/2016/05/01/TypeWars.html', | ||
likes: 2, | ||
__v: 0, | ||
}, | ||
] | ||
const result = listHelper.totalLikes(blogs) | ||
expect(result).toBe(36) | ||
}) | ||
}) |
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