Skip to content

Commit

Permalink
test: Add tests for Virtual Cards changes (#2741)
Browse files Browse the repository at this point in the history
  • Loading branch information
bistaastha authored Feb 21, 2024
1 parent c6a0c87 commit dc12842
Show file tree
Hide file tree
Showing 23 changed files with 448 additions and 44 deletions.
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,
},
};
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,
};
4 changes: 2 additions & 2 deletions src/app/core/models/org-settings.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +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;
amex_feed_enrollment_settings?: AmexFeedEnrollmentSettings;
}

export interface UiPolicySettings {
Expand Down Expand Up @@ -560,5 +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;
amex_feed_enrollment_settings?: AmexFeedEnrollmentSettings;
}
10 changes: 5 additions & 5 deletions src/app/core/models/virtual-card.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ export interface VirtualCard {
id: string;
state: CardStatus;
last_five: string;
expiry_date: Date;
created_at: Date;
updated_at: Date;
expiry_date: string;
created_at: string;
updated_at: string;
org_id: string;
amex_account_id: string;
valid_from_at: Date;
valid_till_at: Date;
valid_from_at: string;
valid_till_at: string;
user_id: string;
creator_user_id: string;
nick_name: string;
Expand Down
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();
});
});
});
6 changes: 3 additions & 3 deletions src/app/core/services/org-settings.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -557,9 +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,
amex_feed_enrollment_settings: outgoing?.amex_feed_enrollment_settings,
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,
};
}
}
79 changes: 78 additions & 1 deletion src/app/core/services/virtual-cards.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@ import {
import { of } from 'rxjs';
import { VirtualCardsRequest } from '../models/virtual-cards-request.model';
import { CardDetailsResponse } from '../models/card-details-response.model';
import { virtualCardResponse, virtualCardUndefinedResponse } from '../mock-data/virtual-card-response.data';
import { VirtualCardsCombinedRequest } from '../models/virtual-cards-combined-request.model';
import { cardDetailsRes } from '../mock-data/platform-corporate-card-detail.data';
import { virtualCardCombinedRequest } from '../mock-data/virtual-cards-combined-request.data';

describe('VirtualCardsService', () => {
let virtualCardsService: VirtualCardsService;
let spenderPlatformV1ApiService: jasmine.SpyObj<SpenderPlatformV1ApiService>;

beforeEach(() => {
const spenderPlatformV1ApiServiceSpy = jasmine.createSpyObj('SpenderPlatformV1ApiService', ['post']);
const spenderPlatformV1ApiServiceSpy = jasmine.createSpyObj('SpenderPlatformV1ApiService', ['post', 'get']);
TestBed.configureTestingModule({
providers: [
VirtualCardsService,
Expand Down Expand Up @@ -72,4 +76,77 @@ describe('VirtualCardsService', () => {
done();
});
});

describe('getVirtualCardById(): ', () => {
it('should get virtual card', (done) => {
const virtualCardsRequest: VirtualCardsRequest = {
id: 'vc1234',
};
const data = {
params: {
id: 'eq.' + virtualCardsRequest.id,
},
};
spenderPlatformV1ApiService.get.and.returnValue(of(virtualCardResponse));

virtualCardsService.getVirtualCard(virtualCardsRequest).subscribe((res) => {
expect(res).toEqual(virtualCardResponse.data[0]);
expect(spenderPlatformV1ApiService.get).toHaveBeenCalledOnceWith('/virtual_cards', data);
done();
});
});

it('should return undefined response in case of undefined data', (done) => {
const virtualCardsRequest: VirtualCardsRequest = {
id: 'vc1234',
};
const data = {
params: {
id: 'eq.' + virtualCardsRequest.id,
},
};
spenderPlatformV1ApiService.get.and.returnValue(of(virtualCardUndefinedResponse));

virtualCardsService.getVirtualCard(virtualCardsRequest).subscribe((res) => {
expect(res).toEqual(undefined);
done();
});
});
});

it('getCardDetailsMap(): should return serialised card details', () => {
const expectedCardDetailsResponse = {
cardDetails: virtualCardDetailsResponse.data,
currentAmount: virtualCardCurrentAmountResponse.data,
virtualCard: virtualCardResponse.data[0],
};

const expectedResponse = {
vcgNQmrZvGhL: {
...expectedCardDetailsResponse.cardDetails,
...expectedCardDetailsResponse.currentAmount,
nick_name: expectedCardDetailsResponse.virtualCard.nick_name,
},
};

spyOn(virtualCardsService, 'getCombinedCardDetails').and.returnValue(of(expectedCardDetailsResponse));
virtualCardsService.getCardDetailsMap(virtualCardCombinedRequest).subscribe((res) => {
expect(res).toEqual(expectedResponse);
});
});

it('getCombinedCardDetails(): should return expected response for Card Details related API calls', () => {
spyOn(virtualCardsService, 'getCardDetails').and.returnValue(of(virtualCardDetailsResponse.data));
spyOn(virtualCardsService, 'getCurrentAmount').and.returnValue(of(virtualCardCurrentAmountResponse.data));
spyOn(virtualCardsService, 'getVirtualCard').and.returnValue(of(virtualCardResponse.data[0]));

const expectedResponse = {
cardDetails: virtualCardDetailsResponse.data,
currentAmount: virtualCardCurrentAmountResponse.data,
virtualCard: virtualCardResponse.data[0],
};
virtualCardsService.getCombinedCardDetails('vcgNQmrZvGhL', true).subscribe((res) => {
expect(res).toEqual(expectedResponse);
});
});
});
14 changes: 14 additions & 0 deletions src/app/core/test-data/org-settings.service.spec.data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -876,6 +876,20 @@ export const orgSettingsPostData: OrgSettingsResponse = {
},
};

export const orgSettingsAmexFeedDataRequest: OrgSettingsResponse = {
...orgSettingsPostData,
amex_feed_enrollment_settings: null,
};

export const orgSettingsAmexFeedDataResponse: OrgSettingsResponse = {
...orgSettingsGetData,
amex_feed_enrollment_settings: {
allowed: undefined,
enabled: undefined,
virtual_card_settings_enabled: undefined,
},
};

export const outgoingTallyAccountObj: AccountingExportSettings = {
allowed: undefined,
tally_settings: {
Expand Down
21 changes: 10 additions & 11 deletions src/app/fyle/dashboard/card-stats/card-stats.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,16 @@
(addCardClick)="openAddCorporateCardPopover()"
></app-spent-cards>
</ng-container>
</ng-container>

<ng-container *ngIf="isVirtualCardsEnabled.enabled === true">
<ng-container *ngIf="virtualCardDetails$ | async as cardDetails">
<app-spent-cards
[cardDetails]="cardDetails"
[homeCurrency]="homeCurrency$ | async"
[currencySymbol]="currencySymbol$ | async"
[showAddCardSlide]="canAddCorporateCards$ | async"
(addCardClick)="openAddCorporateCardPopover()"
></app-spent-cards>
<ng-container *ngIf="isVirtualCardsEnabled.enabled">
<ng-container *ngIf="virtualCardDetails$ | async as cardDetails">
<app-spent-cards
[cardDetails]="cardDetails"
[homeCurrency]="homeCurrency$ | async"
[currencySymbol]="currencySymbol$ | async"
[showAddCardSlide]="canAddCorporateCards$ | async"
(addCardClick)="openAddCorporateCardPopover()"
></app-spent-cards>
</ng-container>
</ng-container>
</ng-container>

Expand Down
Loading

0 comments on commit dc12842

Please sign in to comment.