All files inventory.js

100% Statements 17/17
83.33% Branches 10/12
100% Functions 7/7
100% Lines 16/16

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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    14x       12x       30x       8x 8x       9x   9x 1x     8x 1x     7x 7x         3x 3x 3x         2x
class Inventory {
    constructor() {
        this.books = [];
    }
 
    addBook(book) { // Receive a book object and add it to the inventory
        this.books.push(book);
    }
 
    findBookByISBN(ISBN) {
        return this.books.find(book => book.ISBN === ISBN);
    }
 
    isAvailable(ISBN) {
        const book = this.findBookByISBN(ISBN);
        return book && book.copies > 0;
    }
 
    reduceCopy(ISBN) {
        const book = this.findBookByISBN(ISBN);
 
        if (!book) {
            throw new Error(`Book with ISBN ${ISBN} not found.`);
        }
 
        if (book.copies === 0) {
            throw new Error(`No copies available for book with ISBN ${ISBN}.`);
        }
 
        Eif (book && book.copies > 0) {
            book.copies -= 1;
        }
    }
 
    increaseCopy(ISBN) {
        const book = this.findBookByISBN(ISBN);
        Eif (book) {
            book.copies += 1;
        }
    }
}
 
module.exports = Inventory;