All files BookInventory.js

100% Statements 13/13
100% Branches 6/6
100% Functions 5/5
100% Lines 13/13

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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61                        10x 10x 10x 10x       3x                     3x 3x 1x   2x 1x     1x                   4x                 2x      
// Inventory application for book store
// create book with title, author, isbn, numCopies
// getAvailability => no book out of stock, < 10 low stock & in stock otherwise
// sell(numSold = 1) if no numSold, sold is one
// restock(numCopies = 5)
 
/**
 * Represents a book
 * @constructor
*/
export default class BookInventory{
    constructor({title, author, isbn, numCopies}){
        this.title = title;
        this.author = author;
        this.isbn = isbn;
        this.numCopies = numCopies;
    }
 
    get availability(){
        return this.getAvailability();
    }
 
    /**
     * Method to know the book availability
     * 0 copies - 'out of stock'
     * less than 10 copies - 'low stock'
     * more than 10 copies - 'in stock'
     * returns string that represents number of copies available
    */
    getAvailability(){
        let numCopies = this.numCopies;
        if(numCopies === 0){
            return 'out of stock';
        }
        else if(numCopies < 10){
            return 'low stock';
        }
        else{
            return 'in stock';
        }
    }
 
    /**
     * Method to sell the book
     * @param numSold - integer of number of copies sold, default to 1
     * returns undefined
    */
    sell(numSold = 1){
        this.numCopies -= numSold;
    }
 
    /**
     * Method to restock the book
     * @param numCopies - integer of number of copies restocked, default to 5
     * returns undefined
    */
    restock(numCopies = 5){
        this.numCopies += numCopies;
    }
}