Skip to content

Commit

Permalink
fix failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
arjunaj5 committed Dec 8, 2024
1 parent 02fb34e commit ce96a7f
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 20 deletions.
1 change: 0 additions & 1 deletion src/app/core/services/transaction.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1107,7 +1107,6 @@ describe('TransactionService', () => {
expect(expensesService.createFromFile).toHaveBeenCalledOnceWith(mockFileObject[0].id, 'MOBILE_DASHCAM_BULK');
expect(transactionService.upsert).toHaveBeenCalledOnceWith({
...txnDataCleaned,
file_ids: [fileObjectData1[0].id],
id: expenseData.id,
});
done();
Expand Down
26 changes: 20 additions & 6 deletions src/app/fyle/add-edit-mileage/add-edit-mileage-3.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ export function TestCases3(getTestBed) {
spyOn(component, 'getCustomFields').and.returnValue(of(txnCustomPropertiesData4));
spyOn(component, 'getCalculatedDistance').and.returnValue(of('10'));
component.isConnected$ = of(true);
spyOn(component, 'generateEtxnFromFg').and.returnValue(of(unflattenedTxnData));
spyOn(component, 'generateEtxnFromFg').and.returnValue(of(cloneDeep(unflattenedTxnData)));
spyOn(component, 'checkPolicyViolation').and.returnValue(of(expensePolicyDataWoData));
policyService.getCriticalPolicyRules.and.returnValue([]);
policyService.getPolicyRules.and.returnValue([]);
Expand All @@ -256,11 +256,18 @@ export function TestCases3(getTestBed) {
spyOn(component, 'getFormValues').and.returnValue({
report: expectedReportsPaginated[0],
});
const expectedEtxnData = {
...unflattenedTxnData,
tx: {
...unflattenedTxnData.tx,
report_id: expectedReportsPaginated[0].id,
},
};
transactionOutboxService.addEntryAndSync.and.resolveTo(outboxQueueData1[0]);
fixture.detectChanges();

component.addExpense('SAVE_MILEAGE').subscribe((res) => {
expect(res).toEqual(unflattenedTxnData);
expect(res).toEqual(expectedEtxnData);
expect(component.getCustomFields).toHaveBeenCalledTimes(1);
expect(component.getCalculatedDistance).toHaveBeenCalledTimes(1);
expect(component.generateEtxnFromFg).toHaveBeenCalledOnceWith(
Expand All @@ -274,7 +281,7 @@ export function TestCases3(getTestBed) {
expect(component.trackCreateExpense).toHaveBeenCalledTimes(1);
expect(component.getFormValues).toHaveBeenCalledTimes(1);
expect(transactionOutboxService.addEntryAndSync).toHaveBeenCalledOnceWith(
unflattenedTxnData.tx,
expectedEtxnData.tx,
unflattenedTxnData.dataUrls as any,
[]
);
Expand Down Expand Up @@ -429,18 +436,25 @@ export function TestCases3(getTestBed) {
component.isConnected$ = of(false);
spyOn(component, 'getCustomFields').and.returnValue(of(txnCustomPropertiesData4));
spyOn(component, 'getCalculatedDistance').and.returnValue(of('10'));
spyOn(component, 'generateEtxnFromFg').and.returnValue(of(unflattenedTxnData));
spyOn(component, 'generateEtxnFromFg').and.returnValue(of(cloneDeep(unflattenedTxnData)));
spyOn(component, 'checkPolicyViolation').and.returnValue(of(expensePolicyDataWoData));
spyOn(component, 'trackCreateExpense');
authService.getEou.and.resolveTo(apiEouRes);
spyOn(component, 'getFormValues').and.returnValue({
report: expectedReportsPaginated[0],
});
const expectedEtxnData = {
...unflattenedTxnData,
tx: {
...unflattenedTxnData.tx,
report_id: expectedReportsPaginated[0].id,
},
};
transactionOutboxService.addEntryAndSync.and.resolveTo(outboxQueueData1[0]);
fixture.detectChanges();

component.addExpense('SAVE_MILEAGE').subscribe((res) => {
expect(res).toEqual(unflattenedTxnData);
expect(res).toEqual(expectedEtxnData);
expect(component.getCustomFields).toHaveBeenCalledTimes(1);
expect(component.getCalculatedDistance).toHaveBeenCalledTimes(1);
expect(component.generateEtxnFromFg).toHaveBeenCalledOnceWith(
Expand All @@ -452,7 +466,7 @@ export function TestCases3(getTestBed) {
expect(component.trackCreateExpense).toHaveBeenCalledTimes(1);
expect(component.getFormValues).toHaveBeenCalledTimes(1);
expect(transactionOutboxService.addEntryAndSync).toHaveBeenCalledOnceWith(
unflattenedTxnData.tx,
expectedEtxnData.tx,
unflattenedTxnData.dataUrls as any,
[]
);
Expand Down
40 changes: 29 additions & 11 deletions src/app/fyle/add-edit-per-diem/add-edit-per-diem-3.page.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ import { expectedReportsPaginated } from 'src/app/core/mock-data/platform-report
import { PerDiemRedirectedFrom } from 'src/app/core/models/per-diem-redirected-from.enum';

export function TestCases3(getTestBed) {
return describe('add-edit-per-diem test cases set 3', () => {
return fdescribe('add-edit-per-diem test cases set 3', () => {
let component: AddEditPerDiemPage;
let fixture: ComponentFixture<AddEditPerDiemPage>;
let activatedRoute: jasmine.SpyObj<ActivatedRoute>;
Expand Down Expand Up @@ -613,18 +613,27 @@ export function TestCases3(getTestBed) {
});

describe('addExpense():', () => {
const etxn$ = of({ tx: unflattenedTxnData.tx, ou: unflattenedTxnData.ou, dataUrls: [] });
const customFields$ = of(txnCustomProperties4);
const expectedEtxnDataWithReportId = {
...unflattenedTxnData,
tx: {
...unflattenedTxnData.tx,
report_id: expectedReportsPaginated[0].id,
},
};
beforeEach(() => {
const etxn$ = of({ tx: cloneDeep(unflattenedTxnData.tx), ou: unflattenedTxnData.ou, dataUrls: [] });
spyOn(component, 'generateEtxnFromFg').and.returnValue(etxn$);
spyOn(component, 'getCustomFields').and.returnValue(customFields$);
component.isConnected$ = of(true);
spyOn(component, 'checkPolicyViolation').and.returnValue(of(expensePolicyData));
policyService.getCriticalPolicyRules.and.returnValue(['The expense will be flagged']);
policyService.getPolicyRules.and.returnValue(['The expense will be flagged']);
spyOn(component, 'criticalPolicyViolationErrorHandler').and.returnValue(of({ etxn: unflattenedTxnData }));
spyOn(component, 'criticalPolicyViolationErrorHandler').and.returnValue(
of({ etxn: cloneDeep(unflattenedTxnData) })
);
spyOn(component, 'policyViolationErrorHandler').and.returnValue(
of({ etxn: unflattenedTxnData, comment: 'comment' })
of({ etxn: cloneDeep(unflattenedTxnData), comment: 'comment' })
);
authService.getEou.and.resolveTo(apiEouRes);
spyOn(component, 'getFormValues').and.returnValue({
Expand Down Expand Up @@ -670,7 +679,7 @@ export function TestCases3(getTestBed) {
expect(authService.getEou).toHaveBeenCalledTimes(1);
expect(trackingService.createExpense).toHaveBeenCalledOnceWith(createExpenseProperties3);
expect(transactionOutboxService.addEntryAndSync).toHaveBeenCalledOnceWith(
unflattenedTxnData.tx,
expectedEtxnDataWithReportId.tx,
undefined,
[]
);
Expand Down Expand Up @@ -712,7 +721,7 @@ export function TestCases3(getTestBed) {
expect(authService.getEou).toHaveBeenCalledTimes(1);
expect(trackingService.createExpense).toHaveBeenCalledOnceWith(createExpenseProperties3);
expect(transactionOutboxService.addEntryAndSync).toHaveBeenCalledOnceWith(
unflattenedTxnData.tx,
expectedEtxnDataWithReportId.tx,
undefined,
['comment']
);
Expand Down Expand Up @@ -757,7 +766,7 @@ export function TestCases3(getTestBed) {
expect(authService.getEou).toHaveBeenCalledTimes(1);
expect(trackingService.createExpense).toHaveBeenCalledOnceWith(createExpenseProperties3);
expect(transactionOutboxService.addEntryAndSync).toHaveBeenCalledOnceWith(
unflattenedTxnData.tx,
expectedEtxnDataWithReportId.tx,
undefined,
['comment']
);
Expand Down Expand Up @@ -800,7 +809,7 @@ export function TestCases3(getTestBed) {
expect(authService.getEou).toHaveBeenCalledTimes(1);
expect(trackingService.createExpense).toHaveBeenCalledOnceWith(createExpenseProperties3);
expect(transactionOutboxService.addEntryAndSync).toHaveBeenCalledOnceWith(
unflattenedTxnData.tx,
expectedEtxnDataWithReportId.tx,
undefined,
['comment']
);
Expand Down Expand Up @@ -839,7 +848,7 @@ export function TestCases3(getTestBed) {
expect(authService.getEou).toHaveBeenCalledTimes(1);
expect(trackingService.createExpense).toHaveBeenCalledOnceWith(createExpenseProperties3);
expect(transactionOutboxService.addEntryAndSync).toHaveBeenCalledOnceWith(
unflattenedTxnData.tx,
expectedEtxnDataWithReportId.tx,
undefined,
['comment']
);
Expand Down Expand Up @@ -882,7 +891,11 @@ export function TestCases3(getTestBed) {
expect(authService.getEou).toHaveBeenCalledTimes(1);

expect(trackingService.createExpense).toHaveBeenCalledOnceWith(createExpenseProperties3);
expect(transactionOutboxService.addEntryAndSync).toHaveBeenCalledOnceWith(unflattenedTxnData.tx, [], []);
expect(transactionOutboxService.addEntryAndSync).toHaveBeenCalledOnceWith(
expectedEtxnDataWithReportId.tx,
[],
[]
);
expect(res).toEqual(outboxQueueData1[0]);
done();
});
Expand Down Expand Up @@ -912,7 +925,11 @@ export function TestCases3(getTestBed) {
expect(authService.getEou).toHaveBeenCalledTimes(1);

expect(trackingService.createExpense).toHaveBeenCalledOnceWith(createExpenseProperties3);
expect(transactionOutboxService.addEntryAndSync).toHaveBeenCalledOnceWith(unflattenedTxnData.tx, [], []);
expect(transactionOutboxService.addEntryAndSync).toHaveBeenCalledOnceWith(
expectedEtxnDataWithReportId.tx,
[],
[]
);
expect(res).toEqual(outboxQueueData1[0]);
done();
});
Expand All @@ -923,6 +940,7 @@ export function TestCases3(getTestBed) {
policyService.getPolicyRules.and.returnValue([]);
const mockTxnData = cloneDeep(unflattenedTxnData);
mockTxnData.tx.policy_amount = 0.1;
mockTxnData.tx.report_id = expectedReportsPaginated[0].id;
component.generateEtxnFromFg = jasmine
.createSpy()
.and.returnValue(of({ tx: mockTxnData.tx, ou: unflattenedTxnData.ou, dataUrls: [] }));
Expand Down
5 changes: 3 additions & 2 deletions src/app/fyle/add-edit-per-diem/add-edit-per-diem.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1971,15 +1971,16 @@ export class AddEditPerDiemPage implements OnInit {
}

const formValue = this.getFormValues();
const transaction = cloneDeep(etxn.tx);
if (
formValue.report &&
(etxn.tx.policy_amount === null || (etxn.tx.policy_amount && !(etxn.tx.policy_amount < 0.0001)))
) {
etxn.tx.report_id = formValue.report.id;
transaction.report_id = formValue.report.id;
}
return of(
this.transactionsOutboxService.addEntryAndSync(
etxn.tx,
transaction,
etxn.dataUrls as { url: string; type: string }[],
comments
)
Expand Down

0 comments on commit ce96a7f

Please sign in to comment.