Skip to content

Commit

Permalink
Add Employee class + tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitriikankan committed Nov 4, 2023
1 parent 65f5560 commit da39a7b
Show file tree
Hide file tree
Showing 7 changed files with 831 additions and 930 deletions.
6 changes: 3 additions & 3 deletions rpgsaga/saga/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.23.4",
"eslint-plugin-prettier": "^3.4.0",
"jest": "^27.2.5",
"jest": "^29.7.0",
"prettier": "^2.4.1",
"ts-jest": "^27.1.2",
"ts-node": "^10.3.0",
"typescript": "^4.4.4",
"ts-jest": "^27.1.2"
"typescript": "^4.4.4"
},
"jest": {
"preset": "ts-jest"
Expand Down
64 changes: 64 additions & 0 deletions rpgsaga/saga/src/employee.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
export class Employee {
private theName: string;
private theHireDate: string;
private aPosition: string;
private aSalary: number;
private anEmail: string;
private aPhoneNumber: string;


static employeeCount = 0;
constructor(name: string = 'Не указано', position: string = 'Не указана', hireDate: string = 'Не указана', email: string = 'Не указана', phoneNumber: string = 'Не указан', salary: number = 0) {
this.theName = name;
this.theHireDate = hireDate;
this.aPosition = position;
this.aSalary = salary;
this.anEmail = email;
this.aPhoneNumber = phoneNumber;
Employee.employeeCount += 1;

}
set salary(salary: number){
this.aSalary = salary;
}

get salary(): number{
return this.aSalary
}

set position(position: string){
this.aPosition = position;
}

get position(): string{
return this.aPosition;
}

set email(email: string){
this.anEmail = email;
}

get email(): string{
return this.anEmail;
}

set phoneNumber(phoneNumber: string){
this.aPhoneNumber = phoneNumber;
}

get phoneNumber(): string{
return this.aPhoneNumber;
}
get name(): string{
return this.theName
}

get hireDate(): string{
return this.theHireDate
}

getInfo(): string {
return `ФИО: ${this.theName}; Должность: ${this.aPosition}; Дата приема на работу: ${this.theHireDate}; Заработная плата: ${this.aSalary} рублей; E-mail: ${this.anEmail}; Номер телефона: ${this.aPhoneNumber}.`
}

}
28 changes: 16 additions & 12 deletions rpgsaga/saga/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
import { Phone } from './phone';
import { Employee } from './employee';

const first = new Phone('+7900-000 000 (123)', 1990, 'Телефон 1');
first.year = 1998;
const employee1 = new Employee('Буянов Никита Васильвич', 'PR-менеджер', '15 октября 2014');

first.year = -1998;
first.call('12345');
first.endCall();
employee1.position = 'Аналитик';
employee1.salary = 100000;
employee1.email = '[email protected]'

const second = new Phone('+799900000', -5);
// second.name = 'Телефон 2';
console.log(second.year);
second.call('12345');
second.endCall();
const employee2 = new Employee('Дмитриев Иван Иванович', 'Тестировщик', '26 ноября 2014');

console.log(first, second, Phone.phoneCount);
employee2.position = 'Разработчики';
employee2.salary = 240000;
employee2.phoneNumber = '+7915-323-00-00'

const employee3 = new Employee(undefined, undefined, '15 октября 2014', '[email protected]', '+7915-323-00-00', 100000);

console.log(employee1.getInfo())
console.log(employee2.getInfo())
console.log(employee3.getInfo())
console.log(`Количество сотрудников: ${Employee.employeeCount}`)
28 changes: 0 additions & 28 deletions rpgsaga/saga/src/phone.ts

This file was deleted.

36 changes: 36 additions & 0 deletions rpgsaga/saga/tests/employee.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { Employee } from '../src/employee';

describe('Testing employee constructor', () => {
it('Employee should be created', () => {
const employee1 = new Employee('Буянов Никита Васильвич', 'PR-менеджер', '15 октября 2014', '[email protected]', '+7915-323-00-00', 100000);
expect(employee1.name).toEqual('Буянов Никита Васильвич');
expect(employee1.position).toEqual('PR-менеджер');
expect(employee1.hireDate).toEqual('15 октября 2014');
expect(employee1.email).toEqual('[email protected]');
expect(employee1.phoneNumber).toEqual('+7915-323-00-00');
expect(employee1.salary).toEqual(100000);
});
});

describe('Testing employee methods', () => {
it('Employee new position value', () => {
const employee1 = new Employee('Буянов Никита Васильвич', 'PR-менеджер', '15 октября 2014', '[email protected]', '+7915-323-00-00', 100000);
employee1.position = 'Аналитик';
expect(employee1.position).toEqual('Аналитик');
});
it('Employee new email value', () => {
const employee1 = new Employee('Буянов Никита Васильвич', 'PR-менеджер', '15 октября 2014', '[email protected]', '+7915-323-00-00', 100000);
employee1.email = '[email protected]'
expect(employee1.email).toEqual('[email protected]');
});
it('Employee new phone number value', () => {
const employee1 = new Employee('Буянов Никита Васильвич', 'PR-менеджер', '15 октября 2014', '[email protected]', '+7915-323-00-00', 100000);
employee1.phoneNumber = '+7920-363-33-33';
expect(employee1.phoneNumber).toEqual('+7920-363-33-33');
});
it('Employee new salary value', () => {
const employee1 = new Employee('Буянов Никита Васильвич', 'PR-менеджер', '15 октября 2014', '[email protected]', '+7915-323-00-00', 100000);
employee1.salary = 2000000;
expect(employee1.salary).toEqual(2000000);
});
});
46 changes: 0 additions & 46 deletions rpgsaga/saga/tests/phone.spec.ts

This file was deleted.

Loading

0 comments on commit da39a7b

Please sign in to comment.