Skip to content

Commit

Permalink
fix: Replace public GET calls to display delegatee info (#3172)
Browse files Browse the repository at this point in the history
* replace delegatee info from eou

* minor

* switch to delegator changes

* fix unit tests

* fix employee service unit tests

* more fixes

* switch to delegator changes

* eslint fixes

* more fixes

* minor

* add safety
  • Loading branch information
harshal015 authored Aug 20, 2024
1 parent cb49e6d commit 6731a9e
Show file tree
Hide file tree
Showing 19 changed files with 292 additions and 57 deletions.
112 changes: 112 additions & 0 deletions src/app/core/mock-data/extended-org-user.data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,118 @@ export const eouFlattended: EouApiResponse = deepFreeze({
ou_cost_center_ids: [13792, 13793, 13794, 14018, 13795, 13995, 9493, 9494, 13785, 13787, 13788, 13789, 13790, 13791],
});

export const eouUnFlattended: ExtendedOrgUser = deepFreeze({
ou: {
id: 'ouX8dwsbLCLv',
created_at: new Date('2018-02-01T02:32:25.267Z'),
org_id: 'orNVthTo2Zyo',
user_id: 'usvKA4X8Ugcr',
employee_id: '',
location: 'Mumbai',
level: 123,
level_id: 'lvlPtroPaClQy',
band: 'Very Long Level name Very Long Level name Very Long Level name Very Long Level name Very Long Level name Very Long Level name Very Long Level name Very Long Level name',
rank: 1121212121,
business_unit:
'A very long Business Unit indeed A very long Business Unit indeed A very long Business Unit indeed A very long Business Unit indeed',
department_id: 'deptpmQ0SsMO0S',
department: '0000000',
sub_department: null,
roles: ['ADMIN', 'APPROVER', 'FYLER', 'HOP', 'HOD', 'OWNER'],
approver1_id: 'ouy8gYhZRK4E',
approver2_id: null,
approver3_id: null,
delegatee_id: 'ouAIf3H1yhZj',
delegation_start_at: new Date('2023-02-02T03:07:28.879Z'),
delegation_end_at: null,
title: 'director',
status: 'ACTIVE',
branch_ifsc: 'ICIC0002322',
branch_account: '12123412221',
mobile: '+12025559975',
mobile_verified: false,
mobile_verified_at: null,
is_primary: true,
owner: false,
joining_dt: new Date('2017-07-25T00:00:00.000+0000'),
special_email: '[email protected]',
custom_field_values: [
{
id: 685,
name: 'Hybrid human',
value: null,
},
{
id: 430,
name: 'UNum1',
value: 1,
},
{
id: 138,
name: 'Driver salary limit',
value: 1122,
},
{
id: 139,
name: 'Fuel limit',
value: 1,
},
{
id: 459,
name: 'multi',
value: '',
},
{
id: 456,
name: 'Place',
value: null,
},
{
id: 458,
name: 'Location',
value: null,
},
],
org_name: 'Staging Loaded',
settings_id: 'ousS9MgDNQ6NB',
default_cost_center_id: null,
default_cost_center_name: null,
default_cost_center_code: null,
cost_center_ids: [13792, 13793, 13794, 14018, 13795, 13995, 9493, 9494, 13785, 13787, 13788, 13789, 13790, 13791],
},
org: {
domain: 'fyle.in',
currency: 'INR',
},
us: {
id: 'usvKA4X8Ugcr',
created_at: new Date('2016-06-13T12:21:16.803Z'),
full_name: 'Abhishek Jain',
email: '[email protected]',
email_verified_at: new Date('2022-09-06T05:26:19.898Z'),
onboarded: true,
},
ap1: {
full_name: 'Aditya Gupta',
email: '[email protected]',
},
ap2: {
full_name: null,
email: null,
},
ap3: {
full_name: null,
email: null,
},
bb: {
bank_name: 'ICICI BANK LIMITED',
},
dwolla: {
customer_id: 'dwcJzfwZCgwkdfG',
bank_account_added: true,
},
});

export const eouWithNoAttempts: ExtendedOrgUser = deepFreeze({
...apiEouRes,
ou: {
Expand Down
8 changes: 8 additions & 0 deletions src/app/core/mock-data/platform/v1/delegator.data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import deepFreeze from 'deep-freeze-strict';
import { Delegator } from 'src/app/core/models/platform/delegator.model';

export const delegatorData: Delegator = deepFreeze({
user_id: '0x1234',
email: '[email protected]',
full_name: 'Vercetti',
});
47 changes: 47 additions & 0 deletions src/app/core/mock-data/platform/v1/platform-employee.data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import deepFreeze from 'deep-freeze-strict';
import { DelegationType } from 'src/app/core/models/platform/delegation-type.enum';
import { PlatformApiResponse } from 'src/app/core/models/platform/platform-api-response.model';
import { PlatformEmployee } from 'src/app/core/models/platform/platform-employee.model';

export const platformEmployeeData: PlatformEmployee = deepFreeze({
code: null,
department: {
code: null,
display_name: 'Tech',
id: 'deptCjFrZcE0rH',
name: 'Tech',
sub_department: 'Tech',
},
department_id: 'deptCjFrZcE0rH',
id: 'ouirDZ7tTLEQ',
org_id: 'orNVthTo2Zyo',
user: {
email: '[email protected]',
full_name: 'Arjun',
id: 'usJZ9bgfNB5n',
},
user_id: 'usJZ9bgfNB5n',
delegatees: [
{
id: 100,
type: DelegationType.PERMANENT,
user_id: '0x1234',
email: '[email protected]',
full_name: 'Vercetti',
start_at: new Date(),
end_at: null,
},
],
});

export const platformEmployeeResponse: PlatformApiResponse<PlatformEmployee> = deepFreeze({
count: 1,
offset: 10,
data: platformEmployeeData,
});

export const platformEmployeeEmptyResponse: PlatformApiResponse<PlatformEmployee> = deepFreeze({
count: 1,
offset: 10,
data: null,
});
1 change: 1 addition & 0 deletions src/app/core/models/employee-params.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ export interface EmployeeParams {
order: string;
limit: number;
us_email?: string;
us_id: string;
}
11 changes: 11 additions & 0 deletions src/app/core/models/platform/delegatee.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { DelegationType } from './delegation-type.enum';

export interface Delegatee {
id: number;
type: DelegationType;
user_id: string;
email: string;
full_name: string;
start_at: Date;
end_at: Date;
}
4 changes: 4 additions & 0 deletions src/app/core/models/platform/delegation-type.enum.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export enum DelegationType {
SHORT_TERM,
PERMANENT,
}
5 changes: 5 additions & 0 deletions src/app/core/models/platform/delegator.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export interface Delegator {
user_id: string;
email: string;
full_name: string;
}
2 changes: 2 additions & 0 deletions src/app/core/models/platform/platform-employee.model.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { User } from '../user.model';
import { Delegatee } from './delegatee.model';
import { Department } from './v1/department.model';

export interface PlatformEmployee {
Expand All @@ -9,4 +10,5 @@ export interface PlatformEmployee {
department?: Department;
department_id?: string;
org_id: string;
delegatees?: Delegatee[];
}
20 changes: 14 additions & 6 deletions src/app/core/services/org-user.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import { DataTransformService } from './data-transform.service';
import { of } from 'rxjs';
import { OrgUserService } from './org-user.service';
import { TokenService } from './token.service';
import { delegatorData } from '../mock-data/platform/v1/delegator.data';
import { SpenderPlatformV1ApiService } from './spender-platform-v1-api.service';

describe('OrgUserService', () => {
let orgUserService: OrgUserService;
Expand All @@ -30,10 +32,12 @@ describe('OrgUserService', () => {
let authService: jasmine.SpyObj<AuthService>;
let dataTransformService: jasmine.SpyObj<DataTransformService>;
let apiV2Service: jasmine.SpyObj<ApiV2Service>;
let spenderPlatformV1ApiService: jasmine.SpyObj<SpenderPlatformV1ApiService>;

beforeEach(() => {
const apiServiceSpy = jasmine.createSpyObj('ApiService', ['get', 'post']);
const apiv2ServiceSpy = jasmine.createSpyObj('ApiV2Service', ['get']);
const spenderPlatformV1ApiServiceSpy = jasmine.createSpyObj('spenderPlatformV1ApiService', ['get']);
const jwtHelperServiceSpy = jasmine.createSpyObj('JwtHelperService', ['decodeToken']);
const tokenServiceSpy = jasmine.createSpyObj('TokenService', ['getAccessToken']);
const authServiceSpy = jasmine.createSpyObj('AuthService', ['newRefreshToken', 'refreshEou']);
Expand All @@ -50,6 +54,10 @@ describe('OrgUserService', () => {
provide: ApiV2Service,
useValue: apiv2ServiceSpy,
},
{
provide: SpenderPlatformV1ApiService,
useValue: spenderPlatformV1ApiServiceSpy,
},
{
provide: JwtHelperService,
useValue: jwtHelperServiceSpy,
Expand All @@ -71,6 +79,9 @@ describe('OrgUserService', () => {
orgUserService = TestBed.inject(OrgUserService);
apiService = TestBed.inject(ApiService) as jasmine.SpyObj<ApiService>;
apiV2Service = TestBed.inject(ApiV2Service) as jasmine.SpyObj<ApiV2Service>;
spenderPlatformV1ApiService = TestBed.inject(
SpenderPlatformV1ApiService
) as jasmine.SpyObj<SpenderPlatformV1ApiService>;
jwtHelperService = TestBed.inject(JwtHelperService) as jasmine.SpyObj<JwtHelperService>;
tokenService = TestBed.inject(TokenService) as jasmine.SpyObj<TokenService>;
authService = TestBed.inject(AuthService) as jasmine.SpyObj<AuthService>;
Expand Down Expand Up @@ -162,14 +173,11 @@ describe('OrgUserService', () => {
});

it('should be able to find delegated accounts', (done) => {
const eouList = [currentEouUnflatted];
apiService.get.and.returnValue(of(eouList));
eouList.map((delegatedAccount) =>
dataTransformService.unflatten.withArgs(delegatedAccount).and.returnValue(currentEouRes)
);
const delegatorList = { data: [delegatorData] };
spenderPlatformV1ApiService.get.and.returnValue(of(delegatorList));

orgUserService.findDelegatedAccounts().subscribe((res) => {
expect(res).toEqual([currentEouRes]);
expect(res).toEqual([delegatorData]);
done();
});
});
Expand Down
20 changes: 9 additions & 11 deletions src/app/core/services/org-user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ import { JwtHelperService } from './jwt-helper.service';
import { TokenService } from './token.service';
import { TrackingService } from './tracking.service';
import { AccessTokenData } from '../models/access-token-data.model';
import { Delegator } from '../models/platform/delegator.model';
import { SpenderPlatformV1ApiService } from './spender-platform-v1-api.service';
import { PlatformApiResponse } from '../models/platform/platform-api-response.model';

const orgUsersCacheBuster$ = new Subject<void>();

Expand All @@ -31,7 +34,8 @@ export class OrgUserService {
private authService: AuthService,
private dataTransformService: DataTransformService,
private trackingService: TrackingService,
private apiV2Service: ApiV2Service
private apiV2Service: ApiV2Service,
private spenderPlatformV1ApiService: SpenderPlatformV1ApiService
) {}

@Cacheable()
Expand All @@ -56,16 +60,10 @@ export class OrgUserService {
}

@Cacheable()
findDelegatedAccounts(): Observable<ExtendedOrgUser[]> {
return this.apiService.get<ExtendedOrgUser[]>('/eous/current/delegated_eous').pipe(
map((delegatedAccounts) => {
delegatedAccounts = delegatedAccounts.map((delegatedAccount) =>
this.dataTransformService.unflatten(delegatedAccount)
);

return delegatedAccounts;
})
);
findDelegatedAccounts(): Observable<Delegator[]> {
return this.spenderPlatformV1ApiService
.get<PlatformApiResponse<Delegator[]>>('/employees/delegators')
.pipe(map((response) => response.data));
}

postUser(user: User): Observable<User> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ 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';
import {
platformEmployeeData,
platformEmployeeResponse,
} from 'src/app/core/mock-data/platform/v1/platform-employee.data';
import { PlatformEmployee } from 'src/app/core/models/platform/platform-employee.model';

describe('EmployeesService', () => {
let service: EmployeesService;
Expand Down Expand Up @@ -50,4 +55,15 @@ describe('EmployeesService', () => {
done();
});
});

it('getByParams(): should get employees by params', () => {
spenderService.get.and.returnValue(of(platformEmployeeResponse));
const params: Partial<PlatformEmployee> = {
user_id: 'usJZ9bgfNB5n',
};

service.getByParams(params).subscribe((res) => {
expect(res).toBe(platformEmployeeResponse);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { CommuteDetails } from 'src/app/core/models/platform/v1/commute-details.
import { CommuteDetailsResponse } from 'src/app/core/models/platform/commute-details-response.model';
import { PlatformApiResponse } from 'src/app/core/models/platform/platform-api-response.model';
import { ExtendedOrgUser } from 'src/app/core/models/extended-org-user.model';
import { PlatformEmployee } from 'src/app/core/models/platform/platform-employee.model';

@Injectable({
providedIn: 'root',
Expand All @@ -27,4 +28,8 @@ export class EmployeesService {
},
});
}

getByParams(params: Partial<PlatformEmployee>): Observable<PlatformApiResponse<PlatformEmployee>> {
return this.spenderService.get(`/employees`, { params });
}
}
10 changes: 4 additions & 6 deletions src/app/fyle/delegated-accounts/delegated-accounts.page.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,12 @@
<ion-grid>
<ion-row>
<ion-col size="2">
<div class="delegated--org-thumb">{{ acc?.us?.full_name | initials | uppercase }}</div>
<div class="delegated--org-thumb">{{ acc?.full_name | initials | uppercase }}</div>
</ion-col>
<ion-col size="10">
<div class="delegated--org-element-name">{{acc?.us?.full_name}}</div>
<div class="delegated--org-element-us-details">{{acc?.us?.email}}</div>
<div *ngIf="acc?.ou.org_id === currentOrg.id" class="delegated--org-element-us-details">
{{currentOrg.name}}
</div>
<div class="delegated--org-element-name">{{acc?.full_name}}</div>
<div class="delegated--org-element-us-details">{{acc?.email}}</div>
<div class="delegated--org-element-us-details">{{currentOrg.name}}</div>
</ion-col>
</ion-row>
</ion-grid>
Expand Down
Loading

0 comments on commit 6731a9e

Please sign in to comment.