Advertisement
didkoslawow

Untitled

Jun 8th, 2023
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. describe('Test for bookSelection', () => {
  2.     it('isGenreSuitable', () => {
  3.         expect(bookSelection.isGenreSuitable('Thriller', 12)).to.equal(
  4.             'Books with Thriller genre are not suitable for kids at 12 age'
  5.         );
  6.         expect(bookSelection.isGenreSuitable('Horror', 12)).to.equal(
  7.             'Books with Horror genre are not suitable for kids at 12 age'
  8.         );
  9.         expect(bookSelection.isGenreSuitable('Thriller', 5)).to.equal(
  10.             'Books with Thriller genre are not suitable for kids at 5 age'
  11.         );
  12.         expect(bookSelection.isGenreSuitable('Horror', 5)).to.equal('Books with Horror genre are not suitable for kids at 5 age');
  13.  
  14.         expect(bookSelection.isGenreSuitable('Thriller', 13)).to.equal('Those books are suitable');
  15.         expect(bookSelection.isGenreSuitable('Horror', 13)).to.equal('Those books are suitable');
  16.         expect(bookSelection.isGenreSuitable('Comedy', 10)).to.equal('Those books are suitable');
  17.         expect(bookSelection.isGenreSuitable('Comedy', 25)).to.equal('Those books are suitable');
  18.     });
  19.  
  20.     it('isItAffordable', () => {
  21.         expect(() => bookSelection.isItAffordable('20', 10)).to.throw();
  22.         expect(() => bookSelection.isItAffordable(10, '20')).to.throw();
  23.         expect(() => bookSelection.isItAffordable('10', '20')).to.throw();
  24.         expect(() => bookSelection.isItAffordable([], 10)).to.throw();
  25.         expect(() => bookSelection.isItAffordable(10, {})).to.throw();
  26.         expect(() => bookSelection.isItAffordable(10, 10)).to.not.throw();
  27.         expect(() => bookSelection.isItAffordable(50, 62)).to.not.throw();
  28.  
  29.         expect(bookSelection.isItAffordable(20, 50)).to.equal('Book bought. You have 30$ left');
  30.         expect(bookSelection.isItAffordable(20, 10)).to.equal("You don't have enough money");
  31.     });
  32.  
  33.     it('suitableTitles', () => {
  34.         expect(() => bookSelection.suitableTitles('', '')).to.throw();
  35.         expect(() => bookSelection.suitableTitles([], [])).to.throw();
  36.         expect(() => bookSelection.suitableTitles({}, '')).to.throw();
  37.         expect(() => bookSelection.suitableTitles('', {})).to.throw();
  38.         expect(() => bookSelection.suitableTitles(10, '')).to.throw();
  39.         expect(() => bookSelection.suitableTitles([], 10)).to.throw();
  40.         expect(() => bookSelection.suitableTitles([], '')).to.not.throw();
  41.  
  42.         const books = [
  43.             { title: 'The Matrix', genre: 'Fantasy' },
  44.             { title: 'Avatar', genre: 'Fantasy' },
  45.             { title: 'How High', genre: 'Comedy' },
  46.         ];
  47.         const wantedGenre = 'Fantasy';
  48.         const result = bookSelection.suitableTitles(books, wantedGenre);
  49.  
  50.         expect(result[0]).to.equal('The Matrix');
  51.         expect(result[1]).to.equal('Avatar');
  52.         expect(result.length).to.equal(2);
  53.     });
  54. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement