Skip to content
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

feat: Migrate /v2/spender_employees to platform #3562

Merged
merged 6 commits into from
Mar 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
159 changes: 84 additions & 75 deletions src/app/core/mock-data/employee.data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,132 +2,141 @@ import deepFreeze from 'deep-freeze-strict';

import { Employee } from '../models/spender/employee.model';

export const selectedItem: Record<string, boolean> = deepFreeze({
'[email protected]': true,
'[email protected]': true,
'[email protected]': true,
'[email protected]': true,
'[email protected]': true,
'[email protected]': true,
});

export const selectedOptionRes: Partial<Employee> = deepFreeze({
ou_id: 'oubQzXeZbwbS',
ou_org_id: 'orNVthTo2Zyo',
ou_roles: '["FYLER","APPROVER","HOD","HOP","AUDITOR","FINANCE"]',
ou_status: '"ACTIVE"',
us_email: '[email protected]',
us_full_name: 'AA',
us_id: 'usTdvbcxOqjs',
id: 'oubQzXeZbwbS',
roles: '["FYLER","APPROVER","HOD","HOP","AUDITOR","FINANCE"]',
is_enabled: true,
has_accepted_invite: true,
email: '[email protected]',
full_name: 'AA',
user_id: 'usTdvbcxOqjs',
is_selected: false,
});

export const filteredOptionsRes: Partial<Employee>[] = deepFreeze([
{
ou_id: 'oubQzXeZbwbS',
ou_org_id: 'orNVthTo2Zyo',
ou_roles: '["FYLER","APPROVER","HOD","HOP","AUDITOR","FINANCE"]',
ou_status: '"ACTIVE"',
us_email: '[email protected]',
us_full_name: 'AA',
us_id: 'usTdvbcxOqjs',
id: 'oubQzXeZbwbS',
roles: '["FYLER","APPROVER","HOD","HOP","AUDITOR","FINANCE"]',
is_enabled: true,
has_accepted_invite: true,
email: '[email protected]',
full_name: 'AA',
user_id: 'usTdvbcxOqjs',
is_selected: true,
},
{
ou_id: 'oumDNNh9CfNY',
ou_org_id: 'orNVthTo2Zyo',
ou_roles: '["FYLER","FINANCE","ADMIN","APPROVER"]',
ou_status: '"PENDING_DETAILS"',
us_email: '[email protected]',
us_full_name: 'Aastha',
us_id: 'usqeLyJzMvjv',
id: 'oumDNNh9CfNY',
roles: '["FYLER","FINANCE","ADMIN","APPROVER"]',
is_enabled: true,
has_accepted_invite: false,
email: '[email protected]',
full_name: 'Aastha',
user_id: 'usqeLyJzMvjv',
is_selected: false,
},
{
ou_id: 'ouPoW69slRBp',
ou_org_id: 'orNVthTo2Zyo',
ou_roles: '["FYLER","APPROVER","HOD","HOP","ADMIN","PAYMENT_PROCESSOR"]',
ou_status: '"ACTIVE"',
us_email: '[email protected]',
us_full_name: 'Aastha B',
us_id: 'usRjTPO4r69K',
id: 'ouPoW69slRBp',
roles: '["FYLER","APPROVER","HOD","HOP","ADMIN","PAYMENT_PROCESSOR"]',
is_enabled: true,
has_accepted_invite: true,
email: '[email protected]',
full_name: 'Aastha B',
user_id: 'usRjTPO4r69K',
is_selected: false,
},
{
ou_id: 'ouE7qv3Y45oz',
ou_org_id: 'orNVthTo2Zyo',
ou_roles: '["FYLER","APPROVER","FINANCE","HOP"]',
ou_status: '"ACTIVE"',
us_email: '[email protected]',
us_full_name: 'abcdd',
us_id: 'usQx07v17BX5',
id: 'ouE7qv3Y45oz',
roles: '["FYLER","APPROVER","FINANCE","HOP"]',
is_enabled: true,
has_accepted_invite: true,
email: '[email protected]',
full_name: 'abcdd',
user_id: 'usQx07v17BX5',
is_selected: false,
},
{
ou_id: 'ouKmdituKMi9',
ou_org_id: 'orNVthTo2Zyo',
ou_roles: '["APPROVER","FYLER","AUDITOR","HOP","HOD","ADMIN"]',
ou_status: '"ACTIVE"',
us_email: '[email protected]',
us_full_name: 'Abhishek',
us_id: 'usrLNunqplye',
id: 'ouKmdituKMi9',
roles: '["APPROVER","FYLER","AUDITOR","HOP","HOD","ADMIN"]',
is_enabled: true,
has_accepted_invite: true,
email: '[email protected]',
full_name: 'Abhishek',
user_id: 'usrLNunqplye',
is_selected: false,
},
{
ou_id: 'ouTi8ul9u51y',
ou_org_id: 'orNVthTo2Zyo',
ou_roles: '["FYLER"]',
ou_status: '"PENDING_DETAILS"',
us_email: '[email protected]',
us_full_name: 'Abhishek',
us_id: 'usi3jriNhseA',
id: 'ouTi8ul9u51y',
roles: '["FYLER"]',
is_enabled: true,
has_accepted_invite: false,
email: '[email protected]',
full_name: 'Abhishek',
user_id: 'usi3jriNhseA',
is_selected: false,
},
]);

export const filteredDataRes: Partial<Employee>[] = deepFreeze([
{
us_email: '[email protected]',
email: '[email protected]',
is_selected: true,
},
{
us_email: '[email protected]',
email: '[email protected]',
is_selected: true,
},
{
us_email: '[email protected]',
email: '[email protected]',
is_selected: true,
},
{
us_email: '[email protected]',
email: '[email protected]',
is_selected: true,
},
{
us_email: '[email protected]',
email: '[email protected]',
is_selected: true,
},
]);

export const searchedUserListRes: Partial<Employee>[] = deepFreeze([
{
ou_id: 'oubQzXeZbwbS',
ou_org_id: 'orNVthTo2Zyo',
ou_roles: '["FYLER","APPROVER","HOD","HOP"]',
ou_status: '"ACTIVE"',
us_email: '[email protected]',
us_full_name: 'AA23',
us_id: 'usTdvbcxOqjs',
id: 'oubQzXeZbwbS',
roles: '["FYLER","APPROVER","HOD","HOP"]',
is_enabled: true,
has_accepted_invite: true,
email: '[email protected]',
full_name: 'AA23',
user_id: 'usTdvbcxOqjs',
is_selected: true,
},
{
ou_id: 'ouXYHXfr4w0b',
ou_org_id: 'orNVthTo2Zyo',
ou_roles: '["FYLER","APPROVER","HOP"]',
ou_status: '"PENDING_DETAILS"',
us_email: '[email protected]',
us_full_name: 'AAA',
us_id: 'usBBavu872gu',
id: 'ouXYHXfr4w0b',
roles: '["FYLER","APPROVER","HOP"]',
is_enabled: true,
has_accepted_invite: false,
email: '[email protected]',
full_name: 'AAA',
user_id: 'usBBavu872gu',
is_selected: true,
},
{
ou_id: 'ouX8dwsbLCLv',
ou_org_id: 'orNVthTo2Zyo',
ou_roles: '["FINANCE","ADMIN","APPROVER","FYLER","VERIFIER","PAYMENT_PROCESSOR","AUDITOR","HOP","HOD","OWNER"]',
ou_status: '"ACTIVE"',
us_email: '[email protected]',
us_full_name: 'Abhishek Jain',
us_id: 'usvKA4X8Ugcr',
id: 'ouX8dwsbLCLv',
roles: '["FINANCE","ADMIN","APPROVER","FYLER","VERIFIER","PAYMENT_PROCESSOR","AUDITOR","HOP","HOD","OWNER"]',
is_enabled: true,
has_accepted_invite: true,
email: '[email protected]',
full_name: 'Abhishek Jain',
user_id: 'usvKA4X8Ugcr',
is_selected: false,
},
]);
13 changes: 7 additions & 6 deletions src/app/core/models/employee-params.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ export interface EmployeeParams {
or: string;
and: string;
select: string;
ou_org_id: string;
ou_roles: string;
ou_status: string;
ou_id: string;
org_id: string;
roles: string;
is_enabled: string;
has_accepted_invite: string;
id: string;
order: string;
limit: number;
us_email?: string;
us_id: string;
email?: string;
user_id: string;
}
14 changes: 7 additions & 7 deletions src/app/core/models/spender/employee.model.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
export interface Employee {
ou_id: string;
ou_org_id: string;
ou_roles: string;
ou_status: string;
us_email: string;
us_full_name: string;
us_id: string;
id: string;
roles: string;
is_enabled: boolean;
has_accepted_invite: boolean;
email: string;
full_name: string;
user_id: string;
is_selected?: boolean; // used to show checkmarks while selecting employee
}
Comment on lines 1 to 10
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Model restructured with blockbuster impact!

Mind it! This is not just a minor change, this is a complete model transformation! The old prefixed properties (ou_id, ou_org_id, ou_roles, ou_status, us_email, us_full_name, us_id) have been replaced with cleaner, more direct properties.

The new boolean properties is_enabled and has_accepted_invite provide better type safety than the previous string-based status. This change is as impactful as my slow-motion walk into a fight scene - powerful and purposeful!

One concern though: verify that all references to this model throughout the application have been updated to match this new structure.


🏁 Script executed:

#!/bin/bash
# Check if there are any remaining references to the old property names
echo "Checking for any remaining references to old property names..."
rg "us_email|us_full_name|ou_id|ou_org_id|ou_roles|ou_status" --type ts

Length of output: 65924


Heads up, my friend—blockbuster transformation achieved, but some shadows of the old remain!

