Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Z3RO-O committed Oct 23, 2024
1 parent d2c5fe4 commit 43534fa
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 35 deletions.
18 changes: 18 additions & 0 deletions src/app/fyle/add-edit-expense/add-edit-expense-2.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,24 @@ export function TestCases2(getTestBed) {
done();
});
});

it('should update txn date with invoice_dt', (done) => {
const mockedTxn = cloneDeep(transformedExpenseWithExtractedData2);
const extractedDate = new Date('2023-01-24');

mockedTxn.tx.txn_dt = new Date('2023-01-23');
mockedTxn.tx.extracted_data.invoice_dt = new Date('2023-01-23');
mockedTxn.tx.extracted_data.date = extractedDate;
expensesService.getExpenseById.and.returnValue(of(platformExpenseWithExtractedData2));
transactionService.transformExpense.and.returnValue(mockedTxn);
dateService.getUTCDate.and.returnValue(mockedTxn.tx.extracted_data.invoice_dt);

component.getEditExpenseObservable().subscribe((res) => {
expect(res).toEqual(mockedTxn);
expect(mockedTxn.tx.txn_dt).toEqual(mockedTxn.tx.extracted_data.invoice_dt);
done();
});
});
});

it('goToPrev(): should go to the previous txn', () => {
Expand Down
63 changes: 28 additions & 35 deletions src/app/fyle/add-edit-expense/add-edit-expense-3.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ import { receiptInfoData2 } from 'src/app/core/mock-data/receipt-info.data';
import { ExpensesService } from 'src/app/core/services/platform/v1/spender/expenses.service';
import { AdvanceWalletsService } from 'src/app/core/services/platform/v1/spender/advance-wallets.service';
import { platformExpenseWithExtractedData } from 'src/app/core/mock-data/platform/v1/expense.data';
import { RefinerService } from 'src/app/core/services/refiner.service';

export function TestCases3(getTestBed) {
return describe('AddEditExpensePage-3', () => {
Expand Down Expand Up @@ -165,7 +164,6 @@ export function TestCases3(getTestBed) {
let launchDarklyService: jasmine.SpyObj<LaunchDarklyService>;
let expensesService: jasmine.SpyObj<ExpensesService>;
let advanceWalletsService: jasmine.SpyObj<AdvanceWalletsService>;
let refinerService: jasmine.SpyObj<RefinerService>;

beforeEach(() => {
const TestBed = getTestBed();
Expand Down Expand Up @@ -223,7 +221,6 @@ export function TestCases3(getTestBed) {
storageService = TestBed.inject(StorageService) as jasmine.SpyObj<StorageService>;
launchDarklyService = TestBed.inject(LaunchDarklyService) as jasmine.SpyObj<LaunchDarklyService>;
expensesService = TestBed.inject(ExpensesService) as jasmine.SpyObj<ExpensesService>;
refinerService = TestBed.inject(RefinerService) as jasmine.SpyObj<RefinerService>;

component.fg = formBuilder.group({
currencyObj: [, component.currencyObjValidator],
Expand Down Expand Up @@ -914,38 +911,6 @@ export function TestCases3(getTestBed) {
});
});

describe('triggerNpsSurvey', () => {
it('should start survey if nps_survey feature flag is enabled and user is not an ADMIN', () => {
const roles = ['USER'];
authService.getRoles.and.returnValue(of(roles));
launchDarklyService.getVariation.and.returnValue(of(true));

component.triggerNpsSurvey();

expect(refinerService.startSurvey).toHaveBeenCalledWith({ actionName: 'Save Expense' });
});

it('should not start survey if nps_survey feature flag is disabled', () => {
const roles = ['USER'];
authService.getRoles.and.returnValue(of(roles));
launchDarklyService.getVariation.and.returnValue(of(false));

component.triggerNpsSurvey();

expect(refinerService.startSurvey).not.toHaveBeenCalled();
});

it('should not start survey if user is an ADMIN', () => {
const roles = ['ADMIN'];
authService.getRoles.and.returnValue(of(roles));
launchDarklyService.getVariation.and.returnValue(of(true));

component.triggerNpsSurvey();

expect(refinerService.startSurvey).not.toHaveBeenCalled();
});
});

describe('getCategoryOnAdd():', () => {
it('should return category if provided as parameter', (done) => {
component.getCategoryOnAdd(orgCategoryData).subscribe((res) => {
Expand Down Expand Up @@ -1189,6 +1154,34 @@ export function TestCases3(getTestBed) {
},
});
});

it('should set default comment if user wants to continue with violations but does not provide a comment', (done) => {
loaderService.hideLoader.and.resolveTo();
loaderService.showLoader.and.resolveTo();
component.etxn$ = of(unflattenedTxnData2);
spyOn(component, 'continueWithPolicyViolations').and.resolveTo({ comment: '' });
spyOn(component, 'generateEtxnFromFg').and.returnValue(of(unflattenedExpData));

component
.policyViolationErrorHandler(
{
policyViolations: criticalPolicyViolation1,
policyAction: policyViolation1.data.final_desired_state,
},
of(customFieldData2)
)
.subscribe((result) => {
expect(loaderService.hideLoader).toHaveBeenCalledTimes(1);
expect(loaderService.showLoader).toHaveBeenCalledTimes(1);
expect(component.continueWithPolicyViolations).toHaveBeenCalledOnceWith(
criticalPolicyViolation1,
policyViolation1.data.final_desired_state
);
expect(component.generateEtxnFromFg).toHaveBeenCalledTimes(1);
expect(result.comment).toBe('No policy violation explanation provided');
done();
});
});
});

describe('viewAttachments():', () => {
Expand Down

0 comments on commit 43534fa

Please sign in to comment.