Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions packages/spacecat-shared-data-access/src/models/site/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,10 @@ export const configSchema = Joi.object({
startTime: Joi.number().optional(),
})).optional(),
}).optional(),
rumConfig: Joi.object({
hasDomainKey: Joi.boolean().required(),
lastCheckedAt: Joi.string().isoDate().required(),
}).optional(),
commerceLlmoConfig: Joi.object().pattern(
Joi.string(),
Joi.object({
Expand Down Expand Up @@ -542,6 +546,8 @@ export const Config = (data = {}) => {
self.getEdgeOptimizeConfig = () => state?.edgeOptimizeConfig;
self.getOnboardConfig = () => state?.onboardConfig;
self.getCommerceLlmoConfig = () => state?.commerceLlmoConfig;
self.getRumConfig = () => state?.rumConfig;
self.hasRumDomainKey = () => state?.rumConfig?.hasDomainKey === true;
const AUDIT_TARGET_SOURCES = ['manual', 'moneyPages'];
const auditTargetEntrySchema = Joi.object({
url: Joi.string().uri().required(),
Expand Down Expand Up @@ -955,6 +961,13 @@ export const Config = (data = {}) => {
state.commerceLlmoConfig = commerceLlmoConfig;
};

self.updateRumConfig = (hasDomainKey) => {
state.rumConfig = {
hasDomainKey,
lastCheckedAt: new Date().toISOString(),
};
};

return Object.freeze(self);
};

Expand All @@ -974,6 +987,7 @@ Config.toDynamoItem = (config) => ({
edgeOptimizeConfig: config.getEdgeOptimizeConfig(),
onboardConfig: config.getOnboardConfig?.(),
commerceLlmoConfig: config.getCommerceLlmoConfig?.(),
rumConfig: config.getRumConfig?.(),
enableMoneyPageUrls: config.isMoneyPageUrlsEnabled?.() === false ? false : undefined,
auditTargetURLs: config.getAuditTargetURLsConfig?.(),
});
Original file line number Diff line number Diff line change
Expand Up @@ -3013,6 +3013,113 @@ describe('Config Tests', () => {
});
});

describe('rumConfig', () => {
describe('getRumConfig', () => {
it('returns rumConfig when set', () => {
const config = Config({
rumConfig: { hasDomainKey: true, lastCheckedAt: '2026-05-08T00:00:00.000Z' },
});
expect(config.getRumConfig()).to.deep.equal({
hasDomainKey: true,
lastCheckedAt: '2026-05-08T00:00:00.000Z',
});
});

it('returns undefined when rumConfig is absent', () => {
const config = Config({});
expect(config.getRumConfig()).to.be.undefined;
});
});

describe('hasRumDomainKey', () => {
it('returns true when hasDomainKey is true', () => {
const config = Config({
rumConfig: { hasDomainKey: true, lastCheckedAt: '2026-05-08T00:00:00.000Z' },
});
expect(config.hasRumDomainKey()).to.be.true;
});

it('returns false when hasDomainKey is false', () => {
const config = Config({
rumConfig: { hasDomainKey: false, lastCheckedAt: '2026-05-08T00:00:00.000Z' },
});
expect(config.hasRumDomainKey()).to.be.false;
});

it('returns false when rumConfig is absent', () => {
const config = Config({});
expect(config.hasRumDomainKey()).to.be.false;
});
});

describe('updateRumConfig', () => {
it('sets hasDomainKey to true and records lastCheckedAt', () => {
const before = new Date();
const config = Config({});
config.updateRumConfig(true);
const rum = config.getRumConfig();
expect(rum.hasDomainKey).to.be.true;
expect(new Date(rum.lastCheckedAt).getTime()).to.be.gte(before.getTime());
});

it('sets hasDomainKey to false and records lastCheckedAt', () => {
const config = Config({});
config.updateRumConfig(false);
expect(config.getRumConfig().hasDomainKey).to.be.false;
expect(config.getRumConfig().lastCheckedAt).to.match(/^\d{4}-\d{2}-\d{2}T/);
});

it('overwrites a previous rumConfig value', () => {
const config = Config({
rumConfig: { hasDomainKey: true, lastCheckedAt: '2025-01-01T00:00:00.000Z' },
});
config.updateRumConfig(false);
expect(config.hasRumDomainKey()).to.be.false;
expect(config.getRumConfig().lastCheckedAt).to.not.equal('2025-01-01T00:00:00.000Z');
});
});

describe('Joi schema validation', () => {
it('accepts a valid rumConfig', () => {
expect(() => Config({
rumConfig: { hasDomainKey: true, lastCheckedAt: '2026-05-08T00:00:00.000Z' },
})).to.not.throw();
});

it('rejects rumConfig missing hasDomainKey', () => {
expect(() => validateConfiguration({
rumConfig: { lastCheckedAt: '2026-05-08T00:00:00.000Z' },
})).to.throw(/hasDomainKey/);
});

it('rejects rumConfig with invalid lastCheckedAt', () => {
expect(() => validateConfiguration({
rumConfig: { hasDomainKey: true, lastCheckedAt: 'not-a-date' },
})).to.throw(/lastCheckedAt/);
});

it('treats absent rumConfig as valid (optional field)', () => {
expect(() => validateConfiguration({})).to.not.throw();
});
});

describe('toDynamoItem serialization', () => {
it('includes rumConfig when set', () => {
const config = Config({
rumConfig: { hasDomainKey: true, lastCheckedAt: '2026-05-08T00:00:00.000Z' },
});
const item = Config.toDynamoItem(config);
expect(item.rumConfig).to.deep.equal(config.getRumConfig());
});

it('omits rumConfig from toDynamoItem when not set', () => {
const config = Config({});
const item = Config.toDynamoItem(config);
expect(item.rumConfig).to.be.undefined;
});
});
});

describe('LLMO Well Known Tags', () => {
const { extractWellKnownTags } = Config();

Expand Down
Loading