Skip to content

Commit

Permalink
Merge branch 'master' into FYLE-86cuxuafw
Browse files Browse the repository at this point in the history
  • Loading branch information
bistaastha authored Apr 2, 2024
2 parents 83aa9fc + f859784 commit 1e36774
Show file tree
Hide file tree
Showing 8 changed files with 615 additions and 4 deletions.
24 changes: 24 additions & 0 deletions src/app/core/mock-data/commute-details-response.data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,27 @@ export const commuteDetailsResponseData: PlatformApiResponse<CommuteDetailsRespo
},
],
};

export const commuteDetailsResponseData2: PlatformApiResponse<CommuteDetailsResponse> = {
count: 1,
offset: 0,
data: [],
};

export const commuteDetailsResponseData3: PlatformApiResponse<CommuteDetailsResponse> = {
count: 1,
offset: 0,
data: [
{
user_id: 'uswr93Wqcfjv',
full_name: 'John Doe',
email: '[email protected]',
commute_details: {
distance: null,
distance_unit: null,
home_location: null,
work_location: null,
},
},
],
};
16 changes: 16 additions & 0 deletions src/app/core/mock-data/org-settings.data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1394,3 +1394,19 @@ export const orgSettingsPendingRestrictions: OrgSettings = {
corporate_credit_card_settings: { enabled: true },
pending_cct_expense_restriction: { enabled: true },
};

export const orgSettingsWithCommuteDeductionsEnabled: OrgSettings = {
...orgSettingsRes,
commute_deduction_settings: {
enabled: true,
allowed: true,
},
};

export const orgSettingsWithCommuteDeductionsDisabled: OrgSettings = {
...orgSettingsRes,
commute_deduction_settings: {
enabled: false,
allowed: false,
},
};
13 changes: 13 additions & 0 deletions src/app/core/mock-data/task.data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,16 @@ export const verifyMobileNumberTask = {
},
],
};

export const commuteDeductionTask = {
hideAmount: true,
header: 'Add Commute Details',
subheader: 'Add your Home and Work locations to easily deduct commute distance from your mileage expenses',
icon: TaskIcon.LOCATION,
ctas: [
{
content: 'Add',
event: TASKEVENT.commuteDetails,
},
],
};
Original file line number Diff line number Diff line change
@@ -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<SpenderService>;

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<SpenderService>;
});

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();
});
});
});
86 changes: 84 additions & 2 deletions src/app/core/services/tasks.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,25 @@ import {
verifyMobileNumberTask,
draftExpenseTaskSample2,
unreportedExpenseTaskSample2,
commuteDeductionTask,
} from '../mock-data/task.data';
import { mastercardRTFCard } from '../mock-data/platform-corporate-card.data';
import { OrgSettingsService } from './org-settings.service';
import { ExpensesService } from './platform/v1/spender/expenses.service';
import { expenseDuplicateSets } from '../mock-data/platform/v1/expense-duplicate-sets.data';
import { completeStats, incompleteStats } from '../mock-data/platform/v1/expenses-stats.data';
import { EmployeesService } from './platform/v1/spender/employees.service';
import { orgSettingsRes } from '../mock-data/org-settings.data';
import { commuteDetailsResponseData } from '../mock-data/commute-details-response.data';
import {
orgSettingsRes,
orgSettingsWithCommuteDeductionsDisabled,
orgSettingsWithCommuteDeductionsEnabled,
orgSettingsWoMileage,
} from '../mock-data/org-settings.data';
import {
commuteDetailsResponseData,
commuteDetailsResponseData2,
commuteDetailsResponseData3,
} from '../mock-data/commute-details-response.data';
import { orgSettingsPendingRestrictions } from '../mock-data/org-settings.data';

describe('TasksService', () => {
Expand Down Expand Up @@ -1066,4 +1076,76 @@ describe('TasksService', () => {
});
});
});

describe('getCommuteDetailsTasks():', () => {
it('should return commute details task if commute details response data is not defined', (done) => {
employeesService.getCommuteDetails.and.returnValue(of(commuteDetailsResponseData2));
authService.getEou.and.returnValue(Promise.resolve(extendedOrgUserResponse));
orgSettingsService.get.and.returnValue(of(orgSettingsWithCommuteDeductionsEnabled));

tasksService.getCommuteDetailsTasks().subscribe((res) => {
expect(orgSettingsService.get).toHaveBeenCalledTimes(1);
expect(authService.getEou).toHaveBeenCalledTimes(1);
expect(employeesService.getCommuteDetails).toHaveBeenCalledOnceWith(extendedOrgUserResponse);
expect(res).toEqual([commuteDeductionTask]);
done();
});
});

it('should return commute details task if home location is not present', (done) => {
employeesService.getCommuteDetails.and.returnValue(of(commuteDetailsResponseData3));
authService.getEou.and.returnValue(Promise.resolve(extendedOrgUserResponse));
orgSettingsService.get.and.returnValue(of(orgSettingsWithCommuteDeductionsEnabled));

tasksService.getCommuteDetailsTasks().subscribe((res) => {
expect(orgSettingsService.get).toHaveBeenCalledTimes(1);
expect(authService.getEou).toHaveBeenCalledTimes(1);
expect(employeesService.getCommuteDetails).toHaveBeenCalledOnceWith(extendedOrgUserResponse);
expect(res).toEqual([commuteDeductionTask]);
done();
});
});

it('should not return commute details task if mileage is disabled for org', (done) => {
employeesService.getCommuteDetails.and.returnValue(of(commuteDetailsResponseData3));
authService.getEou.and.returnValue(Promise.resolve(extendedOrgUserResponse));
orgSettingsService.get.and.returnValue(of(orgSettingsWoMileage));

tasksService.getCommuteDetailsTasks().subscribe((res) => {
expect(orgSettingsService.get).toHaveBeenCalledTimes(1);
expect(authService.getEou).toHaveBeenCalledTimes(1);
expect(employeesService.getCommuteDetails).toHaveBeenCalledOnceWith(extendedOrgUserResponse);
expect(res).toEqual([]);
done();
});
});

it('should not return commute details task if commute deduction settings is disabled for org', (done) => {
employeesService.getCommuteDetails.and.returnValue(of(commuteDetailsResponseData3));
authService.getEou.and.returnValue(Promise.resolve(extendedOrgUserResponse));
orgSettingsService.get.and.returnValue(of(orgSettingsRes));

tasksService.getCommuteDetailsTasks().subscribe((res) => {
expect(orgSettingsService.get).toHaveBeenCalledTimes(1);
expect(authService.getEou).toHaveBeenCalledTimes(1);
expect(employeesService.getCommuteDetails).toHaveBeenCalledOnceWith(extendedOrgUserResponse);
expect(res).toEqual([]);
done();
});
});

it('should not return commute details task if home location is present in commute details', (done) => {
employeesService.getCommuteDetails.and.returnValue(of(commuteDetailsResponseData));
authService.getEou.and.returnValue(Promise.resolve(extendedOrgUserResponse));
orgSettingsService.get.and.returnValue(of(orgSettingsWithCommuteDeductionsDisabled));

tasksService.getCommuteDetailsTasks().subscribe((res) => {
expect(orgSettingsService.get).toHaveBeenCalledTimes(1);
expect(authService.getEou).toHaveBeenCalledTimes(1);
expect(employeesService.getCommuteDetails).toHaveBeenCalledOnceWith(extendedOrgUserResponse);
expect(res).toEqual([]);
done();
});
});
});
});
Loading

0 comments on commit 1e36774

Please sign in to comment.