viligen

rentCar

Jun 10th, 2022
1,253
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 rentCar = require('./task.js');
  6.  
  7. describe('Tests rentCar', () => {
  8.     describe('search car method', () => {
  9.         it('check with valid param and happy case', () => {
  10.             assert.equal(
  11.                 rentCar.searchCar(['Volkswagen', 'BMW', 'Audi'], 'Audi'),
  12.                 `There is 1 car of model Audi in the catalog!`
  13.             );
  14.         });
  15.         it('check with valid param and throws', () => {
  16.             assert.throw(
  17.                 () => rentCar.searchCar(['Volkswagen', 'BMW', 'Audi'], 'Lada'),
  18.                 'There are no such models in the catalog!'
  19.             );
  20.         });
  21.         it('check with invalid param to throw', () => {
  22.             assert.throw(
  23.                 () => rentCar.searchCar('Volkswagen', 'BMW'),
  24.                 'Invalid input!'
  25.             );
  26.         });
  27.     });
  28.     describe('calculate car price', () => {
  29.         let catalogue = {
  30.             Volkswagen: 20,
  31.             Audi: 36,
  32.             Toyota: 40,
  33.             BMW: 45,
  34.             Mercedes: 50,
  35.         };
  36.         it('check with valid inputs, expects success', () => {
  37.             assert.equal(
  38.                 rentCar.calculatePriceOfCar('Audi', 2),
  39.                 `You choose Audi and it will cost $72!`
  40.             );
  41.         });
  42.  
  43.         it('check with invalid param to throw', () => {
  44.             assert.throw(
  45.                 () => rentCar.calculatePriceOfCar('Volkswagen', 'BMW'),
  46.                 'Invalid input!'
  47.             );
  48.         });
  49.         it('check with invalid param to throw', () => {
  50.             assert.throw(
  51.                 () => rentCar.calculatePriceOfCar('Volkswagen', 3.5),
  52.                 'Invalid input!'
  53.             );
  54.         });
  55.         it('check with invalid param to throw', () => {
  56.             assert.throw(
  57.                 () => rentCar.calculatePriceOfCar(['Volkswagen'], 3),
  58.                 'Invalid input!'
  59.             );
  60.         });
  61.         it('check with valid param, no success to throw', () => {
  62.             assert.throw(
  63.                 () => rentCar.calculatePriceOfCar('Lada', 3),
  64.                 'No such model in the catalog!'
  65.             );
  66.         });
  67.     });
  68.  
  69.     describe('check budget', () => {
  70.         it('check with valid inputs, expects success', () => {
  71.             assert.equal(rentCar.checkBudget(30, 2, 70), `You rent a car!`);
  72.         });
  73.         it('check with valid inputs, expects no success', () => {
  74.             assert.equal(
  75.                 rentCar.checkBudget(30, 2, 50),
  76.                 'You need a bigger budget!'
  77.             );
  78.         });
  79.         it('check with invalid param to throw', () => {
  80.             assert.throw(
  81.                 () => rentCar.checkBudget('Volkswagen', 3, 5),
  82.                 'Invalid input!'
  83.             );
  84.         });
  85.  
  86.         it('check with invalid param to throw', () => {
  87.             assert.throw(
  88.                 () => rentCar.checkBudget(0, '3', 5),
  89.                 'Invalid input!'
  90.             );
  91.         });
  92.         it('check with invalid param to throw', () => {
  93.             assert.throw(
  94.                 () => rentCar.checkBudget(0, 3, 'five'),
  95.                 'Invalid input!'
  96.             );
  97.         });
  98.         it('check with invalid param to throw', () => {
  99.             assert.throw(
  100.                 () => rentCar.checkBudget(0, 5.5, 8),
  101.                 'Invalid input!'
  102.             );
  103.         });
  104.         it('check with valid param, equal values, success', () => {
  105.             assert.equal(rentCar.checkBudget(30, 2, 60), `You rent a car!`);
  106.         });
  107.     });
  108. });
  109.  
Advertisement
Add Comment
Please, Sign In to add comment