Skip to content

Commit b017ded

Browse files
fix(sync): adiciona fallback para body undefined ou null
Ajusta método createPoHttpRequestData para definir body como objeto vazio caso record seja null/undefined. Fixes: DTHFUI-11347
1 parent 05f84b1 commit b017ded

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

projects/sync/src/lib/services/po-event-sourcing/po-event-sourcing.service.spec.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -821,6 +821,26 @@ describe('PoEventSourcingService:', () => {
821821
expect(result).toEqual(expectedValue);
822822
});
823823

824+
it('createPoHttpRequestData: should return body as empty object when record is undefined', async () => {
825+
const url = 'http://url.com/customers';
826+
const method = PoHttpRequestType.POST;
827+
const headers = [{ name: 'test', value: 'teste1' }];
828+
829+
const poHttpRequestData: PoHttpRequestData = {
830+
url,
831+
method,
832+
body: {},
833+
headers
834+
};
835+
836+
spyOn(eventSourcingService, <any>'createFormData');
837+
838+
const result = await eventSourcingService['createPoHttpRequestData'](url, method, undefined, headers);
839+
840+
expect(result).toEqual(poHttpRequestData);
841+
expect(eventSourcingService['createFormData']).not.toHaveBeenCalled();
842+
});
843+
824844
it('createFormData: should return a FormData', async () => {
825845
const file = new File([''], 'filename', { type: 'text/html' });
826846
const body = 'Data: ';

projects/sync/src/lib/services/po-event-sourcing/po-event-sourcing.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -463,9 +463,9 @@ export class PoEventSourcingService {
463463
record?: PoEventSourcingItem['record'],
464464
headers?: Array<PoHttpHeaderOption>
465465
): Promise<PoHttpRequestData> {
466-
let body = record.body ?? record;
466+
let body = record?.body ?? record ?? {};
467467

468-
if (record.bodyType === 'File') {
468+
if (record?.bodyType === 'File') {
469469
body = await this.createFormData(body, record.fileName, record.mimeType, record.formField);
470470
}
471471

0 commit comments

Comments
 (0)