Advertisement
Liliana797979

Company administration - js advanced - exam

Jan 28th, 2022
883
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const { expect } = require('chai');
  2.  
  3. const companyAdministration = {
  4.  
  5.     hiringEmployee(name, position, yearsExperience) {
  6.         if (position == "Programmer") {
  7.             if (yearsExperience >= 3) {
  8.                 return `${name} was successfully hired for the position ${position}.`;
  9.             } else {
  10.                 return `${name} is not approved for this position.`;
  11.             }
  12.         }
  13.         throw new Error(`We are not looking for workers for this position.`);
  14.     },
  15.     calculateSalary(hours) {
  16.  
  17.         let payPerHour = 15;
  18.         let totalAmount = payPerHour * hours;
  19.  
  20.         if (typeof hours !== "number" || hours < 0) {
  21.             throw new Error("Invalid hours");
  22.         } else if (hours > 160) {
  23.             totalAmount += 1000;
  24.         }
  25.         return totalAmount;
  26.     },
  27.     firedEmployee(employees, index) {
  28.  
  29.         let result = [];
  30.  
  31.         if (!Array.isArray(employees) || !Number.isInteger(index) || index < 0 || index >= employees.length) {
  32.             throw new Error("Invalid input");
  33.         }
  34.         for (let i = 0; i < employees.length; i++) {
  35.             if (i !== index) {
  36.                 result.push(employees[i]);
  37.             }
  38.         }
  39.         return result.join(", ");
  40.     }
  41.  
  42. }
  43.  
  44. describe('companyAdministration', () => {
  45.  
  46.     describe('hiringEmployee', () => {
  47.         it('should have invalid position and throw', () => {
  48.             expect(() => companyAdministration.hiringEmployee('Chocho', 'None', 3)).throw('We are not looking for workers for this position.')
  49.         });
  50.  
  51.         it('should have lower than required experience and return not approved', () => {
  52.             expect(companyAdministration.hiringEmployee('Chocho', 'Programmer', 2)).equal('Chocho is not approved for this position.')
  53.         });
  54.  
  55.         it('should have lower than required experience and return not approved', () => {
  56.             expect(companyAdministration.hiringEmployee('Chocho', 'Programmer')).equal('Chocho is not approved for this position.')
  57.         });
  58.  
  59.         it('should meet required years of experience edge 3', () => {
  60.             expect(companyAdministration.hiringEmployee('Chocho', 'Programmer', 3)).equal('Chocho was successfully hired for the position Programmer.')
  61.         });
  62.  
  63.         it('should have over required years of experience', () => {
  64.             expect(companyAdministration.hiringEmployee('Chocho', 'Programmer', 4)).equal('Chocho was successfully hired for the position Programmer.')
  65.         });
  66.  
  67.  
  68.        
  69.     });
  70.  
  71.     describe('calculateSalary', () => {
  72.         it('should have invalid hours and throw', () => {
  73.             expect(() => companyAdministration.calculateSalary('a')).throw('Invalid hours');
  74.         });
  75.  
  76.         it('should have invalid(negativeNumber) hours and throw', () => {
  77.             expect(() => companyAdministration.calculateSalary(-1)).throw('Invalid hours');
  78.         });
  79.  
  80.         it('should have invalid(negativeNumber) hours and throw', () => {
  81.             expect(() => companyAdministration.calculateSalary([1])).throw('Invalid hours');
  82.         });
  83.  
  84.         it('should have invalid(negativeNumber) hours and throw', () => {
  85.             expect(() => companyAdministration.calculateSalary('-1')).throw('Invalid hours');
  86.         });
  87.  
  88.         it('should have invalid(negativeNumber) hours and throw', () => {
  89.             expect(() => companyAdministration.calculateSalary(-0.25)).throw('Invalid hours');
  90.         });
  91.  
  92.         it('should have 0 hours', () => {
  93.             expect(companyAdministration.calculateSalary(0)).equal(0);
  94.         });
  95.  
  96.         it('should have valid Input with less than 160 hours', () => {
  97.             expect(companyAdministration.calculateSalary(30)).equal(450);
  98.         });
  99.        
  100.         it('should have valid Input with exactly 160 hours', () => {
  101.             expect(companyAdministration.calculateSalary(160)).equal(2400);
  102.         });
  103.  
  104.         it('should have valid Input with more than 160 hours', () => {
  105.             expect(companyAdministration.calculateSalary(161)).equal(3415);
  106.         });
  107.  
  108.         it('should have valid Input with floating number', () => {
  109.             expect(companyAdministration.calculateSalary(2.5)).equal(37.5);
  110.         });
  111.     });
  112.  
  113.     describe('firedEmployee', () => {
  114.         it('should have invalid array and index', () => {
  115.             expect(() => companyAdministration.firedEmployee([], 'a')).throw('Invalid input');
  116.         });
  117.  
  118.         it('should have invalid array and index', () => {
  119.             expect(() => companyAdministration.firedEmployee('[]', 'a')).throw('Invalid input');
  120.         });
  121.  
  122.         it('should have valid array but invalid index', () => {
  123.             expect(() => companyAdministration.firedEmployee(['George', 'Ivan'], 'a')).throw('Invalid input');
  124.         });
  125.  
  126.         it('should have valid array but invalid index', () => {
  127.             expect(() => companyAdministration.firedEmployee(['George', 'Ivan'], 1.5)).throw('Invalid input');
  128.         });
  129.        
  130.  
  131.         it('should have valid index but invalid array', () => {
  132.             expect(() => companyAdministration.firedEmployee('[]', 2)).throw('Invalid input');
  133.         });
  134.  
  135.         it('should have valid index but invalid array', () => {
  136.             expect(() => companyAdministration.firedEmployee([], 2)).throw('Invalid input');
  137.         });
  138.  
  139.         it('should have invalid index but valid array', () => {
  140.             expect(() => companyAdministration.firedEmployee(['George', 'Chocho'], 2)).throw('Invalid input');
  141.         });
  142.  
  143.         it('should have invalid index but valid array', () => {
  144.             expect(() => companyAdministration.firedEmployee(['George', 'Chocho'], 2)).throw('Invalid input');
  145.         });
  146.  
  147.         it('should have invalid index but valid array', () => {
  148.             expect(() => companyAdministration.firedEmployee(['George', 'Chocho'])).throw('Invalid input');
  149.         });
  150.  
  151.         it('should have invalid index but valid array', () => {
  152.             expect(() => companyAdministration.firedEmployee(2)).throw('Invalid input');
  153.         });
  154.  
  155.         it('should have invalid index but valid array', () => {
  156.             expect(() => companyAdministration.firedEmployee(['George', 'Chocho'], -1)).throw('Invalid input');
  157.         });
  158.  
  159.         it('should have valid inputs', () => {
  160.             expect(companyAdministration.firedEmployee(['George', 'Chocho', 'Ivan'], 2)).equal('George, Chocho');
  161.         });
  162.        
  163.         it('should have valid inputs and return empty string', () => {
  164.             expect(companyAdministration.firedEmployee(['George'], 0)).equal('');
  165.         });
  166.        
  167.         it('should have valid inputs', () => {
  168.             expect(companyAdministration.firedEmployee(['George', 'Chocho', 'Ivan'], 2)).equal('George, Chocho');
  169.         })
  170.  
  171.     });
  172. });
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement