diff --git a/src/app/core/mock-data/extended-org-user.data.ts b/src/app/core/mock-data/extended-org-user.data.ts index 23c0c41c69..bb5dbc1643 100644 --- a/src/app/core/mock-data/extended-org-user.data.ts +++ b/src/app/core/mock-data/extended-org-user.data.ts @@ -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: 'receipts+ajain_6@fyle.ai', + 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: 'ajain@fyle.in', + email_verified_at: new Date('2022-09-06T05:26:19.898Z'), + onboarded: true, + }, + ap1: { + full_name: 'Aditya Gupta', + email: 'aditya.g@fyle.in', + }, + 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: { diff --git a/src/app/core/mock-data/platform/v1/delegator.data.ts b/src/app/core/mock-data/platform/v1/delegator.data.ts new file mode 100644 index 0000000000..7c34db1948 --- /dev/null +++ b/src/app/core/mock-data/platform/v1/delegator.data.ts @@ -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: 'test@mail.com', + full_name: 'Vercetti', +}); diff --git a/src/app/core/mock-data/platform/v1/platform-employee.data.ts b/src/app/core/mock-data/platform/v1/platform-employee.data.ts new file mode 100644 index 0000000000..d6741da42f --- /dev/null +++ b/src/app/core/mock-data/platform/v1/platform-employee.data.ts @@ -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: 'arjun.m@fyle.in', + full_name: 'Arjun', + id: 'usJZ9bgfNB5n', + }, + user_id: 'usJZ9bgfNB5n', + delegatees: [ + { + id: 100, + type: DelegationType.PERMANENT, + user_id: '0x1234', + email: 'test@mail.in', + full_name: 'Vercetti', + start_at: new Date(), + end_at: null, + }, + ], +}); + +export const platformEmployeeResponse: PlatformApiResponse = deepFreeze({ + count: 1, + offset: 10, + data: platformEmployeeData, +}); + +export const platformEmployeeEmptyResponse: PlatformApiResponse = deepFreeze({ + count: 1, + offset: 10, + data: null, +}); diff --git a/src/app/core/models/employee-params.model.ts b/src/app/core/models/employee-params.model.ts index f8c66c2a23..99b85e510f 100644 --- a/src/app/core/models/employee-params.model.ts +++ b/src/app/core/models/employee-params.model.ts @@ -9,4 +9,5 @@ export interface EmployeeParams { order: string; limit: number; us_email?: string; + us_id: string; } diff --git a/src/app/core/models/platform/delegatee.model.ts b/src/app/core/models/platform/delegatee.model.ts new file mode 100644 index 0000000000..4c5696f7bc --- /dev/null +++ b/src/app/core/models/platform/delegatee.model.ts @@ -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; +} diff --git a/src/app/core/models/platform/delegation-type.enum.ts b/src/app/core/models/platform/delegation-type.enum.ts new file mode 100644 index 0000000000..f5c9f49c75 --- /dev/null +++ b/src/app/core/models/platform/delegation-type.enum.ts @@ -0,0 +1,4 @@ +export enum DelegationType { + SHORT_TERM, + PERMANENT, +} diff --git a/src/app/core/models/platform/delegator.model.ts b/src/app/core/models/platform/delegator.model.ts new file mode 100644 index 0000000000..cb517d7aee --- /dev/null +++ b/src/app/core/models/platform/delegator.model.ts @@ -0,0 +1,5 @@ +export interface Delegator { + user_id: string; + email: string; + full_name: string; +} diff --git a/src/app/core/models/platform/platform-employee.model.ts b/src/app/core/models/platform/platform-employee.model.ts index cbf8b77956..de0820595d 100644 --- a/src/app/core/models/platform/platform-employee.model.ts +++ b/src/app/core/models/platform/platform-employee.model.ts @@ -1,4 +1,5 @@ import { User } from '../user.model'; +import { Delegatee } from './delegatee.model'; import { Department } from './v1/department.model'; export interface PlatformEmployee { @@ -9,4 +10,5 @@ export interface PlatformEmployee { department?: Department; department_id?: string; org_id: string; + delegatees?: Delegatee[]; } diff --git a/src/app/core/services/org-user.service.spec.ts b/src/app/core/services/org-user.service.spec.ts index a983489fce..d2e2af5b6a 100644 --- a/src/app/core/services/org-user.service.spec.ts +++ b/src/app/core/services/org-user.service.spec.ts @@ -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; @@ -30,10 +32,12 @@ describe('OrgUserService', () => { let authService: jasmine.SpyObj; let dataTransformService: jasmine.SpyObj; let apiV2Service: jasmine.SpyObj; + let spenderPlatformV1ApiService: jasmine.SpyObj; 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']); @@ -50,6 +54,10 @@ describe('OrgUserService', () => { provide: ApiV2Service, useValue: apiv2ServiceSpy, }, + { + provide: SpenderPlatformV1ApiService, + useValue: spenderPlatformV1ApiServiceSpy, + }, { provide: JwtHelperService, useValue: jwtHelperServiceSpy, @@ -71,6 +79,9 @@ describe('OrgUserService', () => { orgUserService = TestBed.inject(OrgUserService); apiService = TestBed.inject(ApiService) as jasmine.SpyObj; apiV2Service = TestBed.inject(ApiV2Service) as jasmine.SpyObj; + spenderPlatformV1ApiService = TestBed.inject( + SpenderPlatformV1ApiService + ) as jasmine.SpyObj; jwtHelperService = TestBed.inject(JwtHelperService) as jasmine.SpyObj; tokenService = TestBed.inject(TokenService) as jasmine.SpyObj; authService = TestBed.inject(AuthService) as jasmine.SpyObj; @@ -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(); }); }); diff --git a/src/app/core/services/org-user.service.ts b/src/app/core/services/org-user.service.ts index 3f70f2086f..7620ffec2a 100644 --- a/src/app/core/services/org-user.service.ts +++ b/src/app/core/services/org-user.service.ts @@ -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(); @@ -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() @@ -56,16 +60,10 @@ export class OrgUserService { } @Cacheable() - findDelegatedAccounts(): Observable { - return this.apiService.get('/eous/current/delegated_eous').pipe( - map((delegatedAccounts) => { - delegatedAccounts = delegatedAccounts.map((delegatedAccount) => - this.dataTransformService.unflatten(delegatedAccount) - ); - - return delegatedAccounts; - }) - ); + findDelegatedAccounts(): Observable { + return this.spenderPlatformV1ApiService + .get>('/employees/delegators') + .pipe(map((response) => response.data)); } postUser(user: User): Observable { 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 1a2b0113f1..5fead93323 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 @@ -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; @@ -50,4 +55,15 @@ describe('EmployeesService', () => { done(); }); }); + + it('getByParams(): should get employees by params', () => { + spenderService.get.and.returnValue(of(platformEmployeeResponse)); + const params: Partial = { + user_id: 'usJZ9bgfNB5n', + }; + + service.getByParams(params).subscribe((res) => { + expect(res).toBe(platformEmployeeResponse); + }); + }); }); diff --git a/src/app/core/services/platform/v1/spender/employees.service.ts b/src/app/core/services/platform/v1/spender/employees.service.ts index 8f90139038..e25c051b74 100644 --- a/src/app/core/services/platform/v1/spender/employees.service.ts +++ b/src/app/core/services/platform/v1/spender/employees.service.ts @@ -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', @@ -27,4 +28,8 @@ export class EmployeesService { }, }); } + + getByParams(params: Partial): Observable> { + return this.spenderService.get(`/employees`, { params }); + } } diff --git a/src/app/fyle/delegated-accounts/delegated-accounts.page.html b/src/app/fyle/delegated-accounts/delegated-accounts.page.html index 5ea42cdfa9..a79778491a 100644 --- a/src/app/fyle/delegated-accounts/delegated-accounts.page.html +++ b/src/app/fyle/delegated-accounts/delegated-accounts.page.html @@ -26,14 +26,12 @@ -
{{ acc?.us?.full_name | initials | uppercase }}
+
{{ acc?.full_name | initials | uppercase }}
-
{{acc?.us?.full_name}}
-
{{acc?.us?.email}}
-
- {{currentOrg.name}} -
+
{{acc?.full_name}}
+
{{acc?.email}}
+
{{currentOrg.name}}
diff --git a/src/app/fyle/delegated-accounts/delegated-accounts.page.spec.ts b/src/app/fyle/delegated-accounts/delegated-accounts.page.spec.ts index 1d7611cbfa..bde998ea0b 100644 --- a/src/app/fyle/delegated-accounts/delegated-accounts.page.spec.ts +++ b/src/app/fyle/delegated-accounts/delegated-accounts.page.spec.ts @@ -6,13 +6,15 @@ import { FormsModule } from '@angular/forms'; import { ActivatedRoute, Router } from '@angular/router'; import { of } from 'rxjs'; import { getElementRef } from 'src/app/core/dom-helpers'; -import { apiEouRes, eouRes2, eouRes3 } from 'src/app/core/mock-data/extended-org-user.data'; +import { apiEouRes, eouFlattended, eouRes2, eouUnFlattended } from 'src/app/core/mock-data/extended-org-user.data'; import { orgData1 } from 'src/app/core/mock-data/org.data'; import { LoaderService } from 'src/app/core/services/loader.service'; import { OrgUserService } from 'src/app/core/services/org-user.service'; import { OrgService } from 'src/app/core/services/org.service'; import { RecentLocalStorageItemsService } from 'src/app/core/services/recent-local-storage-items.service'; import { DelegatedAccountsPage } from './delegated-accounts.page'; +import { delegatorData } from 'src/app/core/mock-data/platform/v1/delegator.data'; +import { employeesParamsRes } from 'src/app/core/test-data/org-user.service.spec.data'; describe('DelegatedAccountsPage', () => { let component: DelegatedAccountsPage; @@ -30,6 +32,8 @@ describe('DelegatedAccountsPage', () => { 'switchToDelegatee', 'findDelegatedAccounts', 'excludeByStatus', + 'getEmployeesByParams', + 'getUserById', ]); const orgServiceSpy = jasmine.createSpyObj('OrgService', ['getCurrentOrg']); const routerSpy = jasmine.createSpyObj('Router', ['navigate']); @@ -99,15 +103,17 @@ describe('DelegatedAccountsPage', () => { loaderService.showLoader.and.resolveTo(); loaderService.hideLoader.and.resolveTo(); recentLocalStorageItemsService.clearRecentLocalStorageCache.and.returnValue(null); - orgUserService.switchToDelegator.and.returnValue(of(apiEouRes)); + orgUserService.getEmployeesByParams.and.returnValue(of(employeesParamsRes)); + orgUserService.getUserById.and.returnValue(of(eouFlattended)); + orgUserService.switchToDelegator.and.returnValue(of(eouUnFlattended)); - component.switchToDelegatee(eouRes2); + component.switchToDelegatee(delegatorData); tick(500); expect(loaderService.showLoader).toHaveBeenCalledTimes(1); expect(loaderService.hideLoader).toHaveBeenCalledTimes(1); expect(recentLocalStorageItemsService.clearRecentLocalStorageCache).toHaveBeenCalledTimes(1); - expect(orgUserService.switchToDelegator).toHaveBeenCalledOnceWith(eouRes2.ou); + expect(orgUserService.switchToDelegator).toHaveBeenCalledOnceWith(eouUnFlattended.ou); expect(router.navigate).toHaveBeenCalledOnceWith(['/', 'enterprise', 'my_dashboard']); })); @@ -132,21 +138,19 @@ describe('DelegatedAccountsPage', () => { component.searchDelegatees = getElementRef(fixture, '.delegated--search-input'); const input = component.searchDelegatees.nativeElement as HTMLInputElement; activatedRoute.snapshot.params.switchToOwn = null; - orgUserService.findDelegatedAccounts.and.returnValue(of([apiEouRes, eouRes2, eouRes3])); + orgUserService.findDelegatedAccounts.and.returnValue(of([delegatorData])); orgService.getCurrentOrg.and.returnValue(of(orgData1[0])); - orgUserService.excludeByStatus.and.returnValue([eouRes2, eouRes3]); component.ionViewWillEnter(); tick(500); - input.value = 'ajain@fyle.in'; + input.value = 'test@mail.com'; input.dispatchEvent(new Event('keyup')); tick(500); - expect(component.delegatedAccList).toEqual([eouRes2, eouRes3]); + expect(component.delegatedAccList).toEqual([delegatorData]); expect(orgUserService.findDelegatedAccounts).toHaveBeenCalledTimes(1); expect(orgService.getCurrentOrg).toHaveBeenCalledTimes(1); - expect(orgUserService.excludeByStatus).toHaveBeenCalledWith([apiEouRes, eouRes2, eouRes3], 'DISABLED'); })); it('should set delegatee acc list to empty array if no accounts are provided', fakeAsync(() => { @@ -167,7 +171,6 @@ describe('DelegatedAccountsPage', () => { expect(component.delegatedAccList).toEqual([]); expect(orgUserService.findDelegatedAccounts).toHaveBeenCalledTimes(1); expect(orgService.getCurrentOrg).toHaveBeenCalledTimes(1); - expect(orgUserService.excludeByStatus).toHaveBeenCalledWith([], 'DISABLED'); })); }); }); diff --git a/src/app/fyle/delegated-accounts/delegated-accounts.page.ts b/src/app/fyle/delegated-accounts/delegated-accounts.page.ts index a93535b0c2..bd0e9580e6 100644 --- a/src/app/fyle/delegated-accounts/delegated-accounts.page.ts +++ b/src/app/fyle/delegated-accounts/delegated-accounts.page.ts @@ -8,7 +8,9 @@ import { OrgUserService } from 'src/app/core/services/org-user.service'; import { OrgService } from 'src/app/core/services/org.service'; import { RecentLocalStorageItemsService } from 'src/app/core/services/recent-local-storage-items.service'; import { globalCacheBusterNotifier } from 'ts-cacheable'; -import { User } from 'src/app/core/models/user.model'; +import { Delegator } from 'src/app/core/models/platform/delegator.model'; +import { DataTransformService } from 'src/app/core/services/data-transform.service'; +import { EouApiResponse } from 'src/app/core/models/eou-api-response.model'; @Component({ selector: 'app-delegated-accounts', @@ -18,7 +20,7 @@ import { User } from 'src/app/core/models/user.model'; export class DelegatedAccountsPage { @ViewChild('searchDelegatees') searchDelegatees: ElementRef; - delegatedAccList; + delegatedAccList = []; currentOrg; @@ -27,16 +29,27 @@ export class DelegatedAccountsPage { constructor( private orgUserService: OrgUserService, private orgService: OrgService, + private dataTransformService: DataTransformService, private router: Router, private loaderService: LoaderService, private activatedRoute: ActivatedRoute, private recentLocalStorageItemsService: RecentLocalStorageItemsService ) {} - switchToDelegatee(eou: ExtendedOrgUser): void { + switchToDelegatee(delegator: Delegator): void { + const params = { + us_id: `eq.${delegator.user_id}`, + }; + from(this.loaderService.showLoader('Switching Account')) .pipe( - concatMap(() => { + concatMap(() => this.orgUserService.getEmployeesByParams(params)), + concatMap((employee) => + this.orgUserService + .getUserById(employee.data[0].ou_id) + .pipe(map((res) => this.dataTransformService.unflatten(res))) + ), + concatMap((eou) => { globalCacheBusterNotifier.next(); this.recentLocalStorageItemsService.clearRecentLocalStorageCache(); return this.orgUserService.switchToDelegator(eou.ou); @@ -84,14 +97,10 @@ export class DelegatedAccountsPage { distinctUntilChanged(), switchMap((searchText) => delegatedAccList$.pipe( - map(({ delegatedAcc }) => this.orgUserService.excludeByStatus(delegatedAcc, 'DISABLED')), - map((delegatees: ExtendedOrgUser[]) => - delegatees?.filter((delegatee: ExtendedOrgUser) => - Object.values(delegatee.us).some( - (delegateeProp: User) => - delegateeProp && - delegateeProp.toString() && - delegateeProp.toString().toLowerCase().includes(searchText.toLowerCase()) + map(({ delegatedAcc }) => + delegatedAcc.filter((delegator: Delegator) => + Object.values(delegator).some((delegatorProp: string) => + delegatorProp?.toString().toLowerCase().includes(searchText.toLowerCase()) ) ) ) diff --git a/src/app/fyle/notifications/notifications.page.spec.ts b/src/app/fyle/notifications/notifications.page.spec.ts index 5170b97d74..7df0125a71 100644 --- a/src/app/fyle/notifications/notifications.page.spec.ts +++ b/src/app/fyle/notifications/notifications.page.spec.ts @@ -21,6 +21,7 @@ import { OrgSettingsService } from 'src/app/core/services/org-settings.service'; import { OrgUserSettingsService } from 'src/app/core/services/org-user-settings.service'; import { orgSettingsData } from 'src/app/core/test-data/accounts.service.spec.data'; import { NotificationsPage } from './notifications.page'; +import { EmployeesService } from 'src/app/core/services/platform/v1/spender/employees.service'; export class NavMock { public navigateBack: Function = (url: string | any[], options: any) => {}; @@ -33,6 +34,7 @@ describe('NotificationsPage', () => { let fixture: ComponentFixture; let authService: jasmine.SpyObj; let orgUserSettingsService: jasmine.SpyObj; + let employeesService: jasmine.SpyObj; let fb: FormBuilder; let orgSettingsService: jasmine.SpyObj; let router: jasmine.SpyObj; @@ -46,6 +48,7 @@ describe('NotificationsPage', () => { 'get', 'getNotificationEvents', ]); + const employeesServiceSpy = jasmine.createSpyObj('EmployeesService', ['getByParams']); const orgSettingsServiceSpy = jasmine.createSpyObj('OrgSettingsService', ['get']); const routerSpy = jasmine.createSpyObj('Router', ['navigate']); @@ -62,6 +65,10 @@ describe('NotificationsPage', () => { provide: OrgUserSettingsService, useValue: orgUserSettingsServiceSpy, }, + { + provide: EmployeesService, + useValue: employeesServiceSpy, + }, { provide: OrgSettingsService, useValue: orgSettingsServiceSpy, @@ -83,6 +90,7 @@ describe('NotificationsPage', () => { authService = TestBed.inject(AuthService) as jasmine.SpyObj; orgUserSettingsService = TestBed.inject(OrgUserSettingsService) as jasmine.SpyObj; + employeesService = TestBed.inject(EmployeesService) as jasmine.SpyObj; orgSettingsService = TestBed.inject(OrgSettingsService) as jasmine.SpyObj; router = TestBed.inject(Router) as jasmine.SpyObj; navController = TestBed.inject(NavController) as jasmine.SpyObj; @@ -95,6 +103,7 @@ describe('NotificationsPage', () => { }); orgUserSettingsService.get.and.returnValue(of(orgUserSettingsData)); + employeesService.getByParams.and.returnValue(of(null)); authService.getEou.and.resolveTo(apiEouRes); orgSettingsService.get.and.returnValue(of(orgSettingsData)); orgUserSettingsService.getNotificationEvents.and.returnValue(of(notificationEventsData)); diff --git a/src/app/fyle/notifications/notifications.page.ts b/src/app/fyle/notifications/notifications.page.ts index 77ad6ba9da..ee10eaac13 100644 --- a/src/app/fyle/notifications/notifications.page.ts +++ b/src/app/fyle/notifications/notifications.page.ts @@ -3,7 +3,7 @@ import { FormArray, FormBuilder, FormControl, FormGroup } from '@angular/forms'; import { Router } from '@angular/router'; import { NavController } from '@ionic/angular'; import { Observable, from, noop, zip } from 'rxjs'; -import { finalize, map } from 'rxjs/operators'; +import { finalize, map, switchMap } from 'rxjs/operators'; import { EmailEvents, NotificationEventFeatures, @@ -14,6 +14,7 @@ import { OrgUserSettings } from 'src/app/core/models/org_user_settings.model'; import { AuthService } from 'src/app/core/services/auth.service'; import { OrgSettingsService } from 'src/app/core/services/org-settings.service'; import { OrgUserSettingsService } from 'src/app/core/services/org-user-settings.service'; +import { EmployeesService } from 'src/app/core/services/platform/v1/spender/employees.service'; @Component({ selector: 'app-notifications', @@ -54,7 +55,8 @@ export class NotificationsPage implements OnInit { private formBuilder: FormBuilder, private orgSettingsService: OrgSettingsService, private router: Router, - private navController: NavController + private navController: NavController, + private employeesService: EmployeesService ) {} get pushEvents(): FormArray { @@ -282,7 +284,10 @@ export class NotificationsPage implements OnInit { this.notificationForm.controls.notifyOption.setValue(notifyOption); }); - this.isDelegateePresent$ = from(this.authService.getEou()).pipe(map((eou) => eou.ou.delegatee_id !== null)); + this.isDelegateePresent$ = from(this.authService.getEou()).pipe( + switchMap((res) => this.employeesService.getByParams({ user_id: `eq.${res.us.id}` })), + map((employee) => employee?.data?.delegatees?.length > 0) + ); this.orgSettings$ = this.orgSettingsService.get(); this.notificationEvents$ = this.orgUserSettingsService.getNotificationEvents(); diff --git a/src/app/shared/components/sidemenu/sidemenu.component.spec.ts b/src/app/shared/components/sidemenu/sidemenu.component.spec.ts index 40f01ef035..145803e99d 100644 --- a/src/app/shared/components/sidemenu/sidemenu.component.spec.ts +++ b/src/app/shared/components/sidemenu/sidemenu.component.spec.ts @@ -33,6 +33,7 @@ import { getSecondarySidemenuOptionsRes1, setSideMenuRes, } from 'src/app/core/mock-data/sidemenu.data'; +import { delegatorData } from 'src/app/core/mock-data/platform/v1/delegator.data'; describe('SidemenuComponent', () => { let component: SidemenuComponent; @@ -509,17 +510,13 @@ describe('SidemenuComponent', () => { orgService.getPrimaryOrg.and.returnValue(of(orgData1[0])); orgSettingsService.get.and.returnValue(of(orgSettingsRes)); orgUserSettingsService.get.and.returnValue(of(orgUserSettingsData)); - orgUserService.findDelegatedAccounts.and.returnValue(of([currentEouRes])); + orgUserService.findDelegatedAccounts.and.returnValue(of([delegatorData])); deviceService.getDeviceInfo.and.returnValue(of(extendedDeviceInfoMockData)); orgUserService.isSwitchedToDelegator.and.resolveTo(false); orgUserService.getCurrent.and.returnValue(of(currentEouRes)); sidemenuService.getAllowedActions.and.returnValue(of(sidemenuAllowedActions)); - const status = 'DISABLED'; - const eousFiltered = eouListWithDisabledUser.filter((eou) => status.indexOf(eou.ou.status) === -1); - orgUserService.excludeByStatus.and.returnValue(eousFiltered); - component.showSideMenuOnline(); tick(500); expect(routerAuthService.isLoggedIn).toHaveBeenCalledTimes(1); @@ -531,7 +528,6 @@ describe('SidemenuComponent', () => { expect(orgSettingsService.get).toHaveBeenCalledTimes(1); expect(orgUserSettingsService.get).toHaveBeenCalledTimes(1); expect(orgUserService.findDelegatedAccounts).toHaveBeenCalledTimes(1); - expect(orgUserService.excludeByStatus).toHaveBeenCalledOnceWith([currentEouRes], 'DISABLED'); expect(deviceService.getDeviceInfo).toHaveBeenCalledTimes(1); })); }); diff --git a/src/app/shared/components/sidemenu/sidemenu.component.ts b/src/app/shared/components/sidemenu/sidemenu.component.ts index 4d6db8fa7d..d9c0c16ea1 100644 --- a/src/app/shared/components/sidemenu/sidemenu.component.ts +++ b/src/app/shared/components/sidemenu/sidemenu.component.ts @@ -106,9 +106,7 @@ export class SidemenuComponent implements OnInit { const primaryOrg$ = this.orgService.getPrimaryOrg().pipe(shareReplay(1)); const orgSettings$ = this.orgSettingsService.get().pipe(shareReplay(1)); const orgUserSettings$ = this.orgUserSettingsService.get(); - const delegatedAccounts$ = this.orgUserService - .findDelegatedAccounts() - .pipe(map((res) => this.orgUserService.excludeByStatus(res, 'DISABLED'))); + const delegatedAccounts$ = this.orgUserService.findDelegatedAccounts(); const deviceInfo$ = this.deviceService.getDeviceInfo().pipe(shareReplay(1)); const isSwitchedToDelegator$ = from(this.orgUserService.isSwitchedToDelegator()); const allowedActions$ = this.sidemenuService.getAllowedActions();