|
| 1 | +const totalLikes = require("../utils/list_helper").totalLikes; |
| 2 | + |
| 3 | +describe("get the total likes in a blog list", () => { |
| 4 | + const blogs = [ |
| 5 | + { |
| 6 | + _id: "5a422a851b54a676234d17f7", |
| 7 | + title: "React patterns", |
| 8 | + author: "Michael Chan", |
| 9 | + url: "https://reactpatterns.com/", |
| 10 | + likes: 7, |
| 11 | + __v: 0, |
| 12 | + }, |
| 13 | + { |
| 14 | + _id: "5a422aa71b54a676234d17f8", |
| 15 | + title: "Go To Statement Considered Harmful", |
| 16 | + author: "Edsger W. Dijkstra", |
| 17 | + url: |
| 18 | + "http://www.u.arizona.edu/~rubinson/copyright_violations/Go_To_Considered_Harmful.html", |
| 19 | + likes: 5, |
| 20 | + __v: 0, |
| 21 | + }, |
| 22 | + { |
| 23 | + _id: "5a422b3a1b54a676234d17f9", |
| 24 | + title: "Canonical string reduction", |
| 25 | + author: "Edsger W. Dijkstra", |
| 26 | + url: "http://www.cs.utexas.edu/~EWD/transcriptions/EWD08xx/EWD808.html", |
| 27 | + likes: 12, |
| 28 | + __v: 0, |
| 29 | + }, |
| 30 | + { |
| 31 | + _id: "5a422b891b54a676234d17fa", |
| 32 | + title: "First class tests", |
| 33 | + author: "Robert C. Martin", |
| 34 | + url: |
| 35 | + "http://blog.cleancoder.com/uncle-bob/2017/05/05/TestDefinitions.htmll", |
| 36 | + likes: 10, |
| 37 | + __v: 0, |
| 38 | + }, |
| 39 | + { |
| 40 | + _id: "5a422ba71b54a676234d17fb", |
| 41 | + title: "TDD harms architecture", |
| 42 | + author: "Robert C. Martin", |
| 43 | + url: |
| 44 | + "http://blog.cleancoder.com/uncle-bob/2017/03/03/TDD-Harms-Architecture.html", |
| 45 | + likes: 0, |
| 46 | + __v: 0, |
| 47 | + }, |
| 48 | + { |
| 49 | + _id: "5a422bc61b54a676234d17fc", |
| 50 | + title: "Type wars", |
| 51 | + author: "Robert C. Martin", |
| 52 | + url: "http://blog.cleancoder.com/uncle-bob/2016/05/01/TypeWars.html", |
| 53 | + likes: 2, |
| 54 | + __v: 0, |
| 55 | + }, |
| 56 | + ]; |
| 57 | + const blog = [ |
| 58 | + { |
| 59 | + _id: "5a422a851b54a676234d17f7", |
| 60 | + title: "React patterns", |
| 61 | + author: "Michael Chan", |
| 62 | + url: "https://reactpatterns.com/", |
| 63 | + likes: 7, |
| 64 | + __v: 0, |
| 65 | + }, |
| 66 | + ]; |
| 67 | + test("expects zero when list is empty", ()=>{ |
| 68 | + expect(totalLikes([])).toBe(0) |
| 69 | + }); |
| 70 | + |
| 71 | + test("when list has only one blog equals the likes of that", ()=>{ |
| 72 | + expect(totalLikes(blog)).toBe(7) |
| 73 | + }) |
| 74 | + |
| 75 | + test("with bigger list", ()=>{ |
| 76 | + expect(totalLikes(blogs)).toBe(36) |
| 77 | + }) |
| 78 | +}); |
0 commit comments