diff --git a/package-lock.json b/package-lock.json index 997ef94..6b1cf32 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1097,7 +1097,7 @@ }, "@map-colonies/mc-priority-queue": { "version": "file:map-colonies-mc-priority-queue-3.1.0.tgz", - "integrity": "sha512-wjEzZyWCTE70kfamJ8ZVoTI9M6+affTHM0xFcuniXuhDzxZBGlJ1SgogXM2m9JCAcn+QhhYlQaP07q/rh+LYyA==", + "integrity": "sha512-75ESOlv4zLtyYsnGV3a5g7/Ssa6EupdpOKxOPKZWDL7uEju9NLuZXLl/49aukFxqNRtb5jjswhTfyhPFNFf7dA==", "requires": { "@map-colonies/mc-utils": "^1.0.0" } diff --git a/package.json b/package.json index eeaec3b..de19f2e 100644 --- a/package.json +++ b/package.json @@ -45,10 +45,10 @@ "@map-colonies/express-access-log-middleware": "^0.0.3", "@map-colonies/js-logger": "^0.0.3", "@map-colonies/mc-model-types": "^9.2.0", + "@map-colonies/mc-priority-queue": "file:map-colonies-mc-priority-queue-3.1.0.tgz", "@map-colonies/mc-utils": "^1.1.2", "@map-colonies/openapi-express-viewer": "^2.0.1", "@map-colonies/read-pkg": "0.0.1", - "@map-colonies/mc-priority-queue": "./map-colonies-mc-priority-queue-3.1.0.tgz", "@map-colonies/telemetry": "3.1.0", "@opentelemetry/api": "1.0.3", "@opentelemetry/api-metrics": "0.24.0", diff --git a/src/index.ts b/src/index.ts index 238eba8..f164947 100644 --- a/src/index.ts +++ b/src/index.ts @@ -5,7 +5,7 @@ import { createServer } from 'http'; import { createTerminus } from '@godaddy/terminus'; import { Logger } from '@map-colonies/js-logger'; import { container } from 'tsyringe'; -import { get } from 'config'; +import config from 'config'; import { DEFAULT_SERVER_PORT, SERVICES } from './common/constants'; import { getApp } from './app'; @@ -14,7 +14,7 @@ interface IServerConfig { port: string; } -const serverConfig = get('server'); +const serverConfig = config.get('server'); const port: number = parseInt(serverConfig.port) || DEFAULT_SERVER_PORT; const app = getApp(); diff --git a/tests/mocks/data.ts b/tests/mocks/data.ts index 7151b70..baf81c8 100644 --- a/tests/mocks/data.ts +++ b/tests/mocks/data.ts @@ -102,7 +102,7 @@ const layerFromCatalog = { metadata: layerMetadata, }; -const jobsMock: IJobResponse = { +const completedJob: IJobResponse = { id: 'b0b19b88-aecb-4e74-b694-dfa7eada8bf7', resourceId: 'string', version: '1.0', @@ -197,6 +197,89 @@ const jobsMock: IJobResponse = { updated: '2021-12-29T08:07:00.270Z', }; +const inProgressJob: IJobResponse = { + id: 'fa3ab609-377a-4d96-bf0b-e0bb72f683b8', + resourceId: 'string', + version: '1.0', + type: 'rasterTilesExporter', + description: '', + parameters: { + crs: 'EPSG:4326', + bbox: [0, 0, 25, 41], + dbId: '0c3e455f-4aeb-4258-982d-f7773469a92d', + version: '1.0', + footprint: { + type: 'Polygon', + coordinates: [ + [ + [-180, -90], + [-180, 90], + [180, 90], + [180, -90], + [-180, -90], + ], + ], + }, + tilesPath: 'string/1.0/OrthophotoHistory', + callbackURL: ['http://localhost:6969'], + packageName: 'gm_0c3e455f_4aeb_4258_982d_f7773469a92d_4_0_000000_0000025_0000041_00000', + productType: 'OrthophotoHistory', + cswProductId: 'string', + targetResolution: 0.0439453125, + }, + status: OperationStatus.PENDING, + reason: '', + isCleaned: false, + priority: 0, + expirationDate: new Date(), + internalId: '0c3e455f-4aeb-4258-982d-f7773469a92d', + productName: 'string', + productType: 'OrthophotoHistory', + taskCount: 1, + completedTasks: 0, + failedTasks: 0, + expiredTasks: 0, + pendingTasks: 0, + inProgressTasks: 1, + tasks: [ + { + id: '1f765695-338b-4752-b182-a8cbae3c610e', + type: 'rasterTilesExporter', + description: '', + parameters: { + crs: 'EPSG:4326', + bbox: [0, 0, 25, 41], + dbId: '0c3e455f-4aeb-4258-982d-f7773469a92d', + footprint: { + type: 'Polygon', + coordinates: [ + [ + [-180, -90], + [-180, 90], + [180, 90], + [180, -90], + [-180, -90], + ], + ], + }, + tilesPath: 'string/1.0/OrthophotoHistory', + zoomLevel: 4, + callbackURL: ['http://localhost:6969'], + packageName: 'gm_0c3e455f_4aeb_4258_982d_f7773469a92d_4_0_000000_0000025_0000041_00000', + productType: 'OrthophotoHistory', + }, + status: OperationStatus.PENDING, + reason: '', + attempts: 0, + resettable: true, + created: '2021-12-29T10:42:13.487Z', + updated: '2021-12-29T10:42:16.231Z', + }, + ], + created: '2021-12-29T10:42:13.487Z', + updated: '2021-12-29T10:42:13.487Z', +}; + const workerInput: IWorkerInput = { footprint: { type: 'Polygon', @@ -226,9 +309,8 @@ const workerInput: IWorkerInput = { }; const jobs = [ - { ...jobsMock, status: OperationStatus.IN_PROGRESS, tasks: [{ ...jobsMock.tasks[0], status: OperationStatus.IN_PROGRESS }] }, - { ...jobsMock, status: OperationStatus.PENDING, tasks: [{ ...jobsMock.tasks[0], status: OperationStatus.PENDING }] }, - // jobsMock, + inProgressJob, + completedJob, ]; const userInput: ICreatePackage = { @@ -239,4 +321,4 @@ const userInput: ICreatePackage = { crs: 'EPSG:4326', }; -export { layerFromCatalog, workerInput, jobs, userInput }; +export { layerFromCatalog, workerInput, jobs, userInput, completedJob, inProgressJob }; diff --git a/tests/unit/createPackage/models/createPackageModel.spec.ts b/tests/unit/createPackage/models/createPackageModel.spec.ts index 2691d0a..ae5d238 100644 --- a/tests/unit/createPackage/models/createPackageModel.spec.ts +++ b/tests/unit/createPackage/models/createPackageModel.spec.ts @@ -3,7 +3,7 @@ import { JobManagerClient } from '../../../../src/clients/jobManagerClient'; import { RasterCatalogManagerClient } from '../../../../src/clients/rasterCatalogManagerClient'; import { ICreateJobResponse, ICreatePackage } from '../../../../src/common/interfaces'; import { CreatePackageManager } from '../../../../src/createPackage/models/createPackageManager'; -import { jobs, layerFromCatalog, userInput } from '../../../mocks/data'; +import { inProgressJob, jobs, layerFromCatalog, userInput } from '../../../mocks/data'; let createPackageManager: CreatePackageManager; let jobManagerClient: JobManagerClient; @@ -31,7 +31,7 @@ describe('CreatePackageManager', () => { const input = { resourceId: 'temp_resourceId', version: 'temp_version', - dbId: 'layerFromCatalog.id', + dbId: layerFromCatalog.id, targetResolution: 0.0000525, bbox: [0, 0, 0, 0], crs: 'EPSG:4326', @@ -72,7 +72,7 @@ describe('CreatePackageManager', () => { jobManagerClient.createJob = createJobStub.mockResolvedValue(undefined); const jobManager = jobManagerClient as unknown as { getJobs: unknown; updateJob: unknown }; - jobManager.getJobs = getJobsStub.mockResolvedValue([jobs[0], jobs[1]]); + jobManager.getJobs = getJobsStub.mockResolvedValue([inProgressJob]); jobManager.updateJob = updateJobStub.mockResolvedValue(undefined); // eslint-disable-next-line @@ -92,11 +92,11 @@ describe('CreatePackageManager', () => { await createPackageManager.createPackage(userInput); const expectedReturn: ICreateJobResponse = { - jobId: '5da59244-4748-4b0d-89b9-2c5e6ba72e70', - taskIds: ['a3ffa55e-67b7-11ec-90d6-0242ac120003'], + jobId: inProgressJob.id, + taskIds: [inProgressJob.tasks[0].id], }; - expect(getJobsStub).toHaveBeenCalledTimes(2); + expect(getJobsStub).toHaveBeenCalledTimes(4); expect(findLayerStub).toHaveBeenCalledTimes(1); expect(createJobStub).toHaveBeenCalledTimes(0); expect(checkForDuplicateResponse).toEqual(expectedReturn);