Skip to content

Commit

Permalink
chore: update data types to mc priorty queue
Browse files Browse the repository at this point in the history
  • Loading branch information
AnguIar committed Dec 29, 2021
1 parent 355d6cf commit 14d69da
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 15 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -14,7 +14,7 @@ interface IServerConfig {
port: string;
}

const serverConfig = get<IServerConfig>('server');
const serverConfig = config.get<IServerConfig>('server');
const port: number = parseInt(serverConfig.port) || DEFAULT_SERVER_PORT;

const app = getApp();
Expand Down
92 changes: 87 additions & 5 deletions tests/mocks/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ const layerFromCatalog = {
metadata: layerMetadata,
};

const jobsMock: IJobResponse<IJobParameters, ITaskParameters> = {
const completedJob: IJobResponse<IJobParameters, ITaskParameters> = {
id: 'b0b19b88-aecb-4e74-b694-dfa7eada8bf7',
resourceId: 'string',
version: '1.0',
Expand Down Expand Up @@ -197,6 +197,89 @@ const jobsMock: IJobResponse<IJobParameters, ITaskParameters> = {
updated: '2021-12-29T08:07:00.270Z',
};

const inProgressJob: IJobResponse<IJobParameters, ITaskParameters> = {
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',
Expand Down Expand Up @@ -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 = {
Expand All @@ -239,4 +321,4 @@ const userInput: ICreatePackage = {
crs: 'EPSG:4326',
};

export { layerFromCatalog, workerInput, jobs, userInput };
export { layerFromCatalog, workerInput, jobs, userInput, completedJob, inProgressJob };
12 changes: 6 additions & 6 deletions tests/unit/createPackage/models/createPackageModel.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand Down

0 comments on commit 14d69da

Please sign in to comment.