-
Notifications
You must be signed in to change notification settings - Fork 15
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
fix: Allow save expense with invalid fields after capture receipt #3308
Changes from 5 commits
253d674
ca1b84b
467025e
4809082
436e0ef
469dea5
02fb34e
ce96a7f
4cf8b8f
8ee656f
32abf93
71c5167
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -141,14 +141,12 @@ export class TransactionsOutboxService { | |
addEntry( | ||
transaction: Partial<Transaction>, | ||
dataUrls: { url: string; type: string }[], | ||
comments?: string[], | ||
reportId?: string | ||
comments?: string[] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Mind this! Method signature updated but calls may be outdated. You've removed the |
||
): Promise<void> { | ||
this.queue.push({ | ||
transaction, | ||
dataUrls, | ||
comments, | ||
reportId, | ||
}); | ||
|
||
return this.saveQueue(); | ||
|
@@ -159,10 +157,9 @@ export class TransactionsOutboxService { | |
addEntryAndSync( | ||
transaction: Partial<Transaction>, | ||
dataUrls: { url: string; type: string }[], | ||
comments: string[], | ||
reportId: string | ||
comments: string[] | ||
): Promise<OutboxQueue> { | ||
this.addEntry(transaction, dataUrls, comments, reportId); | ||
this.addEntry(transaction, dataUrls, comments); | ||
return this.syncEntry(this.queue.pop()); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4275,7 +4275,6 @@ export class AddEditExpensePage implements OnInit { | |
const customFields$ = this.getCustomFields(); | ||
|
||
this.trackAddExpense(); | ||
|
||
return this.generateEtxnFromFg(this.etxn$, customFields$).pipe( | ||
switchMap((etxn) => | ||
this.isConnected$.pipe( | ||
|
@@ -4361,13 +4360,12 @@ export class AddEditExpensePage implements OnInit { | |
etxn.tx.matchCCCId = this.selectedCCCTransaction.id; | ||
} | ||
|
||
let reportId: string; | ||
const formValues = this.getFormValues(); | ||
if ( | ||
formValues.report && | ||
(etxn.tx.policy_amount === null || (etxn.tx.policy_amount && !(etxn.tx.policy_amount < 0.0001))) | ||
) { | ||
reportId = formValues.report.id; | ||
etxn.tx.report_id = formValues.report.id; | ||
} | ||
|
||
etxn.dataUrls = etxn.dataUrls.map((data: FileObject) => { | ||
|
@@ -4387,8 +4385,7 @@ export class AddEditExpensePage implements OnInit { | |
this.transactionOutboxService.addEntryAndSync( | ||
etxn.tx, | ||
etxn.dataUrls as { url: string; type: string }[], | ||
comments, | ||
reportId | ||
comments | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Watch out! Incorrect parameter passed to The method Here's a suggested change: - this.transactionOutboxService.addEntryAndSync(
- etxn.tx,
- etxn.dataUrls as { url: string; type: string }[],
- comments
- );
+ this.transactionOutboxService.addEntryAndSync(
+ etxn.tx,
+ etxn.dataUrls as { url: string; type: string }[],
+ comments
+ );
|
||
) | ||
); | ||
} else { | ||
|
@@ -4404,13 +4401,12 @@ export class AddEditExpensePage implements OnInit { | |
this.transactionOutboxService.addEntryAndSync( | ||
etxn.tx, | ||
etxn.dataUrls as { url: string; type: string }[], | ||
comments, | ||
reportId | ||
comments | ||
) | ||
); | ||
} else { | ||
this.transactionOutboxService | ||
.addEntry(etxn.tx, etxn.dataUrls as { url: string; type: string }[], comments, reportId) | ||
.addEntry(etxn.tx, etxn.dataUrls as { url: string; type: string }[], comments) | ||
.then(noop); | ||
|
||
return of(null); | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -1970,20 +1970,18 @@ export class AddEditPerDiemPage implements OnInit { | |||||||||||||||||||||||||||||||||||||||||||
comments.push(comment); | ||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
let reportId: string; | ||||||||||||||||||||||||||||||||||||||||||||
const formValue = this.getFormValues(); | ||||||||||||||||||||||||||||||||||||||||||||
if ( | ||||||||||||||||||||||||||||||||||||||||||||
formValue.report && | ||||||||||||||||||||||||||||||||||||||||||||
(etxn.tx.policy_amount === null || (etxn.tx.policy_amount && !(etxn.tx.policy_amount < 0.0001))) | ||||||||||||||||||||||||||||||||||||||||||||
) { | ||||||||||||||||||||||||||||||||||||||||||||
reportId = formValue.report.id; | ||||||||||||||||||||||||||||||||||||||||||||
etxn.tx.report_id = formValue.report.id; | ||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||
return of( | ||||||||||||||||||||||||||||||||||||||||||||
this.transactionsOutboxService.addEntryAndSync( | ||||||||||||||||||||||||||||||||||||||||||||
etxn.tx, | ||||||||||||||||||||||||||||||||||||||||||||
etxn.dataUrls as { url: string; type: string }[], | ||||||||||||||||||||||||||||||||||||||||||||
comments, | ||||||||||||||||||||||||||||||||||||||||||||
reportId | ||||||||||||||||||||||||||||||||||||||||||||
comments | ||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hey there! Let's make sure we're handling We're assigning Here's a suggestion: 1978,1980
- 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;
- }
+ if (
+ formValue.report &&
+ formValue.report.id &&
+ (etxn.tx.policy_amount === null || (etxn.tx.policy_amount && !(etxn.tx.policy_amount < 0.0001)))
+ ) {
+ etxn.tx.report_id = formValue.report.id;
+ } 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||||||
).pipe(switchMap((txnData) => from(txnData))); | ||||||||||||||||||||||||||||||||||||||||||||
}) | ||||||||||||||||||||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -127,7 +127,7 @@ export class CaptureReceiptComponent implements OnInit, OnDestroy, AfterViewInit | |
url: base64ImagesWithSource.base64Image, | ||
}, | ||
]; | ||
return this.transactionsOutboxService.addEntry(transaction, attachmentUrls, null, null); | ||
return this.transactionsOutboxService.addEntry(transaction, attachmentUrls, null); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wait a second! Missing argument in method call. In Here's how you might fix it: - return this.transactionsOutboxService.addEntry(transaction, attachmentUrls, null);
+ return this.transactionsOutboxService.addEntry(transaction, attachmentUrls);
|
||
}) | ||
); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧹 Nitpick (assertive)
Mind-blowing test case, but let's make it more robust!
The test case looks good, but in true Rajinikanth style, let's make it even more powerful! Consider adding assertions to verify that
expensesService.createFromFile
was called with the correct parameters.Add this assertion after the existing expect statements:
transactionService.createTxnWithFiles({ ...txnData }, of(mockFileObject)).subscribe((res) => { expect(res).toEqual(txnData2); expect(transactionService.upsert).toHaveBeenCalledOnceWith({ ...txnData, file_ids: [fileObjectData1[0].id] }); + expect(expensesService.createFromFile).toHaveBeenCalledOnceWith(mockFileObject[0].id, txnData.source); done(); });