From 78b7da363a89dfe5f5e50baf26a6ec09430d7e9d Mon Sep 17 00:00:00 2001 From: RowHeat <40065760+rowheat02@users.noreply.github.com> Date: Wed, 15 Jan 2025 13:46:19 +0545 Subject: [PATCH] fix:proxy call for CORS disabled domain for Model layer (#10745) --- .../map/cesium/__tests__/Layer-test.jsx | 35 +++++++++++++++++++ .../map/cesium/plugins/ModelLayer.js | 5 ++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/web/client/components/map/cesium/__tests__/Layer-test.jsx b/web/client/components/map/cesium/__tests__/Layer-test.jsx index a8fbac721d..9aff8bc9da 100644 --- a/web/client/components/map/cesium/__tests__/Layer-test.jsx +++ b/web/client/components/map/cesium/__tests__/Layer-test.jsx @@ -28,9 +28,13 @@ import '../plugins/WFSLayer'; import '../plugins/TerrainLayer'; import '../plugins/ElevationLayer'; import '../plugins/ArcGISLayer'; +import '../plugins/ModelLayer'; import {setStore} from '../../../../utils/SecurityUtils'; import ConfigUtils from '../../../../utils/ConfigUtils'; +import MockAdapter from 'axios-mock-adapter'; +import axios from '../../../../libs/ajax'; + describe('Cesium layer', () => { let map; @@ -1741,4 +1745,35 @@ describe('Cesium layer', () => { done(); }).catch(done); }); + + it('ensure proxy usage in Model layer', (done) => { + const options = { + type: "model", + // url that fails + url: "https://test-CORS/FontaneMarosegeoreferenziato.ifc", + visibility: true, + format: 'ifc' + }; + + // Create a mock adapter for axios + const mockAxios = new MockAdapter(axios); + + ReactDOM.render( + , document.getElementById('container')); + + + setTimeout(() => { + // Check if the API call was made + expect(mockAxios.history.get.length).toBe(1); + // ensure calling from proxy URL (CORS test is performed on fetch before this call) + expect(mockAxios.history.get[0].url.includes('/proxy')).toBe(true); // Check the URL + expect(mockAxios.history.get[0].url.includes('?url=https%3A%2F%2Ftest-cors%2FFontaneMarosegeoreferenziato.ifc')).toBe(true); + mockAxios.restore(); // Restore the original axios instance + done(); + }, 1000); + }); }); diff --git a/web/client/components/map/cesium/plugins/ModelLayer.js b/web/client/components/map/cesium/plugins/ModelLayer.js index 71f8525416..d485c76e40 100644 --- a/web/client/components/map/cesium/plugins/ModelLayer.js +++ b/web/client/components/map/cesium/plugins/ModelLayer.js @@ -189,10 +189,13 @@ const createLayer = (options, map) => { Layers.registerType('model', { create: createLayer, - update: (layer, newOptions, oldOptions) => { + update: (layer, newOptions, oldOptions, map) => { if (layer?.primitives && !isEqual(newOptions?.features?.[0], oldOptions?.features?.[0])) { updatePrimitivesMatrix(layer?.primitives, newOptions?.features?.[0]); } + if (newOptions?.forceProxy !== oldOptions?.forceProxy) { + return createLayer(newOptions, map); + } return null; } });