Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const { expect } = require('chai');
- const {companyAdministration} = require('./companyAdministration');
- describe('Testing a object with 3 methods in it', () => {
- describe('hiringEmployee(name, position, yearsExperience) - with wrong position', () => {
- it('returns error if the position is not Programmer', () => {
- expect(() => companyAdministration.hiringEmployee('Peter', 'Worker', 10)).to.throw('We are not looking for workers for this position.');
- });
- it('returns if person is hired basedn on experience', () => {
- expect(companyAdministration.hiringEmployee('Peter', 'Programmer', 4)).to.be.equal('Peter was successfully hired for the position Programmer.');
- });
- it('returns if person is hired basedn on experience', () => {
- expect(companyAdministration.hiringEmployee('Peter', 'Programmer', 3)).to.be.equal('Peter was successfully hired for the position Programmer.');
- });
- it('returns not approved if the experience is less than 3', () => {
- expect(companyAdministration.hiringEmployee('Peter', 'Programmer', 2)).to.be.equal('Peter is not approved for this position.');
- });
- });
- describe('companyAdministration.calculateSalary(hours)', () => {
- it('returns error if the hours is not a number or a negative number', () =>{
- expect(() => companyAdministration.calculateSalary('a')).to.throw('Invalid hours');
- expect(() => companyAdministration.calculateSalary([])).to.throw('Invalid hours');
- expect(() => companyAdministration.calculateSalary({})).to.throw('Invalid hours');
- expect(() => companyAdministration.calculateSalary(null)).to.throw('Invalid hours');
- expect(() => companyAdministration.calculateSalary(undefined)).to.throw('Invalid hours');
- expect(() => companyAdministration.calculateSalary(-1)).to.throw('Invalid hours');
- });
- it('returns the salary based on the working hours', () => {
- expect(companyAdministration.calculateSalary(100)).to.be.equal(1500);
- expect(companyAdministration.calculateSalary(160)).to.be.equal(2400);
- expect(companyAdministration.calculateSalary(161)).to.be.equal(3415);
- });
- });
- describe('companyAdministration.firedEmployee(employees, index)', () => {
- it('returns throws error if the first parameter is not an array or the index is otuside the limits', () => {
- expect(() => companyAdministration.firedEmployee({}, 1)).to.throw('Invalid input');
- expect(() => companyAdministration.firedEmployee([], 1)).to.throw('Invalid input');
- expect(() => companyAdministration.firedEmployee(null, 1)).to.throw('Invalid input');
- expect(() => companyAdministration.firedEmployee(undefined, 1)).to.throw('Invalid input');
- expect(() => companyAdministration.firedEmployee(undefined, undefined)).to.throw('Invalid input');
- expect(() => companyAdministration.firedEmployee(undefined, null)).to.throw('Invalid input');
- expect(() => companyAdministration.firedEmployee(['Peter', 'George', 'Ivan'], '1')).to.throw('Invalid input');
- expect(() => companyAdministration.firedEmployee(['Peter', 'George', 'Ivan'], [])).to.throw('Invalid input');
- expect(() => companyAdministration.firedEmployee(['Peter', 'George', 'Ivan'], {})).to.throw('Invalid input');
- expect(() => companyAdministration.firedEmployee(['Peter', 'George', 'Ivan'], undefined)).to.throw('Invalid input');
- expect(() => companyAdministration.firedEmployee(['Peter', 'George', 'Ivan'], null)).to.throw('Invalid input');
- expect(() => companyAdministration.firedEmployee(['Peter', 'George', 'Ivan'], -1)).to.throw('Invalid input');
- });
- it('returns the employees array if the conditions are met', () => {
- expect(companyAdministration.firedEmployee(['Peter', 'George', 'Ivan'], 1)).to.be.equal('Peter, Ivan');
- expect(companyAdministration.firedEmployee(['Peter', 'George', 'Ivan'], 2)).to.be.equal('Peter, George');
- expect(companyAdministration.firedEmployee(['Peter', 'George', 'Ivan'], 0)).to.be.equal('George, Ivan');
- });
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement