Advertisement
Guest User

Untitled

a guest
Jan 17th, 2018
72
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. let c = new Cart([items[0], items[1]]);
  45. describe("Cart", function() {
  46.     describe("getCart()", function() {
  47.         it("make sure the variable is instance of cart", function() {
  48.             expect(c).to.be.an.instanceOf(Cart);
  49.         });
  50.     });
  51.  
  52.     describe("freeShipping()", function() {
  53.         it("free shipping should return true when total is greater than 750", function() {
  54.             fullCart = new Cart(items);
  55.             expect(fullCart.freeShipping()).to.be.true;
  56.             expect(c.freeShipping()).to.be.false;
  57.         });
  58.     });
  59. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement