Skip to content

Commit

Permalink
chore: integration #1
Browse files Browse the repository at this point in the history
  • Loading branch information
ronenkapelian committed Jun 5, 2023
1 parent f0d91c8 commit 87e1ffd
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 8 deletions.
6 changes: 6 additions & 0 deletions src/common/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
3 changes: 3 additions & 0 deletions src/tasks/models/tasksManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions tests/mocks/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,10 @@ const completedExportJob: IJobResponse<IJobExportParameters, ITaskParameters> =
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',
Expand Down
26 changes: 18 additions & 8 deletions tests/unit/createPackage/models/tasksModel.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
CreateFinalizeTaskBody,
ICallbackDataBase,
ICallbackDataExportBase,
ICallbackExportResponse,
ICallbackTargetExport,
ITaskParameters,
JobExportResponse,
Expand Down Expand Up @@ -483,7 +484,7 @@ describe('TasksManager', () => {
createExportJsonMetadataMock.mockResolvedValue(true);
sendCallbacksSpy = jest.spyOn(tasksManager, 'sendExportCallbacks');

const expectedCallbackParamData: ICallbackDataExportBase = {
const expectedCallbackParamData: ICallbackExportResponse = {
expirationTime,
fileSize: 2000,
links: {
Expand All @@ -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 = {
Expand All @@ -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);
Expand All @@ -522,7 +526,7 @@ describe('TasksManager', () => {
createExportJsonMetadataMock.mockResolvedValue(false);
sendCallbacksSpy = jest.spyOn(tasksManager, 'sendExportCallbacks');

const expectedCallbackParamData: ICallbackDataExportBase = {
const expectedCallbackParamData: ICallbackExportResponse = {
expirationTime,
fileSize: 0,
links: {
Expand All @@ -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 = {
Expand All @@ -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);
Expand All @@ -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: {
Expand All @@ -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 = {
Expand All @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions tests/unit/finalizationManager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ describe('FinalizationManager', () => {
recordCatalogId: completedExportJob.internalId as string,
fileSize: 1000,
jobId: completedExportJob.id,
fileNames: { metadataName: 'test', dataName: 'test' },
},
},
};
Expand Down Expand Up @@ -169,6 +170,7 @@ describe('FinalizationManager', () => {
fileSize: 0,
errorReason: 'Failed on GPKG creation',
jobId: completedExportJob.id,
fileNames: { metadataName: 'testTemplate', dataName: 'testTemplate' }
},
},
};
Expand Down Expand Up @@ -278,6 +280,7 @@ describe('FinalizationManager', () => {
recordCatalogId: completedExportJob.internalId as string,
fileSize: 1000,
jobId: completedExportJob.id,
fileNames: { metadataName: 'test', dataName: 'test' }
},
},
};
Expand Down

0 comments on commit 87e1ffd

Please sign in to comment.