poli1993_

Warehouse

Jan 18th, 2020
260
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. describe('PaymentPackage', function () {
  2.     function getInstance() {
  3.         return new Warehouse(100);
  4.     }
  5.     it("Test if class properties exists", function () {
  6.         let inst = getInstance();
  7.         expect(Object.getPrototypeOf(inst).hasOwnProperty('capacity')).to.be.equal(true);
  8.         expect(Object.getPrototypeOf(inst).hasOwnProperty('constructor')).to.be.equal(true);
  9.         expect(typeof Warehouse).to.be.equal('function');
  10.     });
  11.     it('capacity to throw with negative num', function () {
  12.         expect(() => {
  13.             let inst = new Warehouse(-100);
  14.         }).to.throw();
  15.     });
  16.     it('capacity to throw with zero', function () {
  17.         expect(() => {
  18.             let inst = new Warehouse(0);
  19.         }).to.throw();
  20.     });
  21.     it("should have a getter property 'capacity'", function () {
  22.         const paymentPackage = getInstance()
  23.         expect(paymentPackage.capacity).to.equal(100)
  24.     });
  25.  
  26.     it("should have a setter property 'capacity'", function () {
  27.         const paymentPackage = getInstance();
  28.         paymentPackage.capacity = 10;
  29.         expect(paymentPackage.capacity).to.equal(10);
  30.     });
  31.     describe('warehouse add products tests',function(){
  32.         it('add product should add product and return it\'s name',function(){
  33.             let warehouse =  getInstance();
  34.             let product = 'rice';
  35.             let type ='Food';
  36.             let quantity = 5;
  37.             let productObject = {
  38.                 'rice':quantity
  39.             }
  40.             let result = warehouse.addProduct(type,product,quantity);
  41.             expect(productObject).to.deep.equal(result);
  42.         });
  43.         it('add product should take right amount of capacity',function(){
  44.             let capacity = 10;
  45.             let warehouse = new Warehouse(capacity);
  46.             let product ='rice';
  47.             let type = 'Food';
  48.             let quantity = 5;
  49.            
  50.             warehouse.addProduct(type,product,quantity);
  51.             let takenSpace = warehouse.occupiedCapacity();
  52.             let spaceThatShouldBeTaken = capacity - quantity;
  53.             expect(takenSpace).to.equal(spaceThatShouldBeTaken);
  54.         });
  55.  
  56.         it('add product should add product and increase its quantity if exists',function(){
  57.             let warehouse = getInstance();
  58.             let product = 'rice';
  59.             let type = 'Food';
  60.             let quantity = 5;      
  61.      
  62.             warehouse.addProduct(type,product,quantity);
  63.             warehouse.addProduct(type,product,quantity);
  64.             let riceQuantity = warehouse.availableProducts.Food[product];
  65.             let expectedQuantity = quantity * 2;
  66.             expect(riceQuantity).to.equal(expectedQuantity);
  67.         });
  68.  
  69.         it('add product should throw string if not enough capacity',function(){
  70.  
  71.             expect(function(){
  72.                 let warehouse = new Warehouse(5);
  73.                 let product = 'rice';
  74.                 let type = 'Food';
  75.                 let quantity = 10;
  76.                
  77.                 warehouse.addProduct(type,product,quantity);
  78.             }).to.throw('There is not enough space or the warehouse is already full');
  79.         });
  80.     })
  81.     describe('warehouse sort products test',function(){
  82.  
  83.         it('sort products should sort products of the type descending',function(){
  84.             let warehouse = getInstance();
  85.             let productOne ='rice';
  86.             let productType = 'Food';
  87.             let productOneQuantity = 10;
  88.             let productTwo = 'bread';
  89.             let productTwoQuantity = 5;
  90.             warehouse.addProduct(productType,productOne,productOneQuantity);
  91.             warehouse.addProduct(productType,productTwo,productTwoQuantity);
  92.             let result = warehouse.orderProducts(productType);
  93.             let expectedOrder = {'rice':10,'bread':5};
  94.             expect(result).to.deep.equal(expectedOrder);    
  95.         });
  96. });
  97. describe('warehouse revision tests',function(){
  98.  
  99.     it('revision should return empty warehouse message',function(){
  100.         let warehouse = getInstance();
  101.         let revision = warehouse.revision();
  102.         let expectedOutput = 'The warehouse is empty';
  103.         expect(revision).to.equal(expectedOutput);
  104.     });
  105.  
  106.     it('revision should return  ordered list',function(){
  107.         let warehouse = getInstance();
  108.         let productOne = 'rice';
  109.         let productType = 'Food';
  110.         let productTypeTwo = 'Drink';
  111.         let productOneQuantity = 10;
  112.         let productTwo = 'bread';
  113.         let productTwoQuantity = 5;
  114.         warehouse.addProduct(productType,productOne,productOneQuantity);
  115.         warehouse.addProduct(productType,productTwo,productTwoQuantity);
  116.         let revision = warehouse.revision();
  117.         let expectedOutput =`Product type - [${productType}]\n`+
  118.         `- ${productOne} ${productOneQuantity}\n`+
  119.         `- ${productTwo} ${productTwoQuantity}\n`+
  120.         `Product type - [${productTypeTwo}]\n`;
  121.         let expected = expectedOutput.trim();
  122.         expect(revision).to.equal(expected);
  123.     });
  124. });
  125.  
  126. describe('warehouse scrape a product tests',function(){
  127.  
  128.     it('it should return nonexisting product',function(){
  129.         const noneExistingType ="wine";
  130.         let expectedResult = `${noneExistingType} do not exists`;      
  131.         expect(function(){
  132.             let warehouse = getInstance();
  133.             let productOne ='rice';
  134.             let productType ='Food';
  135.             let productOneQuantity = 10;
  136.             let productTwo ='bread';
  137.             let productTwoQuantity = 5;          
  138.             warehouse.addProduct(productType,productOne,productOneQuantity);
  139.             warehouse.addProduct(productType,productTwo,productTwoQuantity);
  140.             warehouse.scrapeAProduct(noneExistingType,5);          
  141.         }).to.throw(expectedResult)
  142.  
  143.     });
  144.  
  145.     it('it should reset amount of the product with not enough quantity',function(){
  146.         let warehouse = getInstance();
  147.         let product ='rice';
  148.         let productType ='Food';
  149.         let productQuantity = 5;
  150.         let productWantedQuantity = 10;          
  151.         warehouse.addProduct(productType,product,productQuantity);
  152.         warehouse.scrapeAProduct(product,productWantedQuantity);
  153.         let currentCountProduct = warehouse.availableProducts.Food[product];
  154.         const expectedCount = 0;
  155.         expect(currentCountProduct).to.equal(expectedCount);          
  156.     });
  157.  
  158.     it('it should return correct quantity of the product',function(){
  159.         let warehouse = getInstance();
  160.         let product ='rice';
  161.         let productType ='Food';
  162.         let productQuantity = 10;
  163.         let productWantedQuantity = 5;          
  164.         warehouse.addProduct(productType,product,productQuantity);
  165.         warehouse.scrapeAProduct(product,productWantedQuantity);
  166.         let currentCountProduct = warehouse.availableProducts.Food[product];
  167.         const expectedCount = 5;
  168.         expect(currentCountProduct).to.equal(expectedCount);          
  169.     });
  170. })
  171. })
RAW Paste Data