Advertisement
diela33

test

Feb 7th, 2022
973
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const { expect } = require('chai');
  2. const  {companyAdministration}  = require('./companyAdministration');
  3.  
  4. describe('Testing a object with 3 methods in it', () => {
  5.  
  6.     describe('hiringEmployee(name, position, yearsExperience) - with wrong position', () => {
  7.         it('returns error if the position is not Programmer', () => {
  8.             expect(() => companyAdministration.hiringEmployee('Peter', 'Worker', 10)).to.throw('We are not looking for workers for this position.');
  9.         });
  10.         it('returns if person is hired basedn on experience', () => {
  11.             expect(companyAdministration.hiringEmployee('Peter', 'Programmer', 4)).to.be.equal('Peter was successfully hired for the position Programmer.');
  12.         });
  13.         it('returns if person is hired basedn on experience', () => {
  14.             expect(companyAdministration.hiringEmployee('Peter', 'Programmer', 3)).to.be.equal('Peter was successfully hired for the position Programmer.');
  15.         });
  16.         it('returns not approved if the experience is less than 3', () => {
  17.             expect(companyAdministration.hiringEmployee('Peter', 'Programmer', 2)).to.be.equal('Peter is not approved for this position.');
  18.         });
  19.     });
  20.  
  21.     describe('companyAdministration.calculateSalary(hours)', () => {
  22.         it('returns error if the hours is not a number or a negative number', () =>{
  23.             expect(() => companyAdministration.calculateSalary('a')).to.throw('Invalid hours');
  24.             expect(() => companyAdministration.calculateSalary([])).to.throw('Invalid hours');
  25.             expect(() => companyAdministration.calculateSalary({})).to.throw('Invalid hours');
  26.             expect(() => companyAdministration.calculateSalary(null)).to.throw('Invalid hours');
  27.             expect(() => companyAdministration.calculateSalary(undefined)).to.throw('Invalid hours');
  28.             expect(() => companyAdministration.calculateSalary(-1)).to.throw('Invalid hours');
  29.         });
  30.         it('returns the salary based on the working hours', () => {
  31.             expect(companyAdministration.calculateSalary(100)).to.be.equal(1500);
  32.             expect(companyAdministration.calculateSalary(160)).to.be.equal(2400);
  33.             expect(companyAdministration.calculateSalary(161)).to.be.equal(3415);
  34.         });
  35.     });
  36.  
  37.     describe('companyAdministration.firedEmployee(employees, index)', () => {
  38.         it('returns throws error if the first parameter is not an array or the index is otuside the limits', () => {
  39.             expect(() => companyAdministration.firedEmployee({}, 1)).to.throw('Invalid input');
  40.             expect(() => companyAdministration.firedEmployee([], 1)).to.throw('Invalid input');
  41.             expect(() => companyAdministration.firedEmployee(null, 1)).to.throw('Invalid input');
  42.             expect(() => companyAdministration.firedEmployee(undefined, 1)).to.throw('Invalid input');
  43.             expect(() => companyAdministration.firedEmployee(undefined, undefined)).to.throw('Invalid input');
  44.             expect(() => companyAdministration.firedEmployee(undefined, null)).to.throw('Invalid input');
  45.             expect(() => companyAdministration.firedEmployee(['Peter', 'George', 'Ivan'], '1')).to.throw('Invalid input');
  46.             expect(() => companyAdministration.firedEmployee(['Peter', 'George', 'Ivan'], [])).to.throw('Invalid input');
  47.             expect(() => companyAdministration.firedEmployee(['Peter', 'George', 'Ivan'], {})).to.throw('Invalid input');
  48.             expect(() => companyAdministration.firedEmployee(['Peter', 'George', 'Ivan'], undefined)).to.throw('Invalid input');
  49.             expect(() => companyAdministration.firedEmployee(['Peter', 'George', 'Ivan'], null)).to.throw('Invalid input');
  50.             expect(() => companyAdministration.firedEmployee(['Peter', 'George', 'Ivan'], -1)).to.throw('Invalid input');
  51.         });
  52.         it('returns the employees array if the conditions are met', () => {
  53.             expect(companyAdministration.firedEmployee(['Peter', 'George', 'Ivan'], 1)).to.be.equal('Peter, Ivan');
  54.             expect(companyAdministration.firedEmployee(['Peter', 'George', 'Ivan'], 2)).to.be.equal('Peter, George');
  55.             expect(companyAdministration.firedEmployee(['Peter', 'George', 'Ivan'], 0)).to.be.equal('George, Ivan');
  56.         });
  57.     });
  58.  
  59. });
  60.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement