diff --git a/src/controllers/sites.js b/src/controllers/sites.js index c089de4e2..621847a75 100755 --- a/src/controllers/sites.js +++ b/src/controllers/sites.js @@ -22,7 +22,7 @@ import { hasText, isBoolean, isObject, - getStoredMetrics, getRUMDomainKey, isValidUUID, + getStoredMetrics, getRUMDomainKey, isValidUUID, deepEqual, } from '@adobe/spacecat-shared-utils'; import { Site as SiteModel } from '@adobe/spacecat-shared-data-access'; @@ -280,6 +280,11 @@ function SitesController(dataAccess, log, env) { updates = true; } + if (isObject(requestBody.hlxConfig) && !deepEqual(requestBody.hlxConfig, site.getHlxConfig())) { + site.setHlxConfig(requestBody.hlxConfig); + updates = true; + } + if (updates) { const updatedSite = await site.save(); return ok(SiteDto.toJSON(updatedSite)); diff --git a/test/controllers/sites.test.js b/test/controllers/sites.test.js index f38b2e631..48450241a 100644 --- a/test/controllers/sites.test.js +++ b/test/controllers/sites.test.js @@ -37,10 +37,10 @@ describe('Sites Controller', () => { const sites = [ { - siteId: SITE_IDS[0], baseURL: 'https://site1.com', deliveryType: 'aem_edge', config: Config({}), + siteId: SITE_IDS[0], baseURL: 'https://site1.com', deliveryType: 'aem_edge', config: Config({}), hlxConfig: {}, }, { - siteId: SITE_IDS[1], baseURL: 'https://site2.com', deliveryType: 'aem_edge', config: Config({}), + siteId: SITE_IDS[1], baseURL: 'https://site2.com', deliveryType: 'aem_edge', config: Config({}), hlxConfig: {}, }, ].map((site) => new Site( { @@ -55,6 +55,7 @@ describe('Sites Controller', () => { gitHubURL: { type: 'string', name: 'gitHubURL', get: (value) => value }, isLive: { type: 'boolean', name: 'isLive', get: (value) => value }, organizationId: { type: 'string', name: 'organizationId', get: (value) => value }, + hlxConfig: { type: 'any', name: 'hlxConfig', get: (value) => value }, }, }, }, @@ -222,6 +223,9 @@ describe('Sites Controller', () => { deliveryType: 'other', gitHubURL: 'https://github.com/blah/bluh', config: {}, + hlxConfig: { + field: true, + }, }, }); @@ -233,6 +237,7 @@ describe('Sites Controller', () => { expect(updatedSite).to.have.property('baseURL', 'https://site1.com'); expect(updatedSite).to.have.property('deliveryType', 'other'); expect(updatedSite).to.have.property('gitHubURL', 'https://github.com/blah/bluh'); + expect(updatedSite.hlxConfig).to.deep.equal({ field: true }); }); it('returns bad request when updating a site if id not provided', async () => {