poli1993_

Warehouse

Apr 15th, 2020
332
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. describe('Warehouse', function() {
  2.     let warehouse;
  3.       beforeEach(function () {
  4.           warehouse = new Warehouse(20);
  5.       });      
  6.            it('Test valid constructor', function () {
  7.               expect(warehouse.capacity).to.equal(20);
  8.            })
  9.            it('Test invalid constructor', function () {
  10.               expect(() => new Warehouse(-20)).to.throw();
  11.               expect(() => new Warehouse(0)).to.throw();
  12.               expect(() => new Warehouse('s')).to.throw();
  13.            })        
  14.                    
  15.            it('Test revision functionality', function () {
  16.               expect(warehouse.revision()).to.be.equal('The warehouse is empty');
  17.               warehouse.addProduct('Food','bread',5);
  18.               warehouse.addProduct('Drink','coke',6);
  19.               warehouse.addProduct('Food','meat',7);
  20.               const check = 'Product type - [Food]\n'+
  21.               '- bread 5\n'+
  22.               '- meat 7\n'+            
  23.               'Product type - [Drink]\n'+
  24.               '- coke 6';
  25.               const otput = warehouse.revision();
  26.               expect(otput).to.equal(check);
  27.            })      
  28.            it("Throw error if product is not found", function () {
  29.               expect(() => warehouse.scrapeAProduct('coke',15)).to.throw('coke do not exists');
  30.            })
  31.           });
  32.  
  33.           describe('Add and Sort Warehouse', function() {          
  34.                    it('Test sort functionality', function () {
  35.                     const house = new Warehouse(20);
  36.                     house.addProduct('Food','bread',5);
  37.                     house.addProduct('Drink','coke',6);
  38.                     house.addProduct('Food','meat',7);
  39.                     const sorted = Object.keys(house.orderProducts('Food'));
  40.                     expect(sorted[0]).to.equal('meat');
  41.                     expect(sorted[1]).to.equal('bread');
  42.                  })  
  43.                  it('Test add functionality', function () {
  44.                     const house = new Warehouse(20);
  45.                     const currentHouse = house.addProduct('Food','bread',20);
  46.                     expect(currentHouse['bread']).to.equal(20);
  47.                     expect(house.occupiedCapacity()).to.equal(20);
  48.                     expect(() => house.addProduct('Food','bread',15)).to.throw();
  49.                  })  
  50.                    
  51.                   });
Advertisement
Add Comment
Please, Sign In to add comment