Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const { it, describe } = require('mocha');
- const { assert, expect } = require('chai');
- let bookSelection = require('./task.js');
- describe('Tests bookSelection', function () {
- describe('isGenre suitable', function () {
- it('check to return suitable, 12 yo', function () {
- assert.equal(
- bookSelection.isGenreSuitable('Fantasy', 12),
- `Those books are suitable`
- );
- });
- it('check to return suitable, 13 yo', function () {
- assert.equal(
- bookSelection.isGenreSuitable('Thriller', 13),
- `Those books are suitable`
- );
- });
- it('check to return not suitable, 12 yo', function () {
- assert.equal(
- bookSelection.isGenreSuitable('Thriller', 12),
- `Books with Thriller genre are not suitable for kids at 12 age`
- );
- });
- });
- describe('is it affordable', function () {
- it('check with valid params to return success', function () {
- assert.equal(
- bookSelection.isItAffordable(15, 30),
- `Book bought. You have 15$ left`
- );
- });
- it('check with valid params to return success', function () {
- assert.equal(
- bookSelection.isItAffordable(15, 15),
- `Book bought. You have 0$ left`
- );
- });
- it('check with valid params to return no success', function () {
- assert.equal(
- bookSelection.isItAffordable(15, 14),
- "You don't have enough money"
- );
- });
- it('check with valid float params to return no success', function () {
- assert.equal(
- bookSelection.isItAffordable(15.7, 14),
- "You don't have enough money"
- );
- });
- it('check with invalid params to throw', function () {
- assert.throw(
- () => bookSelection.isItAffordable('15.7', 14),
- 'Invalid input'
- );
- });
- it('check with invalid params to throw', function () {
- assert.throw(
- () => bookSelection.isItAffordable(15.7, '14'),
- 'Invalid input'
- );
- });
- it('check with invalid params to throw', function () {
- assert.throw(
- () => bookSelection.isItAffordable([15.7], 14),
- 'Invalid input'
- );
- });
- });
- describe('suitable Titles', function () {
- it('assert with valid params', function () {
- assert.equal(
- bookSelection.suitableTitles(
- [{ title: 'The Da Vinci Code', genre: 'Thriller' }],
- 'Thriller'
- ),
- 'The Da Vinci Code'
- );
- });
- it('assert with valid params', function () {
- assert.equal(
- JSON.stringify(
- bookSelection.suitableTitles(
- [
- { title: 'The Da Vinci Code', genre: 'Thriller' },
- { title: 'The Origin', genre: 'Thriller' },
- ],
- 'Thriller'
- )
- ),
- JSON.stringify(['The Da Vinci Code', 'The Origin'])
- );
- });
- it('assert with valid params', function () {
- assert.equal(
- JSON.stringify(
- bookSelection.suitableTitles(
- [
- { title: 'The Da Vinci Code', genre: 'Thriller' },
- { title: 'The Origin', genre: 'Thriller' },
- ],
- 'Fantasy'
- )
- ),
- JSON.stringify([])
- );
- });
- it('assert with invalid params', ()=>{
- assert.throw(
- () => bookSelection.suitableTitles('Some Title', 'Genre'),
- 'Invalid input'
- );
- })
- it('assert with invalid params', () => {
- assert.throw(
- () => bookSelection.suitableTitles({title:'Some Title', genre:'Genre'}, 'Genre'),
- 'Invalid input'
- );
- });
- it('assert with invalid params', () => {
- assert.throw(
- () =>
- bookSelection.suitableTitles(
- [{ title: 'Some Title', genre: 'Genre' }],
- ['Genre']
- ),
- 'Invalid input'
- );
- });
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement