Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const { it, describe } = require('mocha');
- const { assert, expect } = require('chai');
- let rentCar = require('./task.js');
- describe('Tests rentCar', () => {
- describe('search car method', () => {
- it('check with valid param and happy case', () => {
- assert.equal(
- rentCar.searchCar(['Volkswagen', 'BMW', 'Audi'], 'Audi'),
- `There is 1 car of model Audi in the catalog!`
- );
- });
- it('check with valid param and throws', () => {
- assert.throw(
- () => rentCar.searchCar(['Volkswagen', 'BMW', 'Audi'], 'Lada'),
- 'There are no such models in the catalog!'
- );
- });
- it('check with invalid param to throw', () => {
- assert.throw(
- () => rentCar.searchCar('Volkswagen', 'BMW'),
- 'Invalid input!'
- );
- });
- });
- describe('calculate car price', () => {
- let catalogue = {
- Volkswagen: 20,
- Audi: 36,
- Toyota: 40,
- BMW: 45,
- Mercedes: 50,
- };
- it('check with valid inputs, expects success', () => {
- assert.equal(
- rentCar.calculatePriceOfCar('Audi', 2),
- `You choose Audi and it will cost $72!`
- );
- });
- it('check with invalid param to throw', () => {
- assert.throw(
- () => rentCar.calculatePriceOfCar('Volkswagen', 'BMW'),
- 'Invalid input!'
- );
- });
- it('check with invalid param to throw', () => {
- assert.throw(
- () => rentCar.calculatePriceOfCar('Volkswagen', 3.5),
- 'Invalid input!'
- );
- });
- it('check with invalid param to throw', () => {
- assert.throw(
- () => rentCar.calculatePriceOfCar(['Volkswagen'], 3),
- 'Invalid input!'
- );
- });
- it('check with valid param, no success to throw', () => {
- assert.throw(
- () => rentCar.calculatePriceOfCar('Lada', 3),
- 'No such model in the catalog!'
- );
- });
- });
- describe('check budget', () => {
- it('check with valid inputs, expects success', () => {
- assert.equal(rentCar.checkBudget(30, 2, 70), `You rent a car!`);
- });
- it('check with valid inputs, expects no success', () => {
- assert.equal(
- rentCar.checkBudget(30, 2, 50),
- 'You need a bigger budget!'
- );
- });
- it('check with invalid param to throw', () => {
- assert.throw(
- () => rentCar.checkBudget('Volkswagen', 3, 5),
- 'Invalid input!'
- );
- });
- it('check with invalid param to throw', () => {
- assert.throw(
- () => rentCar.checkBudget(0, '3', 5),
- 'Invalid input!'
- );
- });
- it('check with invalid param to throw', () => {
- assert.throw(
- () => rentCar.checkBudget(0, 3, 'five'),
- 'Invalid input!'
- );
- });
- it('check with invalid param to throw', () => {
- assert.throw(
- () => rentCar.checkBudget(0, 5.5, 8),
- 'Invalid input!'
- );
- });
- it('check with valid param, equal values, success', () => {
- assert.equal(rentCar.checkBudget(30, 2, 60), `You rent a car!`);
- });
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment