Skip to content

Commit

Permalink
feat: Add Virtual Card Changes (#2694)
Browse files Browse the repository at this point in the history
  • Loading branch information
bistaastha authored Feb 21, 2024
1 parent b37db34 commit ca1c375
Show file tree
Hide file tree
Showing 45 changed files with 1,254 additions and 45 deletions.
8 changes: 8 additions & 0 deletions src/app/core/enums/card-status.enum.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export enum CardStatus {
ACTIVE = 'ACTIVE',
PREACTIVE = 'PREACTIVE',
INACTIVE = 'INACTIVE',
USED = 'USED',
DELETED = 'DELETED',
EXPIRED = 'EXPIRED',
}
4 changes: 4 additions & 0 deletions src/app/core/enums/manage-cards-page-segment.enum.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export enum ManageCardsPageSegment {
CORPORATE_CARDS,
VIRTUAL_CARDS,
}
15 changes: 15 additions & 0 deletions src/app/core/mock-data/org-settings.data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,11 @@ export const orgSettingsRes: OrgSettings = {
allowed: true,
enabled: true,
},
amex_feed_enrollment_settings: {
allowed: true,
enabled: true,
virtual_card_settings_enabled: true,
},
};

export const orgSettingsParams2: OrgSettings = {
Expand Down Expand Up @@ -804,6 +809,11 @@ export const orgSettingsParams2: OrgSettings = {
allowed: true,
enabled: true,
},
amex_feed_enrollment_settings: {
allowed: true,
enabled: true,
virtual_card_settings_enabled: true,
},
};

export const orgSettingsParamWoCCC: OrgSettings = {
Expand Down Expand Up @@ -1184,6 +1194,11 @@ export const orgSettingsParamWoCCC: OrgSettings = {
allowed: true,
enabled: true,
},
amex_feed_enrollment_settings: {
allowed: true,
enabled: true,
virtual_card_settings_enabled: true,
},
};

export const orgSettingsCCCDisabled: OrgSettings = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
import { PlatformCorporateCardDetail } from '../models/platform-corporate-card-detail.model';
import { mastercardRTFCard, statementUploadedCard, visaRTFCard } from './platform-corporate-card.data';
import { mastercardRTFCard, statementUploadedCard, virtualCard, visaRTFCard } from './platform-corporate-card.data';
import { virtualCardCombinedResponse } from './virtual-card-combined-response.data';

export const virtualCardDetails: PlatformCorporateCardDetail[] = [
{
card: virtualCard,
stats: {
totalDraftTxns: 0,
totalDraftValue: 0,
totalCompleteTxns: 0,
totalCompleteExpensesValue: 0,
totalTxnsCount: 0,
totalAmountValue: 0,
},
},
];

export const cardDetailsRes: PlatformCorporateCardDetail[] = [
{
Expand Down Expand Up @@ -35,6 +50,7 @@ export const cardDetailsRes: PlatformCorporateCardDetail[] = [
totalAmountValue: 2624.27,
},
},
virtualCardDetails[0],
];

export const statementUploadedCardDetail: PlatformCorporateCardDetail[] = [
Expand All @@ -50,3 +66,10 @@ export const statementUploadedCardDetail: PlatformCorporateCardDetail[] = [
},
},
];

export const virtualCardDetailsCombined: PlatformCorporateCardDetail[] = [
{
...virtualCardDetails[0],
virtualCardDetail: virtualCardCombinedResponse['vc1234'],
},
];
26 changes: 26 additions & 0 deletions src/app/core/mock-data/platform-corporate-card.data.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { CardStatus } from '../enums/card-status.enum';
import { DataFeedSource } from '../enums/data-feed-source.enum';
import { PlatformCorporateCard } from '../models/platform/platform-corporate-card.model';

Expand Down Expand Up @@ -70,6 +71,31 @@ export const statementUploadedCard: PlatformCorporateCard = {
verification_status: 'NOT_VERIFIED',
};

