From 87e1ffdb951827981ba06739839c2ec50c6431ab Mon Sep 17 00:00:00 2001 From: ronenk1 Date: Mon, 5 Jun 2023 18:40:14 +0300 Subject: [PATCH] chore: integration #1 --- src/common/interfaces.ts | 6 +++++ src/tasks/models/tasksManager.ts | 3 +++ tests/mocks/data.ts | 4 +++ .../createPackage/models/tasksModel.spec.ts | 26 +++++++++++++------ tests/unit/finalizationManager.spec.ts | 3 +++ 5 files changed, 34 insertions(+), 8 deletions(-) diff --git a/src/common/interfaces.ts b/src/common/interfaces.ts index 5d1cc35..d6802b1 100644 --- a/src/common/interfaces.ts +++ b/src/common/interfaces.ts @@ -154,8 +154,14 @@ export interface ILinkDefinition { metadataURI: string; } +export interface IFileNameDefinition { + dataName: string; + metadataName: string; +} + export interface ICallbackExportResponse extends ICallbackExportData { status: OperationStatus.IN_PROGRESS | OperationStatus.COMPLETED | OperationStatus.FAILED; + fileNames: IFileNameDefinition; } /** diff --git a/src/tasks/models/tasksManager.ts b/src/tasks/models/tasksManager.ts index d517041..90f3561 100644 --- a/src/tasks/models/tasksManager.ts +++ b/src/tasks/models/tasksManager.ts @@ -235,6 +235,7 @@ export class TasksManager { roi: job.parameters.roi, status: finalizeStatus, errorReason: reason, + fileNames: {dataName: job.parameters.fileNamesTemplates.dataURI, metadataName:job.parameters.fileNamesTemplates.metadataURI} }; await this.sendExportCallbacks(job, callbackParams); @@ -265,6 +266,7 @@ export class TasksManager { roi: job.parameters.roi, status: OperationStatus.FAILED, errorReason: reason, + fileNames: {dataName: job.parameters.fileNamesTemplates.dataURI, metadataName:job.parameters.fileNamesTemplates.metadataURI} }; await this.sendExportCallbacks(job, callbackParams); @@ -308,6 +310,7 @@ export class TasksManager { return cleanupData; } + // todo - refactor after first integration with mutual export - to suite the real webhook interface private async generateCallbackParam( job: JobExportResponse | JobFinalizeResponse, expirationDate: Date, diff --git a/tests/mocks/data.ts b/tests/mocks/data.ts index 09c0f20..648f40d 100644 --- a/tests/mocks/data.ts +++ b/tests/mocks/data.ts @@ -757,6 +757,10 @@ const completedExportJob: IJobResponse = jobId: 'afbdd5e6-25db-4567-a81f-71e0e7d30761', expirationTime: new Date(), recordCatalogId: 'b0b19b88-aecb-4e74-b694-dfa7eada8bf7', + fileNames: { + dataName: 'Orthophoto_testArea_1_0_2023_02_28T15_09_50_924Z.gpkg', + metadataName: 'Orthophoto_testArea_1_0_2023_02_28T15_09_50_924Z.json', + } }, cleanupData: { directoryPath: 'b0b19b88-aecb-4e74-b694-dfa7eada8bf7', diff --git a/tests/unit/createPackage/models/tasksModel.spec.ts b/tests/unit/createPackage/models/tasksModel.spec.ts index 8cb9eee..95b3423 100644 --- a/tests/unit/createPackage/models/tasksModel.spec.ts +++ b/tests/unit/createPackage/models/tasksModel.spec.ts @@ -7,6 +7,7 @@ import { CreateFinalizeTaskBody, ICallbackDataBase, ICallbackDataExportBase, + ICallbackExportResponse, ICallbackTargetExport, ITaskParameters, JobExportResponse, @@ -483,7 +484,7 @@ describe('TasksManager', () => { createExportJsonMetadataMock.mockResolvedValue(true); sendCallbacksSpy = jest.spyOn(tasksManager, 'sendExportCallbacks'); - const expectedCallbackParamData: ICallbackDataExportBase = { + const expectedCallbackParamData: ICallbackExportResponse = { expirationTime, fileSize: 2000, links: { @@ -494,6 +495,9 @@ describe('TasksManager', () => { jobId: mockCompletedJob.id, errorReason: undefined, description: 'test job', + roi: mockCompletedJob.parameters.roi, + status: OperationStatus.COMPLETED, + fileNames: {dataName: mockCompletedJob.parameters.fileNamesTemplates.dataURI, metadataName:mockCompletedJob.parameters.fileNamesTemplates.metadataURI} }; const expectedUpdateRequest = { @@ -502,14 +506,14 @@ describe('TasksManager', () => { status: OperationStatus.COMPLETED, parameters: { ...mockCompletedJob.parameters, - callbackParams: { ...expectedCallbackParamData, roi: mockCompletedJob.parameters.roi, status: OperationStatus.COMPLETED }, + callbackParams: expectedCallbackParamData, cleanupData: { directoryPath: mockCompletedJob.parameters.relativeDirectoryPath, cleanupExpirationTimeUTC: expirationTime }, }, }; const results = await tasksManager.finalizeGPKGSuccess(mockCompletedJob, expirationTime); expect(createExportJsonMetadataMock).toHaveBeenCalledTimes(1); // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access - const createdCallbackParam: ICallbackDataExportBase = sendCallbacksSpy.mock.calls[0][1] as ICallbackDataExportBase; + const createdCallbackParam: ICallbackExportResponse = sendCallbacksSpy.mock.calls[0][1] as ICallbackExportResponse; expect(sendCallbacksSpy).toHaveBeenCalledTimes(1); expect(createdCallbackParam).toStrictEqual(expectedCallbackParamData); expect(results).toStrictEqual(expectedUpdateRequest); @@ -522,7 +526,7 @@ describe('TasksManager', () => { createExportJsonMetadataMock.mockResolvedValue(false); sendCallbacksSpy = jest.spyOn(tasksManager, 'sendExportCallbacks'); - const expectedCallbackParamData: ICallbackDataExportBase = { + const expectedCallbackParamData: ICallbackExportResponse = { expirationTime, fileSize: 0, links: { @@ -533,6 +537,9 @@ describe('TasksManager', () => { jobId: mockCompletedJob.id, errorReason: 'Failed on metadata.json creation', description: 'test job', + roi: mockCompletedJob.parameters.roi, + status: OperationStatus.FAILED, + fileNames: {dataName: mockCompletedJob.parameters.fileNamesTemplates.dataURI, metadataName:mockCompletedJob.parameters.fileNamesTemplates.metadataURI} }; const expectedUpdateRequest = { @@ -548,7 +555,7 @@ describe('TasksManager', () => { const results = await tasksManager.finalizeGPKGSuccess(mockCompletedJob, expirationTime); expect(createExportJsonMetadataMock).toHaveBeenCalledTimes(1); // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access - const createdCallbackParam: ICallbackDataExportBase = sendCallbacksSpy.mock.calls[0][1] as ICallbackDataExportBase; + const createdCallbackParam: ICallbackExportResponse = sendCallbacksSpy.mock.calls[0][1] as ICallbackExportResponse; expect(sendCallbacksSpy).toHaveBeenCalledTimes(1); expect(createdCallbackParam).toStrictEqual(expectedCallbackParamData); expect(results).toStrictEqual(expectedUpdateRequest); @@ -565,7 +572,7 @@ describe('TasksManager', () => { const expirationTime = new Date(); sendCallbacksSpy = jest.spyOn(tasksManager, 'sendExportCallbacks'); - const expectedCallbackParamData: ICallbackDataExportBase = { + const expectedCallbackParamData: ICallbackExportResponse = { expirationTime, fileSize: 0, links: { @@ -576,6 +583,9 @@ describe('TasksManager', () => { jobId: mockCompletedJob.id, errorReason: exportingErrorMsg, description: 'test job', + roi: mockCompletedJob.parameters.roi, + status: OperationStatus.FAILED, + fileNames: {dataName: mockCompletedJob.parameters.fileNamesTemplates.dataURI, metadataName:mockCompletedJob.parameters.fileNamesTemplates.metadataURI} }; const expectedUpdateRequest = { @@ -584,13 +594,13 @@ describe('TasksManager', () => { status: OperationStatus.FAILED, parameters: { ...mockCompletedJob.parameters, - callbackParams: { ...expectedCallbackParamData, roi: mockCompletedJob.parameters.roi, status: OperationStatus.FAILED }, + callbackParams: expectedCallbackParamData, cleanupData: { directoryPath: mockCompletedJob.parameters.relativeDirectoryPath, cleanupExpirationTimeUTC: expirationTime }, }, }; const results = await tasksManager.finalizeGPKGFailure(mockCompletedJob, expirationTime, exportingErrorMsg); // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access - const createdCallbackParam: ICallbackDataExportBase = sendCallbacksSpy.mock.calls[0][1] as ICallbackDataExportBase; + const createdCallbackParam: ICallbackExportResponse = sendCallbacksSpy.mock.calls[0][1] as ICallbackExportResponse; expect(sendCallbacksSpy).toHaveBeenCalledTimes(1); expect(createdCallbackParam).toStrictEqual(expectedCallbackParamData); expect(results).toStrictEqual(expectedUpdateRequest); diff --git a/tests/unit/finalizationManager.spec.ts b/tests/unit/finalizationManager.spec.ts index ad42e05..1f47a66 100644 --- a/tests/unit/finalizationManager.spec.ts +++ b/tests/unit/finalizationManager.spec.ts @@ -118,6 +118,7 @@ describe('FinalizationManager', () => { recordCatalogId: completedExportJob.internalId as string, fileSize: 1000, jobId: completedExportJob.id, + fileNames: { metadataName: 'test', dataName: 'test' }, }, }, }; @@ -169,6 +170,7 @@ describe('FinalizationManager', () => { fileSize: 0, errorReason: 'Failed on GPKG creation', jobId: completedExportJob.id, + fileNames: { metadataName: 'testTemplate', dataName: 'testTemplate' } }, }, }; @@ -278,6 +280,7 @@ describe('FinalizationManager', () => { recordCatalogId: completedExportJob.internalId as string, fileSize: 1000, jobId: completedExportJob.id, + fileNames: { metadataName: 'test', dataName: 'test' } }, }, };