Advertisement
Guest User

Untitled

a guest
Jan 17th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //assume this is a database
  2. let items = [
  3.     {
  4.         name: "GPU",
  5.         price: 500
  6.     },
  7.     {
  8.         name: "CPU",
  9.         price: 200
  10.     },
  11.     {
  12.         name: "RAM",
  13.         price: 80
  14.     }
  15. ];
  16.  
  17. class Cart {
  18.     constructor(cartItems) {
  19.         this.cartItems = cartItems;
  20.     }
  21.  
  22.     freeShipping() {
  23.         if (this.getTotal() >= 750) {
  24.             return true;
  25.         } else {
  26.             return false;
  27.         }
  28.     }
  29.  
  30.     getCart() {
  31.         return this.cartItems;
  32.     }
  33.  
  34.     getTotal() {
  35.         let total = 0;
  36.         for (let item of this.cartItems) {
  37.             total += item.price;
  38.         }
  39.         return total;
  40.     }
  41. }
  42.  
  43. ///////////////////////////////////////
  44.  
  45. let c = new Cart([items[0], items[1]]);
  46.  
  47. describe("Cart", function() {
  48.     describe("getCart()", function() {
  49.         it("make sure the variable is instance of cart", function() {
  50.             expect(c).to.be.an.instanceOf(Cart);
  51.         });
  52.     });
  53.  
  54.     describe("freeShipping()", function() {
  55.         it("free shipping should return true when total is greater than 750", function() {
  56.             fullCart = new Cart(items);
  57.             expect(fullCart.freeShipping()).to.be.true;
  58.             expect(c.freeShipping()).to.be.false;
  59.         });
  60.     });
  61.  
  62.     describe("constructor", () => {
  63.         it("cart items should be an array", function() {
  64.             assert.typeOf(c.getCart(), "array");
  65.         });
  66.     });
  67. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement