Skip to content

Commit

Permalink
fix: for merge expenses attachments issue (#3009)
Browse files Browse the repository at this point in the history
  • Loading branch information
Chethan-Fyle authored May 21, 2024
1 parent c518ed6 commit 50c74e3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
10 changes: 10 additions & 0 deletions src/app/core/mock-data/file-object.data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -369,3 +369,13 @@ export const fileObject10: FileObject[] = deepFreeze([
thumbnail: 'src/assets/images/pdf-receipt-placeholder.png',
},
]);

export const fileObject11: FileObject[] = deepFreeze([
{
id: '1',
name: 'invoice.pdf',
type: 'pdf',
url: 'https://sampledownloadurl.com',
thumbnail: 'img/fy-pdf.svg',
},
]);
5 changes: 2 additions & 3 deletions src/app/core/services/merge-expenses.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ import {
optionsData8,
optionsData9,
} from '../mock-data/merge-expenses-options-data.data';
import { fileObject5 } from '../mock-data/file-object.data';
import { fileObject11, fileObject5 } from '../mock-data/file-object.data';
import { mergeExpenesesCustomInputsData } from '../mock-data/merge-expenses-custom-inputs.data';
import * as lodash from 'lodash';
import { projectsV1Data } from '../test-data/projects.spec.data';
Expand All @@ -100,7 +100,6 @@ import { cloneDeep } from 'lodash';
import { ExpensesService } from './platform/v1/spender/expenses.service';
import { SpenderFileService } from './platform/v1/spender/file.service';
import { platformExpenseData, platformExpenseWithExtractedData } from '../mock-data/platform/v1/expense.data';
import { receiptInfoData2 } from '../mock-data/receipt-info.data';
import { generateUrlsBulkData1 } from '../mock-data/generate-urls-bulk-response.data';

describe('MergeExpensesService', () => {
Expand Down Expand Up @@ -394,7 +393,7 @@ describe('MergeExpensesService', () => {

const transactionId = 'txz2vohKxBXu';
mergeExpensesService.getAttachements(transactionId).subscribe((res) => {
expect(res).toEqual(receiptInfoData2);
expect(res).toEqual(fileObject11);
expect(expensesService.getExpenseById).toHaveBeenCalledOnceWith(transactionId);
expect(spenderFileService.generateUrlsBulk).toHaveBeenCalledOnceWith(platformExpenseWithExtractedData.file_ids);
expect(fileService.getReceiptsDetails).toHaveBeenCalledOnceWith(
Expand Down
15 changes: 7 additions & 8 deletions src/app/core/services/merge-expenses.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import { DependentFieldsMapping } from '../models/dependent-field-mapping.model'
import { CustomInput } from '../models/custom-input.model';
import { ExpensesService } from './platform/v1/spender/expenses.service';
import { PlatformFileGenerateUrlsResponse } from '../models/platform/platform-file-generate-urls-response.model';
import { ReceiptInfo } from '../models/receipt-info.model';

type CardTransactionsConfig = {
queryParams: {
Expand Down Expand Up @@ -122,23 +121,23 @@ export class MergeExpensesService {
getAttachements(txnID: string): Observable<FileObject[]> {
return this.expensesService.getExpenseById(txnID).pipe(
switchMap((expense: PlatformExpense) =>
expense.file_ids.length > 0 ? this.spenderFileService.generateUrlsBulk(expense.file_ids) : of([])
expense?.file_ids.length > 0 ? this.spenderFileService.generateUrlsBulk(expense.file_ids) : of([])
),
map((response: PlatformFileGenerateUrlsResponse[]) => {
const files = response.filter((file) => file.content_type !== 'text/html');
const receiptObjs: ReceiptInfo[] = files.map((file) => {
const fileObjs: FileObject[] = response.map((file) => {
const details = this.fileService.getReceiptsDetails(file.name, file.download_url);

const receipt: ReceiptInfo = {
const fileObj: FileObject = {
id: file.id,
name: file.name,
url: file.download_url,
type: details.type,
thumbnail: details.thumbnail,
};

return receipt;
return fileObj;
});

return receiptObjs;
return fileObjs;
})
);
}
Expand Down

0 comments on commit 50c74e3

Please sign in to comment.