Advertisement
Liliana797979

library - js advanced exam

Oct 23rd, 2021
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const library = require('./library');
  2. const { assert, expect } = require('chai');
  3.  
  4. describe("Test Library functionallity", function() {
  5.     describe("Test calcPriceOfBook", function() {
  6.         it("calcPriceOfBook should return 20.00 and year is 1990", function() {
  7.             let price = 20
  8.             let expectedResult = `Price of My Title is 20.00`;
  9.             let actualResult = library.calcPriceOfBook('My Title', 1990);
  10.             expect(expectedResult).to.equal(actualResult);
  11.         });
  12.  
  13.         it("calcPriceOfBook should return descreased price when year is equal to 1980", function() {
  14.             let expectedResult = `Price of My Title is 10.00`;
  15.             let actualResult = library.calcPriceOfBook('My Title', 1980)
  16.             expect(expectedResult).to.equal(actualResult);
  17.         });
  18.  
  19.         it("calcPriceOfBook should return descreased price when year is equal to 1979", function() {
  20.             let expectedResult = `Price of My Title is 10.00`;
  21.             let actualResult = library.calcPriceOfBook('My Title', 1979);
  22.             expect(expectedResult).to.equal(actualResult);
  23.         });
  24.  
  25.         it("calcPriceOfBook should should throw ex when name is array", function() {
  26.             assert.throw(() => library.calcPriceOfBook([], 1979))
  27.          //   expect().to.throw(error);
  28.         });
  29.  
  30.         it("calcPriceOfBook should should throw ex when name is undefined", function() {
  31.             assert.throw(() => library.calcPriceOfBook(undefined, 1979));
  32.         });
  33.  
  34.         it("calcPriceOfBook should should throw ex when name is null", function() {
  35.             assert.throw(() => library.calcPriceOfBook(null, 1979));
  36.         });
  37.  
  38.         it("calcPriceOfBook should should throw ex when name is object", function() {
  39.             assert.throw(() => library.calcPriceOfBook({}, 1979));
  40.         });
  41.  
  42.         it("calcPriceOfBook should should throw ex when year is double", function() {
  43.             assert.throw(() => library.calcPriceOfBook('My Title', 1979.25));
  44.         });
  45.  
  46.         it("calcPriceOfBook should should throw ex when year is string", function() {
  47.             assert.throw(() => library.calcPriceOfBook('My Title', '1979'));
  48.         });
  49.  
  50.         it("calcPriceOfBook should should throw ex when year is Nan", function() {
  51.             assert.throw(() => library.calcPriceOfBook('My Title', NaN));
  52.         });
  53.  
  54.         it("calcPriceOfBook should should throw ex when year is undefined", function() {
  55.             assert.throw(() => library.calcPriceOfBook('My Title', undefined));
  56.         });
  57.        
  58.         it("calcPriceOfBook should should throw ex when year is object", function() {
  59.             assert.throw(() => library.calcPriceOfBook('My Title', {}));
  60.         });
  61.  
  62.         it("calcPriceOfBook should should throw ex when year is array", function() {
  63.             assert.throw(() => library.calcPriceOfBook('My Title', []));
  64.         });
  65.      });
  66.    
  67.  
  68.      describe("Test findBook", function() {
  69.         it("findBook should return success message when book is found", function() {
  70.             let expectedResult = `We found the book you want.`;
  71.             let actualResult = library.findBook(['Spiderman', 'Pod igoto'], 'Pod igoto');
  72.             expect(expectedResult).to.equal(actualResult);
  73.         });
  74.  
  75.         it("findBook should throws when array is empty", function() {
  76.             //test meesage of ex?
  77.             assert.throw(() => library.findBook([], 'Pod Igoto'));
  78.         });
  79.  
  80.         it("findBook should return no found message when book is not found", function() {
  81.             let expectedResult = `The book you are looking for is not here!`;
  82.             let actualResult = library.findBook(['Spiderman', 'Pod igoto'], 'Druga kniga');
  83.             expect(expectedResult).to.equal(actualResult);
  84.         });
  85.  
  86.         it("findBook should return no found message when book is not found", function() {
  87.             let expectedResult = `The book you are looking for is not here!`;
  88.             let actualResult = library.findBook(['Spiderman', 6], 'Druga kniga');
  89.             expect(expectedResult).to.equal(actualResult);
  90.         });
  91.      });
  92.  
  93.      describe("Test arrangeTheBooks", function() {
  94.         it("arrangeTheBooks should return success message when books are below 40", function() {
  95.             //countShelves = 40
  96.             let expectedResult = `Great job, the books are arranged.`;
  97.             let actualResult = library.arrangeTheBooks(35);
  98.             expect(expectedResult).to.equal(actualResult);
  99.         });
  100.  
  101.         it("arrangeTheBooks should return success message when books are exact 40", function() {
  102.             //countShelves = 40
  103.             let expectedResult = `Great job, the books are arranged.`;
  104.             let actualResult = library.arrangeTheBooks(40);
  105.             expect(expectedResult).to.equal(actualResult);
  106.         });
  107.  
  108.         it("arrangeTheBooks should return no success message when books are above 40", function() {
  109.             //countShelves = 40
  110.             let expectedResult = `Insufficient space, more shelves need to be purchased.`;
  111.             let actualResult = library.arrangeTheBooks(41);
  112.             expect(expectedResult).to.equal(actualResult);
  113.         });
  114.  
  115.         it("arrangeTheBooks should throw ex when count is string", function() {
  116.             assert.throw(() => library.arrangeTheBooks('40'));
  117.         });
  118.  
  119.         it("arrangeTheBooks should throw ex when count is string", function() {
  120.             assert.throw(() => library.arrangeTheBooks('somestring'));
  121.         });
  122.  
  123.         it("arrangeTheBooks should throw ex when count is array", function() {
  124.             assert.throw(() => library.arrangeTheBooks([]));
  125.         });
  126.  
  127.         it("arrangeTheBooks should throw ex when count is object", function() {
  128.             assert.throw(() => library.arrangeTheBooks({}));
  129.         });
  130.  
  131.         it("arrangeTheBooks should throw ex when count is double", function() {
  132.             assert.throw(() => library.arrangeTheBooks(4.50));
  133.         });
  134.  
  135.         it("arrangeTheBooks should throw ex when count is negative", function() {
  136.             assert.throw(() => library.arrangeTheBooks(-5));
  137.         });
  138.     });
  139. });
  140.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement