Advertisement
viligen

bookSelection

Jun 11th, 2022
887
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const { it, describe } = require('mocha');
  2.  
  3. const { assert, expect } = require('chai');
  4.  
  5. let bookSelection = require('./task.js');
  6.  
  7. describe('Tests bookSelection', function () {
  8.     describe('isGenre suitable', function () {
  9.         it('check to return suitable, 12 yo', function () {
  10.             assert.equal(
  11.                 bookSelection.isGenreSuitable('Fantasy', 12),
  12.                 `Those books are suitable`
  13.             );
  14.         });
  15.         it('check to return suitable, 13 yo', function () {
  16.             assert.equal(
  17.                 bookSelection.isGenreSuitable('Thriller', 13),
  18.                 `Those books are suitable`
  19.             );
  20.         });
  21.         it('check to return not suitable, 12 yo', function () {
  22.             assert.equal(
  23.                 bookSelection.isGenreSuitable('Thriller', 12),
  24.                 `Books with Thriller genre are not suitable for kids at 12 age`
  25.             );
  26.         });
  27.     });
  28.     describe('is it affordable', function () {
  29.         it('check with valid params to return success', function () {
  30.             assert.equal(
  31.                 bookSelection.isItAffordable(15, 30),
  32.                 `Book bought. You have 15$ left`
  33.             );
  34.         });
  35.         it('check with valid params to return success', function () {
  36.             assert.equal(
  37.                 bookSelection.isItAffordable(15, 15),
  38.                 `Book bought. You have 0$ left`
  39.             );
  40.         });
  41.         it('check with valid params to return no success', function () {
  42.             assert.equal(
  43.                 bookSelection.isItAffordable(15, 14),
  44.                 "You don't have enough money"
  45.             );
  46.         });
  47.         it('check with valid float params to return no success', function () {
  48.             assert.equal(
  49.                 bookSelection.isItAffordable(15.7, 14),
  50.                 "You don't have enough money"
  51.             );
  52.         });
  53.         it('check with invalid params to throw', function () {
  54.             assert.throw(
  55.                 () => bookSelection.isItAffordable('15.7', 14),
  56.                 'Invalid input'
  57.             );
  58.         });
  59.         it('check with invalid params to throw', function () {
  60.             assert.throw(
  61.                 () => bookSelection.isItAffordable(15.7, '14'),
  62.                 'Invalid input'
  63.             );
  64.         });
  65.         it('check with invalid params to throw', function () {
  66.             assert.throw(
  67.                 () => bookSelection.isItAffordable([15.7], 14),
  68.                 'Invalid input'
  69.             );
  70.         });
  71.     });
  72.     describe('suitable Titles', function () {
  73.         it('assert with valid params', function () {
  74.             assert.equal(
  75.                 bookSelection.suitableTitles(
  76.                     [{ title: 'The Da Vinci Code', genre: 'Thriller' }],
  77.                     'Thriller'
  78.                 ),
  79.                 'The Da Vinci Code'
  80.             );
  81.         });
  82.  
  83.         it('assert with valid params', function () {
  84.             assert.equal(
  85.                 JSON.stringify(
  86.                     bookSelection.suitableTitles(
  87.                         [
  88.                             { title: 'The Da Vinci Code', genre: 'Thriller' },
  89.                             { title: 'The Origin', genre: 'Thriller' },
  90.                         ],
  91.                         'Thriller'
  92.                     )
  93.                 ),
  94.                 JSON.stringify(['The Da Vinci Code', 'The Origin'])
  95.             );
  96.         });
  97.  
  98.         it('assert with valid params', function () {
  99.             assert.equal(
  100.                 JSON.stringify(
  101.                     bookSelection.suitableTitles(
  102.                         [
  103.                             { title: 'The Da Vinci Code', genre: 'Thriller' },
  104.                             { title: 'The Origin', genre: 'Thriller' },
  105.                         ],
  106.                         'Fantasy'
  107.                     )
  108.                 ),
  109.                 JSON.stringify([])
  110.             );
  111.         });
  112.  
  113.         it('assert with invalid params', ()=>{
  114.             assert.throw(
  115.                 () => bookSelection.suitableTitles('Some Title', 'Genre'),
  116.                 'Invalid input'
  117.             );
  118.         })
  119.         it('assert with invalid params', () => {
  120.             assert.throw(
  121.                 () => bookSelection.suitableTitles({title:'Some Title', genre:'Genre'}, 'Genre'),
  122.                 'Invalid input'
  123.             );
  124.         });
  125.  
  126.         it('assert with invalid params', () => {
  127.             assert.throw(
  128.                 () =>
  129.                     bookSelection.suitableTitles(
  130.                         [{ title: 'Some Title', genre: 'Genre' }],
  131.                         ['Genre']
  132.                     ),
  133.                 'Invalid input'
  134.             );
  135.         });
  136.     });
  137. });
  138.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement