Advertisement
Danny_Berova

HolidayPackageTests

Nov 13th, 2018
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let expect = require('chai').expect;
  2. let HolidayPackage = require('../sourcecode').HolidayPackage;
  3.  
  4. describe("Holiday Package", function() {
  5.     let holidayPackage;
  6.     beforeEach(function () {
  7.         holidayPackage = new HolidayPackage('Mallorca', 'Summer');
  8.     });
  9.     describe("init", function() {
  10.         it("should generate corectly", function() {
  11.             expect(holidayPackage.destination).equal('Mallorca');
  12.             expect(holidayPackage.season).equal('Summer');
  13.             expect(holidayPackage.showVacationers()).equal('No vacationers are added yet');
  14.             expect(holidayPackage.vacationers).eql([]);
  15.             expect(holidayPackage.insuranceIncluded ).equal(false);
  16.         });
  17.     });
  18.     describe("init without params", function() {
  19.         let holidayPackage1 = new HolidayPackage();
  20.         it("should generate corectly without params", function() {
  21.             expect(holidayPackage1.destination).equal(undefined);
  22.             expect(holidayPackage1.season).equal(undefined);
  23.  
  24.         });
  25.     });
  26.     describe("insurance", function() {
  27.         it("should set insurance corectly", function() {
  28.             holidayPackage.insuranceIncluded = true;
  29.             expect(holidayPackage.insuranceIncluded ).equal(true);
  30.         });
  31.         it("should throw if insurance value is not boolean", function() {
  32.             expect(() => {holidayPackage.insuranceIncluded='Pesho'}).throw("Insurance status must be a boolean");
  33.         });
  34.     });
  35.     describe("vacationers", function() {
  36.         it("should show vacationers corectly", function() {
  37.             expect(holidayPackage.showVacationers()).equal("No vacationers are added yet");
  38.         });
  39.         it("should add and show vacationers corectly", function() {
  40.             holidayPackage.addVacationer('Danny Berova');
  41.             holidayPackage.addVacationer('Nicky Berov');
  42.             expect(holidayPackage.showVacationers()).equal('Vacationers:\nDanny Berova\nNicky Berov');
  43.         });
  44.         it("should throw for split", function() {
  45.             expect(() => {holidayPackage.addVacationer('Danny')}).throw("Name must consist of first name and last name");
  46.         });
  47.         it("should throw if empty", function() {
  48.             expect(() => {holidayPackage.addVacationer()}).throw("Vacationer name must be a non-empty string");
  49.         });
  50.         it("should throw if empty string", function() {
  51.             expect(() => {holidayPackage.addVacationer(' ')}).throw("Vacationer name must be a non-empty string");
  52.         });
  53.         it("should throw if non-string", function() {
  54.             expect(() => {holidayPackage.addVacationer(5)}).throw("Vacationer name must be a non-empty string");
  55.         });
  56.     });
  57.     describe("generate HolydayPackage corectly", function() {
  58.         it("should generate corectly", function() {
  59.             holidayPackage.addVacationer('Danny Berova');
  60.             holidayPackage.addVacationer('Nicky Berov');
  61.             expect(holidayPackage.generateHolidayPackage())
  62.             .equal("Holiday Package Generated\n" +
  63.             "Destination: " + 'Mallorca' + "\n" +
  64.             'Vacationers:\nDanny Berova\nNicky Berov' + "\n" +
  65.             "Price: " + '1000');
  66.         });
  67.         it("should generate corectly with insurance", function() {
  68.             holidayPackage.addVacationer('Danny Berova');
  69.             holidayPackage.addVacationer('Nicky Berov');
  70.             holidayPackage.insuranceIncluded = true;
  71.             expect(holidayPackage.generateHolidayPackage())
  72.             .equal("Holiday Package Generated\n" +
  73.             "Destination: " + 'Mallorca' + "\n" +
  74.             'Vacationers:\nDanny Berova\nNicky Berov' + "\n" +
  75.             "Price: " + '1100');
  76.         });
  77.         it("should throw without vacationers", function() {
  78.             expect(() => {holidayPackage.generateHolidayPackage()}).throw();
  79.         });
  80.     });
  81. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement