-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaccounts.test.js
More file actions
60 lines (51 loc) · 1.88 KB
/
Copy pathaccounts.test.js
File metadata and controls
60 lines (51 loc) · 1.88 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
const { expect } = require("chai");
const {
findAccountById,
sortAccountsByLastName,
getTotalNumberOfBorrows,
getBooksPossessedByAccount,
} = require("../public/src/accounts.js");
const accountsFixture = require("./fixtures/accounts.fixture");
const authorsFixture = require("./fixtures/authors.fixture");
const booksFixture = require("./fixtures/books.fixture");
describe("Accounts Page", () => {
let accounts;
let authors;
let books;
beforeEach(() => {
accounts = accountsFixture.slice();
authors = authorsFixture.slice();
books = booksFixture.slice();
});
describe("findAccountById()", () => {
it("should return the account object when given a particular ID", () => {
const account = accounts[3];
const actual = findAccountById(accounts, account.id);
expect(actual).to.eql(account);
});
});
describe("sortAccountsByLastName()", () => {
it("should return the list of accounts ordered by last name", () => {
const [first, second] = sortAccountsByLastName(accounts);
expect(first.name.last).to.eql("Ball");
expect(second.name.last).to.eql("Banks");
});
});
describe("getTotalNumberOfBorrows()", () => {
it("should return the number of times an account has created a 'borrow' record", () => {
const account = accounts[0];
const actual = getTotalNumberOfBorrows(account, books);
expect(actual).to.equal(2);
});
});
describe("getBooksPossessedByAccount()", () => {
it("should return all of the books taken out by an account with the author embedded", () => {
const account = accounts[4];
const actual = getBooksPossessedByAccount(account, books, authors);
expect(actual.length).to.equal(1);
const book = actual[0];
expect(book.author.name).to.eql({ first: "Giles", last: "Barlow" });
expect(book.title).to.equal("esse ea veniam non occaecat");
});
});
});