All files transactionManager.js

100% Statements 13/13
100% Branches 4/4
100% Functions 5/5
100% Lines 12/12

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    11x       9x 9x 9x       5x   5x 1x     4x       3x 3x 3x       2x
class TransactionManager{
    constructor(){
        this.transactions = [];
    }
 
    logBorrowTransaction(transaction, transactionID){
        transaction.ID = transactionID || Math.floor(Math.random() * 10000);
        this.transactions.push(transaction);
        return transaction;
    }
 
    findTransaction(transactionID){
        let foundTransaction = this.transactions.find((transaction) => transaction.ID == transactionID);
 
        if(foundTransaction == undefined){
            throw new Error(`Transaction with ID ${transactionID} not found`);
        }
 
        return foundTransaction;
    }
 
    logReturnTransaction(transactionID){
        const transaction = this.findTransaction(transactionID);
        transaction.returnDate = new Date();
        return transaction;
    }
}
 
module.exports = TransactionManager;