Advertisement
Lulunga

Unit Testing 07. Warehouse

Oct 21st, 2019
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. describe("Test", function () {
  2.     let warehouse;
  3.     beforeEach(function () {
  4.         warehouse = new Warehouse(5);
  5.     });
  6.  
  7.     it('should give correct message for empty warehouse', function () {
  8.         expect(warehouse.revision()).to.be.equal('The warehouse is empty')
  9.     })
  10. });
  11. describe('Warehouse', () => {
  12.     describe("Constructor Tests", () => {
  13.         it('should throw string if givenSpace <= 0 or non-number argument',
  14.             () => {
  15.                 expect(() => {
  16.                     new Warehouse(-1)
  17.                 }).to.throw();
  18.                 expect(() => {
  19.                     new Warehouse(0)
  20.                 }).to.throw();
  21.                 expect(() => {
  22.                     new Warehouse("a")
  23.                 }).to.throw();
  24.             });
  25.         it('should throw string no free space is available', () => {
  26.             let warehouse = new Warehouse(1);
  27.             assert.throws(() => warehouse.addProduct('Food', 'bread', 2))
  28.         });
  29.         it('should sort foods in descending order by quantity', () => {
  30.             let warehouse = new Warehouse(12);
  31.             warehouse.addProduct('Food', 'bread', 1);
  32.             warehouse.addProduct('Food', 'potatoes', 2);
  33.             warehouse.addProduct('Food', 'mushrooms', 3);
  34.             warehouse.orderProducts('Food');
  35.             let foods = JSON.stringify(warehouse.availableProducts.Food);
  36.             assert.equal(foods, '{"mushrooms":3,"potatoes":2,"bread":1}')
  37.         });
  38.         it('should return string "The warehouse is empty" for 0 products', () => {
  39.             let warehouse = new Warehouse(4);
  40.             expect(warehouse.revision()).to.be.equal('The warehouse is empty')
  41.         });
  42.         it('throw error for non existing type', function () {
  43.             expect(() => {
  44.                 let warehouse = new Warehouse(5);
  45.                 warehouse.addProduct('Food', 'banana', 4);
  46.                 warehouse.addProduct('Food', 'apple', 1);
  47.                 warehouse.scrapeAProduct('tomato', 1)
  48.             }).to.throw('tomato do not exists');
  49.         })
  50.     });
  51. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement