exercise 4.6 completed
This commit is contained in:
parent
0309a2cc95
commit
e51f318929
3 changed files with 75 additions and 0 deletions
54
parts/4/blogApp/tests/mostPosts.test.js
Normal file
54
parts/4/blogApp/tests/mostPosts.test.js
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
const { test, describe } = require("node:test");
|
||||
const assert = require("node:assert");
|
||||
const { mostPosts } = require("../src/utils");
|
||||
|
||||
describe("most posts ", () => {
|
||||
const posts = [
|
||||
{
|
||||
_id: "5a422aa71b54a676234d17f8",
|
||||
title: "Go To Statement Considered Harmful",
|
||||
author: "Edsger W. Dijkstra",
|
||||
url: "https://homepages.cwi.nl/~storm/teaching/reader/Dijkstra68.pdf",
|
||||
likes: 5,
|
||||
__v: 0,
|
||||
},
|
||||
{
|
||||
_id: "5a422aa71b54a676234d17f8",
|
||||
title: "Go To Statement Considered Harmful",
|
||||
author: "Edsger W. Dijkstra",
|
||||
url: "https://homepages.cwi.nl/~storm/teaching/reader/Dijkstra68.pdf",
|
||||
likes: 2,
|
||||
__v: 0,
|
||||
},
|
||||
{
|
||||
_id: "123",
|
||||
title: "Lololo",
|
||||
author: "John Doe",
|
||||
url: "https://homepages.cwi.nl/~storm/teaching/reader/Dijkstra68.pdf",
|
||||
likes: 1,
|
||||
__v: 0,
|
||||
},
|
||||
];
|
||||
|
||||
const emptyArray = [];
|
||||
|
||||
const gibberish = "asdaSd123asd";
|
||||
|
||||
test("finds top author properly", () => {
|
||||
assert.deepStrictEqual(mostPosts(posts), {
|
||||
author: "Edsger W. Dijkstra",
|
||||
posts: 2,
|
||||
});
|
||||
});
|
||||
|
||||
test("works fine with empty array", () => {
|
||||
assert.strictEqual(mostPosts(emptyArray), null);
|
||||
});
|
||||
|
||||
test("fails with gibberish input", () => {
|
||||
const failedCall = () => {
|
||||
mostPosts(gibberish);
|
||||
};
|
||||
assert.throws(failedCall, Error);
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue