From f859784564117ed5cc73bf8e901d1fe9db657539 Mon Sep 17 00:00:00 2001 From: Suyash Patil <127177049+suyashpatil78@users.noreply.github.com> Date: Tue, 2 Apr 2024 17:30:26 +0530 Subject: [PATCH] test: unit test for employees service (#2851) --- .../v1/spender/employees.service.spec.ts | 41 ++++++++++++++++++- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/src/app/core/services/platform/v1/spender/employees.service.spec.ts b/src/app/core/services/platform/v1/spender/employees.service.spec.ts index f0f6b04085..1a2b0113f1 100644 --- a/src/app/core/services/platform/v1/spender/employees.service.spec.ts +++ b/src/app/core/services/platform/v1/spender/employees.service.spec.ts @@ -1,16 +1,53 @@ import { TestBed } from '@angular/core/testing'; import { EmployeesService } from './employees.service'; +import { SpenderService } from './spender.service'; +import { commuteDetailsResponseData } from 'src/app/core/mock-data/commute-details-response.data'; +import { of } from 'rxjs'; +import { extendedOrgUserResponse } from 'src/app/core/test-data/tasks.service.spec.data'; -xdescribe('EmployeesService', () => { +describe('EmployeesService', () => { let service: EmployeesService; + let spenderService: jasmine.SpyObj; beforeEach(() => { - TestBed.configureTestingModule({}); + const spenderServiceSpy = jasmine.createSpyObj('SpenderService', ['get', 'post']); + TestBed.configureTestingModule({ + providers: [{ provide: SpenderService, useValue: spenderServiceSpy }], + }); service = TestBed.inject(EmployeesService); + spenderService = TestBed.inject(SpenderService) as jasmine.SpyObj; }); it('should be created', () => { expect(service).toBeTruthy(); }); + + it('getCommuteDetails(): should return commute details', (done) => { + spenderService.get.and.returnValue(of(commuteDetailsResponseData)); + + service.getCommuteDetails(extendedOrgUserResponse).subscribe((response) => { + expect(response).toEqual(commuteDetailsResponseData); + expect(spenderService.get).toHaveBeenCalledOnceWith('/employees', { + params: { + user_id: `eq.${extendedOrgUserResponse.us.id}`, + }, + }); + done(); + }); + }); + + it('postCommuteDetails(): should return commute details', (done) => { + spenderService.post.and.returnValue(of({ data: commuteDetailsResponseData.data[0] })); + + service.postCommuteDetails(commuteDetailsResponseData.data[0].commute_details).subscribe((response) => { + expect(response).toEqual({ data: commuteDetailsResponseData.data[0] }); + expect(spenderService.post).toHaveBeenCalledOnceWith('/employees/commute_details', { + data: { + commute_details: commuteDetailsResponseData.data[0].commute_details, + }, + }); + done(); + }); + }); });