Your new Employee model is as powerful as a Rajini punch—with cleaner, direct properties and improved type safety. However, the grep shows that many parts of the codebase (especially in test-data, mock-data, and related models) still reference the old property names like ou_id, us_email, us_full_name, and so on. For example:

  • src/app/core/mock-data/employee.data.ts and src/app/core/test-data/status.service.spec.data.ts still contain these old identifiers.
  • Similar references appear in other models and service specifications.

Please update these references accordingly to harmonize the entire codebase with your new structure, or ensure a proper migration layer exists to handle the old keys safely.

Keep rocking like a superstar!

46 changes: 19 additions & 27 deletions src/app/core/services/org-user.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
accessTokenData,
accessTokenWithProxyOrgUserId,
} from '../test-data/org-user.service.spec.data';
import { ApiV2Service } from './api-v2.service';
import { ApiService } from './api.service';
import { AuthService } from './auth.service';
import { DataTransformService } from './data-transform.service';
Expand All @@ -31,12 +30,10 @@ describe('OrgUserService', () => {
let apiService: jasmine.SpyObj<ApiService>;
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']);
Expand All @@ -50,10 +47,6 @@ describe('OrgUserService', () => {
provide: ApiService,
useValue: apiServiceSpy,
},
{
provide: ApiV2Service,
useValue: apiv2ServiceSpy,
},
{
provide: SpenderPlatformV1ApiService,
useValue: spenderPlatformV1ApiServiceSpy,
Expand All @@ -78,7 +71,6 @@ 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>;
Expand Down Expand Up @@ -113,50 +105,50 @@ describe('OrgUserService', () => {
});

it('should be able to get employees by params', (done) => {
apiV2Service.get.and.returnValue(of(employeesRes));
spenderPlatformV1ApiService.get.and.returnValue(of(employeesRes));
const params = {
limit: 5,
order: 'us_full_name.asc,ou_id',
ou_id: 'not.eq.ouX8dwsbLCLv',
ou_org_id: 'eq.orNVthTo2Zyo',
ou_roles: 'like.%ADMIN%',
ou_status: 'eq."ACTIVE"',
select: 'us_full_name,us_email',
order: 'full_name.asc',
id: 'neq.ouX8dwsbLCLv',
roles: 'like.%ADMIN%',
is_enabled: 'eq.true',
has_accepted_invite: 'eq.true',
select: 'full_name,email',
};
orgUserService.getEmployeesByParams(params).subscribe((res) => {
expect(res).toEqual(employeesRes);
expect(apiV2Service.get).toHaveBeenCalledWith('/spender_employees', { params });
expect(spenderPlatformV1ApiService.get).toHaveBeenCalledWith('/employees', { params });
done();
});
});

it('should be able to get employees by search with OR param', (done) => {
const params = {
order: 'us_full_name.asc,us_email.asc,ou_id',
us_email: 'in.([email protected])',
or: '(ou_status.like.*"ACTIVE",ou_status.like.*"PENDING_DETAILS")',
and: '(or(ou_status.like.*"ACTIVE",ou_status.like.*"PENDING_DETAILS"),or(ou_status.like.*"ACTIVE",ou_status.like.*"PENDING_DETAILS"))',
order: 'full_name.asc,email.asc',
email: 'in.([email protected])',
or: '(is_enabled.eq.true)',
and: '(or(is_enabled.eq.true),or(is_enabled.eq.true))',
};
apiV2Service.get.and.returnValue(of(employeesParamsRes));
spenderPlatformV1ApiService.get.and.returnValue(of(employeesParamsRes));

orgUserService.getEmployeesBySearch(params).subscribe((res) => {
expect(res).toEqual(employeesParamsRes.data);
expect(apiV2Service.get).toHaveBeenCalledWith('/spender_employees', { params });
expect(spenderPlatformV1ApiService.get).toHaveBeenCalledWith('/employees', { params });
done();
});
});

it('should be able to get employees by search without OR param', (done) => {
const params = {
order: 'us_full_name.asc,us_email.asc,ou_id',
us_email: 'in.([email protected])',
and: '(or(ou_status.like.*"ACTIVE",ou_status.like.*"PENDING_DETAILS"),or(ou_status.like.*"ACTIVE",ou_status.like.*"PENDING_DETAILS"))',
order: 'full_name.asc,email.asc,id',
email: 'in.([email protected])',
and: '(or(is_enabled.eq.true),or(is_enabled.eq.true))',
};
apiV2Service.get.and.returnValue(of(employeesParamsRes));
spenderPlatformV1ApiService.get.and.returnValue(of(employeesParamsRes));

orgUserService.getEmployeesBySearch(params).subscribe((res) => {
expect(res).toEqual(employeesParamsRes.data);
expect(apiV2Service.get).toHaveBeenCalledWith('/spender_employees', { params });
expect(spenderPlatformV1ApiService.get).toHaveBeenCalledWith('/employees', { params });
done();
});
});
Expand Down
Loading