-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathchallenge.test.js
41 lines (37 loc) · 1.18 KB
/
challenge.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
const { faker } = require("@faker-js/faker");
const { addReview } = require("./objects");
describe("🌶️🌶️🌶️ Challenge", () => {
let book;
let newReview;
beforeEach(() => {
book = {
title: faker.book.title(),
author: faker.book.author(),
publishedYear: faker.date.past().getFullYear(),
genre: faker.book.genre(),
};
newReview = {
reviewer: faker.person.fullName(),
comment: faker.lorem.sentence(),
};
});
describe("addReview", () => {
it("should add a review to an exist array of reviews", () => {
book.reviews = [
{
reviewer: faker.person.fullName(),
comment: faker.lorem.sentence(),
},
];
const { reviewer, comment } = newReview;
const updatedBook = addReview(book, reviewer, comment);
expect(updatedBook.reviews).toContainEqual(newReview);
expect(updatedBook.reviews.length).toBe(2);
});
it("should create a review array if one didn't already exist", () => {
const { reviewer, comment } = newReview;
const updatedBook = addReview(book, reviewer, comment);
expect(updatedBook.reviews).toContainEqual(newReview);
});
});
});