export const virtualCard: PlatformCorporateCard = {
assignor_user_id: 'usvKA4X8Ugcr',
bank_name: 'American Express',
card_number: '5555',
cardholder_name: null,
code: null,
created_at: '2023-03-03T07:16:46.376082+00:00',
data_feed_source: null,
id: 'bacc15bbrRGWzf',
is_dummy: false,
is_mastercard_enrolled: false,
is_visa_enrolled: false,
last_assigned_at: '2023-03-03T07:16:46.376082+00:00',
last_ready_for_verification_at: null,
last_synced_at: null,
last_verification_attempt_at: null,
last_verified_at: null,
org_id: 'orNVthTo2Zyo',
updated_at: '2023-03-03T07:16:46.376082+00:00',
user_id: 'usvKA4X8Ugcr',
verification_status: 'NOT_VERIFIED',
virtual_card_id: 'vc1234',
virtual_card_state: CardStatus.PREACTIVE,
};

export const bankFeedCard: PlatformCorporateCard = {
assignor_user_id: 'usvKA4X8Ugcr',
bank_name: 'MASTERCARD_BANK',
Expand Down
9 changes: 9 additions & 0 deletions src/app/core/mock-data/virtual-card-combined-response.data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export const virtualCardCombinedResponse = {
vc1234: {
full_card_number: '123451234512345',
cvv: '1234',
expiry_date: new Date('2029-01-01T00:00:00+00:00'),
nick_name: 'Nickname',
current_amount: 1000,
},
};
17 changes: 17 additions & 0 deletions src/app/core/mock-data/virtual-card-details-response.data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { CardDetailsAmountResponse } from '../models/card-details-amount-response';
import { CardDetailsResponse } from '../models/card-details-response.model';

export const virtualCardDetailsResponse: { data: CardDetailsResponse } = {
data: {
full_card_number: '123412341234123',
cvv: '123',
// @ts-ignore
expiry_date: '2029-01-01T00:00:00+00:00',
},
};

export const virtualCardCurrentAmountResponse: { data: CardDetailsAmountResponse } = {
data: {
current_amount: 1000,
},
};
31 changes: 31 additions & 0 deletions src/app/core/mock-data/virtual-card-response.data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { CardStatus } from '../enums/card-status.enum';
import { PlatformApiResponse } from '../models/platform/platform-api-response.model';
import { VirtualCard } from '../models/virtual-card.model';

export const virtualCardResponse: PlatformApiResponse<VirtualCard> = {
count: 1,
data: [
{
amex_account_id: 'amacume6Bw1WQ2',
created_at: '2024-02-06T20:16:33.981634+00:00',
creator_user_id: 'us3csPBnWxv6',
expiry_date: '2029-02-01T00:00:00+00:00',
id: 'vcgNQmrZvGhL',
last_five: '35799',
nick_name: 'Demo Cad',
org_id: 'or76bSzYIDxb',
state: CardStatus.INACTIVE,
updated_at: '2024-02-06T20:16:33.981634+00:00',
user_id: 'usqigaQKd1sI',
valid_from_at: '2024-02-06T00:00:00+00:00',
valid_till_at: '2024-02-08T00:00:00+00:00',
},
],
offset: 0,
};

export const virtualCardUndefinedResponse: PlatformApiResponse<VirtualCard> = {
count: 0,
data: undefined,
offset: 0,
};
4 changes: 4 additions & 0 deletions src/app/core/mock-data/virtual-cards-combined-request.data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const virtualCardCombinedRequest = {
virtualCardIds: ['vcgNQmrZvGhL'],
includeCurrentAmount: true,
};
3 changes: 3 additions & 0 deletions src/app/core/models/card-details-amount-response.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface CardDetailsAmountResponse {
current_amount: number;
}
7 changes: 7 additions & 0 deletions src/app/core/models/card-details-combined-response.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export interface CardDetailsCombinedResponse {
full_card_number: string;
cvv: string;
expiry_date: Date;
nick_name?: string;
current_amount?: number;
}
5 changes: 5 additions & 0 deletions src/app/core/models/card-details-response.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export interface CardDetailsResponse {
full_card_number: string;
cvv: string;
expiry_date: Date;
}
6 changes: 6 additions & 0 deletions src/app/core/models/org-settings.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,10 @@ export interface DataExtractionSettings extends CommonOrgSettings {
web_app_pdf?: boolean;
}

export interface AmexFeedEnrollmentSettings extends CommonOrgSettings {
virtual_card_settings_enabled: boolean;
}

export interface SplitExpenseSettings {
enabled?: boolean;
}
Expand Down Expand Up @@ -444,6 +448,7 @@ export interface OrgSettingsResponse {
xe_provider_settings?: XeProviderSettings;
simplified_report_closure_settings?: CommonOrgSettings;
mobile_app_my_expenses_beta_enabled?: boolean;
amex_feed_enrollment_settings?: AmexFeedEnrollmentSettings;
}

export interface UiPolicySettings {
Expand Down Expand Up @@ -555,4 +560,5 @@ export interface OrgSettings {
company_expenses_beta_settings?: CommonOrgSettings;
simplified_report_closure_settings?: CommonOrgSettings;
mobile_app_my_expenses_beta_enabled?: boolean;
amex_feed_enrollment_settings?: AmexFeedEnrollmentSettings;
}
2 changes: 2 additions & 0 deletions src/app/core/models/platform-corporate-card-detail.model.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { CardDetailsCombinedResponse } from './card-details-combined-response.model';
import { PlatformCorporateCard } from './platform/platform-corporate-card.model';

export interface PlatformCorporateCardDetail {
Expand All @@ -10,4 +11,5 @@ export interface PlatformCorporateCardDetail {
totalDraftTxns: number;
totalDraftValue: number;
};
virtualCardDetail?: CardDetailsCombinedResponse;
}
2 changes: 2 additions & 0 deletions src/app/core/models/platform/platform-corporate-card.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ export interface PlatformCorporateCard {
updated_at: string;
user_id: string;
verification_status: string;
virtual_card_id?: string;
virtual_card_state?: string;
}
17 changes: 17 additions & 0 deletions src/app/core/models/virtual-card.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { CardStatus } from '../enums/card-status.enum';

export interface VirtualCard {
id: string;
state: CardStatus;
last_five: string;
expiry_date: string;
created_at: string;
updated_at: string;
org_id: string;
amex_account_id: string;
valid_from_at: string;
valid_till_at: string;
user_id: string;
creator_user_id: string;
nick_name: string;
}
4 changes: 4 additions & 0 deletions src/app/core/models/virtual-cards-combined-request.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface VirtualCardsCombinedRequest {
virtualCardIds: string[];
includeCurrentAmount?: boolean;
}
3 changes: 3 additions & 0 deletions src/app/core/models/virtual-cards-request.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface VirtualCardsRequest {
id: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { eCCCApiResponse } from '../mock-data/corporate-card-expense-flattened.d
import { mastercardRTFCard, statementUploadedCard } from '../mock-data/platform-corporate-card.data';
import { StatsResponse } from '../models/v2/stats-response.model';
import { bankFeedSourcesData } from '../mock-data/bank-feed-sources.data';
import { statementUploadedCardDetail } from '../mock-data/platform-corporate-card-detail-data';
import { statementUploadedCardDetail } from '../mock-data/platform-corporate-card-detail.data';

describe('CorporateCreditCardExpenseService', () => {
let cccExpenseService: CorporateCreditCardExpenseService;
Expand Down Expand Up @@ -65,7 +65,7 @@ describe('CorporateCreditCardExpenseService', () => {
apiV2Service = TestBed.inject(ApiV2Service) as jasmine.SpyObj<ApiV2Service>;
authService = TestBed.inject(AuthService) as jasmine.SpyObj<AuthService>;
spenderPlatformV1ApiService = TestBed.inject(
SpenderPlatformV1ApiService,
SpenderPlatformV1ApiService
) as jasmine.SpyObj<SpenderPlatformV1ApiService>;
dataTransformService = TestBed.inject(DataTransformService);
dateService = TestBed.inject(DateService) as jasmine.SpyObj<DateService>;
Expand Down Expand Up @@ -127,7 +127,7 @@ describe('CorporateCreditCardExpenseService', () => {
queryParams +
'&corporate_credit_card_account_number=not.is.null&debit=is.true&tx_org_user_id=eq.' +
apiEouRes.ou.id,
{},
{}
);
expect(cccExpenseService.constructInQueryParamStringForV2).toHaveBeenCalledOnceWith(['COMPLETE', 'DRAFT']);
done();
Expand All @@ -143,7 +143,7 @@ describe('CorporateCreditCardExpenseService', () => {
it('getPlatformCorporateCardDetails(): should get corporate card details', () => {
const result = cccExpenseService.getPlatformCorporateCardDetails(
[statementUploadedCard],
mastercardCCCStats.cardDetails,
mastercardCCCStats.cardDetails
);

expect(result).toEqual(statementUploadedCardDetail);
Expand Down
10 changes: 10 additions & 0 deletions src/app/core/services/org-settings.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import {
incomingQuickbooksAccountingObjWithoutSettings,
outgoingAccountingQuickbooksObjWithoutSettings,
outgoingAccountingTallyObjWithoutSettings,
orgSettingsAmexFeedDataRequest,
orgSettingsAmexFeedDataResponse,
} from '../test-data/org-settings.service.spec.data';

import { OrgSettingsService } from './org-settings.service';
Expand Down Expand Up @@ -132,4 +134,12 @@ describe('OrgSettingsService', () => {
outgoingAccountingQuickbooksObjectWithoutSettings
);
});

it('should be able to get the org settings properly for undefined amex feed enrollment values', (done) => {
apiService.get.and.returnValue(of(orgSettingsAmexFeedDataRequest));
orgSettingsService.get().subscribe((res) => {
expect(res).toEqual(orgSettingsAmexFeedDataResponse);
done();
});
});
});
10 changes: 8 additions & 2 deletions src/app/core/services/org-settings.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,11 @@ export class OrgSettingsService {
enabled: incoming?.simplified_report_closure_settings?.enabled,
},
mobile_app_my_expenses_beta_enabled: incoming?.mobile_app_my_expenses_beta_enabled,
amex_feed_enrollment_settings: {
allowed: incoming?.amex_feed_enrollment_settings?.allowed,
enabled: incoming?.amex_feed_enrollment_settings?.enabled,
virtual_card_settings_enabled: incoming?.amex_feed_enrollment_settings?.virtual_card_settings_enabled,
},
};

Object.keys(orgSettings).forEach((settingsType) => {
Expand Down Expand Up @@ -552,8 +557,9 @@ export class OrgSettingsService {
company_expenses_beta_settings: outgoing.company_expenses_beta_settings,
visa_enrollment_settings: outgoing.visa_enrollment_settings,
mastercard_enrollment_settings: outgoing.mastercard_enrollment_settings,
simplified_report_closure_settings: outgoing?.simplified_report_closure_settings,
mobile_app_my_expenses_beta_enabled: outgoing?.mobile_app_my_expenses_beta_enabled,
simplified_report_closure_settings: outgoing.simplified_report_closure_settings,
mobile_app_my_expenses_beta_enabled: outgoing.mobile_app_my_expenses_beta_enabled,
amex_feed_enrollment_settings: outgoing.amex_feed_enrollment_settings,
};
}
}
Loading

0 comments on commit ca1c375

Please sign in to comment.