-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Yakymiv/officials list #2713
Merged
Merged
Yakymiv/officials list #2713
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
82a0a9e
fetched data from endpoint and tabs removed
4cca4af
placeholder changed and deputy table template removed
0979aec
employees tests adjusted
13bbd02
unit tests for employee service and component
cac50c6
naming updated to officialEmployee
c421437
imports sorted and comment in the model
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Person } from './user.model'; | ||
|
||
export class OfficialEmployee implements Person { | ||
id?: string; | ||
userId?: string; | ||
position: string; | ||
positionId: string; | ||
firstName: string; | ||
middleName?: string; | ||
lastName: string; | ||
rnokpp: string; | ||
// TODO: add this functionality when avaliable on backend | ||
dismissalOrder: string; | ||
recruitmentOrder: string; | ||
dismissalReason: string; | ||
employmentType: string; | ||
// | ||
activeFrom: string; | ||
activeTo: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
145 changes: 142 additions & 3 deletions
145
src/app/shared/services/employee/employee.service.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,159 @@ | ||
import { HttpClientTestingModule } from '@angular/common/http/testing'; | ||
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing'; | ||
import { TestBed } from '@angular/core/testing'; | ||
import { NgxsModule } from '@ngxs/store'; | ||
|
||
import { Employee, EmployeeParameters } from 'shared/models/employee.model'; | ||
import { SearchResponse } from 'shared/models/search.model'; | ||
import { OfficialEmployee } from 'shared/models/official-employee.model'; | ||
import { EmployeeBlockData } from 'shared/models/block.model'; | ||
import { EmployeeService } from './employee.service'; | ||
|
||
describe('EmployeeService', () => { | ||
let service: EmployeeService; | ||
let httpMock: HttpTestingController; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [HttpClientTestingModule, NgxsModule.forRoot([])] | ||
imports: [HttpClientTestingModule, NgxsModule.forRoot([])], | ||
providers: [EmployeeService] | ||
}); | ||
service = TestBed.inject(EmployeeService); | ||
httpMock = TestBed.inject(HttpTestingController); | ||
}); | ||
|
||
afterEach(() => { | ||
httpMock.verify(); | ||
}); | ||
|
||
it('should be created', () => { | ||
expect(service).toBeTruthy(); | ||
}); | ||
|
||
it('should GET employee by id', () => { | ||
const mockEmployee: Employee = { id: '1', firstName: 'John', lastName: 'Smith', email: 'email', phoneNumber: 'number' }; | ||
const employeeId = '1'; | ||
|
||
service.getEmployeeById(employeeId).subscribe((employee) => { | ||
expect(employee).toEqual(mockEmployee); | ||
}); | ||
|
||
const req = httpMock.expectOne(`/api/v1/Employees/GetEmployeeById/${employeeId}`); | ||
expect(req.request.method).toBe('GET'); | ||
|
||
req.flush(mockEmployee); | ||
}); | ||
|
||
it('should GET filtered official employees', () => { | ||
const filterParams: EmployeeParameters = { | ||
searchString: 'John', | ||
from: 0, | ||
size: 10, | ||
providerId: '1' | ||
}; | ||
|
||
const mockResponse: SearchResponse<OfficialEmployee[]> = { | ||
entities: [ | ||
{ | ||
id: '1', | ||
firstName: 'John', | ||
lastName: 'Doe', | ||
position: 'employee', | ||
positionId: '1', | ||
rnokpp: '111', | ||
dismissalOrder: '', | ||
recruitmentOrder: '', | ||
dismissalReason: '', | ||
employmentType: '', | ||
activeFrom: '', | ||
activeTo: '' | ||
} | ||
], | ||
totalAmount: 1 | ||
}; | ||
|
||
service.getFilteredOfficialEmployees(filterParams).subscribe((response) => { | ||
expect(response).toEqual(mockResponse); | ||
}); | ||
|
||
const req = httpMock.expectOne(`/api/v1/providers/${filterParams.providerId}/officials/Get?searchString=John&from=0&size=10`); | ||
expect(req.request.method).toBe('GET'); | ||
|
||
req.flush(mockResponse); | ||
}); | ||
|
||
it('should create a new employee', () => { | ||
const newEmployee: Employee = { id: '1', firstName: 'John', lastName: 'Smith', email: 'email', phoneNumber: '+000' }; | ||
|
||
service.createEmployee(newEmployee).subscribe((response) => { | ||
expect(response).toEqual(newEmployee); | ||
}); | ||
|
||
const req = httpMock.expectOne('/api/v1/Employees/Create'); | ||
expect(req.request.method).toBe('POST'); | ||
expect(req.request.body).toEqual(newEmployee); | ||
|
||
req.flush(newEmployee); | ||
}); | ||
|
||
it('should DELETE an employee', () => { | ||
const employeeId = '1'; | ||
const providerId = '1'; | ||
|
||
service.deleteEmployee(employeeId, providerId).subscribe((response) => { | ||
expect(response).toBeUndefined(); | ||
}); | ||
|
||
const req = httpMock.expectOne(`/api/v1/Employees/Delete?employeeId=${employeeId}&providerId=${providerId}`); | ||
expect(req.request.method).toBe('DELETE'); | ||
|
||
req.flush(null); | ||
}); | ||
|
||
it('should block an employee successfully', () => { | ||
const employeeBlockParams: EmployeeBlockData = { | ||
userId: '1', | ||
providerId: '1', | ||
isBlocked: true | ||
}; | ||
|
||
service.blockEmployee(employeeBlockParams).subscribe((response) => { | ||
expect(response).toBeUndefined(); | ||
}); | ||
|
||
const req = httpMock.expectOne( | ||
`/api/v1/Employees/Block?employeeId=${employeeBlockParams.userId}&providerId=${employeeBlockParams.providerId}&isBlocked=true` | ||
); | ||
expect(req.request.method).toBe('PUT'); | ||
expect(req.request.body).toEqual({}); | ||
|
||
req.flush(null); | ||
}); | ||
|
||
it('should update an employee successfully', () => { | ||
const providerId = '1'; | ||
const updatedEmployee: Employee = { id: '1', firstName: 'John', lastName: 'Smith', email: 'email', phoneNumber: 'number' }; | ||
|
||
service.updateEmployee(providerId, updatedEmployee).subscribe((response) => { | ||
expect(response).toEqual(updatedEmployee); | ||
}); | ||
|
||
const req = httpMock.expectOne(`/api/v1/Employees/Update?providerId=${providerId}`); | ||
expect(req.request.method).toBe('PUT'); | ||
expect(req.request.body).toEqual(updatedEmployee); | ||
|
||
req.flush(updatedEmployee); | ||
}); | ||
|
||
it('should reinvite an employee successfully', () => { | ||
const employee: Employee = { id: '1', firstName: 'John', lastName: 'Smith', email: 'email', phoneNumber: 'number' }; | ||
|
||
service.reinvateEmployee(employee).subscribe((response) => { | ||
expect(response).toBeUndefined(); | ||
}); | ||
|
||
const req = httpMock.expectOne(`/api/v1/Employees/Reinvite/${employee.id}`); | ||
expect(req.request.method).toBe('PUT'); | ||
expect(req.request.body).toEqual(employee); | ||
|
||
req.flush(null); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably should be an enum instead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dima said these are some new "placeholder" fields which can be removed or edited in the future, maybe it is better to leave them like that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I asked him and we decided just to ignore it and add TODO comment