44 lines
1.1 KiB
JavaScript
44 lines
1.1 KiB
JavaScript
|
|
const { test, describe } = require("node:test");
|
||
|
|
const assert = require("node:assert");
|
||
|
|
const { favoritePost } = require("../src/utils");
|
||
|
|
|
||
|
|
describe("favoritePost ", () => {
|
||
|
|
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,
|
||
|
|
},
|
||
|
|
];
|
||
|
|
|
||
|
|
const emptyArray = [];
|
||
|
|
|
||
|
|
const gibberish = "asdaSd123asd";
|
||
|
|
|
||
|
|
test("finds top properly", () => {
|
||
|
|
assert.strictEqual(favoritePost(posts), posts[0]);
|
||
|
|
});
|
||
|
|
|
||
|
|
test("works fine with empty array", () => {
|
||
|
|
assert.strictEqual(favoritePost(emptyArray), null);
|
||
|
|
});
|
||
|
|
|
||
|
|
test("fails with gibberish input", () => {
|
||
|
|
const failedCall = () => {
|
||
|
|
favoritePost(gibberish);
|
||
|
|
};
|
||
|
|
assert.throws(failedCall, Error);
|
||
|
|
});
|
||
|
|
});
|