Skip to content

Commit

Permalink
fix(sites): update hlxConfig via API (#707)
Browse files Browse the repository at this point in the history
  • Loading branch information
ekremney authored Jan 17, 2025
1 parent 1b70ea9 commit 1f42265
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/controllers/sites.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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));
Expand Down
9 changes: 7 additions & 2 deletions test/controllers/sites.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
{
Expand All @@ -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 },
},
},
},
Expand Down Expand Up @@ -222,6 +223,9 @@ describe('Sites Controller', () => {
deliveryType: 'other',
gitHubURL: 'https://github.com/blah/bluh',
config: {},
hlxConfig: {
field: true,
},
},
});

Expand All @@ -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 () => {
Expand Down

0 comments on commit 1f42265

Please sign in to comment.