Skip to content

Commit

Permalink
fix: return proper config object (#516)
Browse files Browse the repository at this point in the history
  • Loading branch information
solaris007 authored Dec 31, 2024
1 parent a51afa1 commit 84a393a
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
* governing permissions and limitations under the License.
*/

import { Config } from '../../../models/site/config.js';
import BaseModel from '../base/base.model.js';

/**
Expand All @@ -27,10 +26,6 @@ class Site extends BaseModel {

static DEFAULT_DELIVERY_TYPE = Site.DELIVERY_TYPES.AEM_EDGE;

getConfig() {
return Config(this.record.config);
}

async toggleLive() {
const newIsLive = !this.getIsLive();
this.setIsLive(newIsLive);
Expand Down
76 changes: 51 additions & 25 deletions packages/spacecat-shared-data-access/test/fixtures/sites.fixture.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,35 +20,61 @@ const sites = [
isLive: true,
isLiveToggledAt: '2024-11-29T07:45:55.952Z',
GSI1PK: 'ALL_SITES',
config:
{
slack:
{
workspace: '0-workspace',
channel: '0-channel',
config: {
handlers: {
404: {
mentions: {
slack: [],
},
handlers:
{
404:
{
byOrg: true,
mentions:
{
slack:
[
'0-slackId',
],
},
},
'broken-backlinks': {
excludedURLs: [],
manualOverwrites: [],
fixedURLs: [],
mentions: {
slack: [],
},
},
},
slack: {
channel: 'some-channel',
},
imports: [
{
type: 'rum-to-aa',
mapper: {
mapping: {
pageURL: {
rumField: 'url',
},
'lhs-mobile':
{
excludedURLs:
[
'https://example.com/excluded',
],
userAgent: {
default: 'rum/1.0.0',
},
eVars: {
eVar4: {
default: 'RUM',
},
eVar3: {
rumField: 'url',
},
},
events: {
event4: {
rumField: 'pageviews',
},
},
reportSuiteID: {
default: 'ageo1xxpnwdemoexpleugue',
},
visitorID: {
default: '000',
},
},
timezone: 'UTC-07:00',
},
},
},
],
},
},
{
siteId: '78fec9c7-2141-4600-b7b1-ea5c78752b91',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { isIsoDate } from '@adobe/spacecat-shared-utils';
import { expect, use } from 'chai';
import chaiAsPromised from 'chai-as-promised';

import siteFixtures from '../../fixtures/sites.fixture.js';
import { sanitizeTimestamps } from '../../../src/v2/util/util.js';
import { getDataAccess } from '../util/db.js';
import { seedDatabase } from '../util/seed.js';
Expand Down Expand Up @@ -339,6 +340,14 @@ describe('Site IT', async () => {
expect(updatedSite.getOrganizationId()).to.equal(updates.organizationId);
});

it('reads config of a site', async () => {
const { config: configFixture } = siteFixtures[0];
const site = await Site.findById('5d6d4439-6659-46c2-b646-92d110fa5a52');
const config = site.getConfig();
expect(config).to.be.an('object');
expect(config.state).to.deep.equals(configFixture);
});

it('removes a site', async () => {
const site = await Site.findById(sampleData.sites[0].getId());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import sinonChai from 'sinon-chai';

import Site from '../../../../../src/v2/models/site/site.model.js';
import siteFixtures from '../../../../fixtures/sites.fixture.js';
import { Config } from '../../../../../src/models/site/config.js';
import { createElectroMocks } from '../../util.js';

chaiUse(chaiAsPromised);
Expand Down Expand Up @@ -81,9 +80,9 @@ describe('SiteModel', () => {

describe('config', () => {
it('gets config', () => {
const config = Config.toDynamoItem(instance.getConfig());
const config = instance.getConfig();
delete config.imports;
expect(config).to.deep.equal(sampleSite.config);
expect(config).to.deep.equal(siteFixtures[0].config);
});
});

Expand Down

0 comments on commit 84a393a

Please sign in to comment.