11import jsLogger from '@map-colonies/js-logger' ;
22import { faker } from '@faker-js/faker' ;
3- import { AggregationFeature , RoiFeatureCollection } from '@map-colonies/raster-shared' ;
3+ import { AggregationFeature , RasterProductTypes , RoiFeatureCollection } from '@map-colonies/raster-shared' ;
44import nock from 'nock' ;
55import { PolygonPartsMangerClient } from '../../../src/httpClients/polygonPartsMangerClient' ;
66import { createFakeRoiFeatureCollection } from '../mocks/exportMockData' ;
7- import { LayerMetadataAggregationError } from '../../../src/common/errors' ;
7+ import { LayerMetadataAggregationError , PolygonPartsProcessingError } from '../../../src/common/errors' ;
8+ import { PolygonPartsProcessPayload } from '../../../src/common/interfaces' ;
89import { configMock , registerDefaultConfig } from '../mocks/configMock' ;
910import { createFakeAggregatedFeature } from './catalogClientSetup' ;
1011
@@ -18,6 +19,44 @@ describe('polygonPartsManagerClient', () => {
1819 jest . resetAllMocks ( ) ;
1920 } ) ;
2021
22+ describe ( 'process' , ( ) => {
23+ it ( 'should process polygon parts successfully' , async ( ) => {
24+ polygonPartsManagerClient = new PolygonPartsMangerClient ( configMock , jsLogger ( { enabled : false } ) ) ;
25+
26+ const baseUrl = configMock . get < string > ( 'servicesUrl.polygonPartsManager' ) ;
27+ const payload : PolygonPartsProcessPayload = {
28+ jobType : 'Ingestion_New' ,
29+ productId : 'test_layer' ,
30+ productType : RasterProductTypes . ORTHOPHOTO ,
31+ } ;
32+ const url = '/polygonParts/process' ;
33+ nock ( baseUrl ) . put ( url , payload ) . reply ( 200 ) ;
34+
35+ const action = polygonPartsManagerClient . process ( payload ) ;
36+
37+ await expect ( action ) . resolves . toBeUndefined ( ) ;
38+ expect ( nock . isDone ( ) ) . toBe ( true ) ;
39+ } ) ;
40+
41+ it ( 'should throw PolygonPartsProcessingError when the request fails' , async ( ) => {
42+ polygonPartsManagerClient = new PolygonPartsMangerClient ( configMock , jsLogger ( { enabled : false } ) ) ;
43+
44+ const baseUrl = configMock . get < string > ( 'servicesUrl.polygonPartsManager' ) ;
45+ const payload : PolygonPartsProcessPayload = {
46+ jobType : 'Ingestion_New' ,
47+ productId : 'test_layer' ,
48+ productType : RasterProductTypes . ORTHOPHOTO ,
49+ } ;
50+ const url = '/polygonParts/process' ;
51+ nock ( baseUrl ) . put ( url , payload ) . reply ( 500 ) ;
52+
53+ const action = polygonPartsManagerClient . process ( payload ) ;
54+
55+ await expect ( action ) . rejects . toThrow ( PolygonPartsProcessingError ) ;
56+ expect ( nock . isDone ( ) ) . toBe ( true ) ;
57+ } ) ;
58+ } ) ;
59+
2160 describe ( 'getAggregatedLayerMetadata' , ( ) => {
2261 it ( 'should return aggregated part data based on polygonPartsEntityName' , async ( ) => {
2362 polygonPartsManagerClient = new PolygonPartsMangerClient ( configMock , jsLogger ( { enabled : false } ) ) ;
0 commit comments