All files library.js

100% Statements 14/14
100% Branches 2/2
100% Functions 3/3
100% Lines 14/14

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 311x       6x 6x       7x 6x 6x   6x 6x   6x   1x         2x 2x   2x       1x
const Transaction = require("./transaction");
 
class Library {
    constructor(inventory, transactionManager) {
        this.inventory = inventory;
        this.transactionManager = transactionManager;
    }
 
    borrowBook(ISBN, borrowedDate) {
        if (this.inventory.isAvailable(ISBN)) {
            let book = this.inventory.findBookByISBN('002-555-362');
            let initTransaction = new Transaction(book, borrowedDate);
            
            let borrowedTransaction = this.transactionManager.logBorrowTransaction(initTransaction);
            this.inventory.reduceCopy(ISBN);
 
            return borrowedTransaction;
        }else{
            throw new Error("Book isn't available");           
        }
    }
 
    returnBook(ISBN, transactionID) {
        const returnedBookTransaction = this.transactionManager.logReturnTransaction(transactionID);        
        this.inventory.increaseCopy(ISBN);
 
        return returnedBookTransaction;
    }
}
 
module.exports = Library;