Skip to content

Commit 0b776e1

Browse files
author
Kanishka
committed
docs: Add ESLint 9 compatibility note to updateSandboxAuditConfig
1 parent ebe9581 commit 0b776e1

File tree

12 files changed

+552
-28
lines changed

12 files changed

+552
-28
lines changed

package-lock.json

Lines changed: 14 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/spacecat-shared-data-access/src/models/configuration/configuration.model.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,6 @@ class Configuration extends BaseModel {
117117
return false;
118118
}
119119

120-
// Check if an audit type is enabled for sandbox sites
121-
isAuditEnabledForSandbox(auditType) {
122-
return !!this.getSandboxAuditConfig(auditType);
123-
}
124-
125120
// Get configuration for a sandbox audit type
126121
getSandboxAuditConfig(auditType) {
127122
return this.getSandboxAudits()?.enabledAudits?.[auditType] || null;
@@ -132,8 +127,14 @@ class Configuration extends BaseModel {
132127
return Object.keys(this.getSandboxAudits()?.enabledAudits || {});
133128
}
134129

130+
// Check if a specific audit type is enabled for sandbox
131+
isAuditEnabledForSandbox(auditType) {
132+
return this.getSandboxAudits()?.enabledAudits?.[auditType] !== undefined;
133+
}
134+
135135
// Update sandbox audit configuration
136136
// This method updates the sandbox audit configuration for a specific audit type
137+
// Updated to use proper attribute accessors for ESLint 9 compatibility
137138
updateSandboxAuditConfig(auditType, config = {}) {
138139
// eslint-disable-next-line no-console
139140
console.log(`[Configuration Model] Updating sandbox audit config for ${auditType}:`, config);

packages/spacecat-shared-data-access/test/unit/models/audit/audit.model.test.js

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import sinon, { stub } from 'sinon';
1818
import sinonChai from 'sinon-chai';
1919

2020
import Audit from '../../../../src/models/audit/audit.model.js';
21+
import { ValidationError } from '../../../../src/errors/index.js';
2122
import { createElectroMocks } from '../../util.js';
2223

2324
chaiUse(chaiAsPromised);
@@ -146,6 +147,26 @@ describe('AuditModel', () => {
146147
mockRecord.auditResult = [{ scores: { foo: 'bar' } }];
147148
expect(Audit.validateAuditResult(mockRecord.auditResult, 'experimentation')).to.be.true;
148149
});
150+
151+
it('returns true if auditResult has runtimeError', () => {
152+
const auditResultWithError = {
153+
runtimeError: {
154+
message: 'Some error occurred',
155+
stack: 'error stack trace',
156+
},
157+
};
158+
expect(Audit.validateAuditResult(auditResultWithError, 'lhs-mobile')).to.be.true;
159+
});
160+
161+
it('throws error if audit type has expected properties but they are missing', () => {
162+
const auditResult = {
163+
scores: {
164+
// Missing required properties for lhs-mobile
165+
},
166+
};
167+
expect(() => Audit.validateAuditResult(auditResult, 'lhs-mobile'))
168+
.to.throw(ValidationError, 'Missing expected property');
169+
});
149170
});
150171

151172
describe('AuditTypes', () => {
@@ -323,5 +344,60 @@ describe('AuditModel', () => {
323344
},
324345
});
325346
});
347+
348+
it('formats content scraper payload with default processingType when not provided', () => {
349+
const stepResult = {
350+
urls: [{ url: 'someUrl' }],
351+
siteId: 'someSiteId',
352+
// No processingType provided
353+
};
354+
const context = {
355+
env: {
356+
AUDIT_JOBS_QUEUE_URL: 'audit-jobs-queue-url',
357+
},
358+
};
359+
const auditContext = { some: 'context' };
360+
const formattedPayload = auditStepDestinationConfigs[auditStepDestinations.CONTENT_SCRAPER]
361+
.formatPayload(stepResult, auditContext, context);
362+
363+
expect(formattedPayload).to.deep.equal({
364+
urls: [{ url: 'someUrl' }],
365+
jobId: 'someSiteId',
366+
processingType: 'default', // Should default to 'default'
367+
completionQueueUrl: 'audit-jobs-queue-url',
368+
skipMessage: false,
369+
allowCache: true,
370+
options: {},
371+
auditContext: { some: 'context' },
372+
});
373+
});
374+
375+
it('formats scrape client payload with default processingType when not provided', () => {
376+
const stepResult = {
377+
urls: [{ url: 'someUrl' }],
378+
siteId: 'someSiteId',
379+
// No processingType provided
380+
};
381+
const context = {
382+
env: {
383+
AUDIT_JOBS_QUEUE_URL: 'audit-jobs-queue-url',
384+
},
385+
};
386+
const auditContext = { some: 'context' };
387+
const formattedPayload = auditStepDestinationConfigs[auditStepDestinations.SCRAPE_CLIENT]
388+
.formatPayload(stepResult, auditContext, context);
389+
390+
expect(formattedPayload).to.deep.equal({
391+
urls: ['someUrl'],
392+
options: {},
393+
processingType: 'default', // Should default to 'default'
394+
maxScrapeAge: 24,
395+
auditData: {
396+
siteId: 'someSiteId',
397+
completionQueueUrl: 'audit-jobs-queue-url',
398+
auditContext: { some: 'context' },
399+
},
400+
});
401+
});
326402
});
327403
});

packages/spacecat-shared-data-access/test/unit/models/configuration/configuration.model.test.js

Lines changed: 93 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -295,15 +295,16 @@ describe('ConfigurationModel', () => {
295295
queues: { test: 'test' },
296296
jobs: [],
297297
handlers: {},
298-
sandboxAudits: {
299-
enabledAudits: {
300-
cwv: {
301-
expire: '5',
302-
},
303-
'alt-text': {},
298+
};
299+
// Set sandboxAudits using the proper attribute setter
300+
instance.setSandboxAudits({
301+
enabledAudits: {
302+
cwv: {
303+
expire: '5',
304304
},
305+
'alt-text': {},
305306
},
306-
};
307+
});
307308
});
308309

309310
it('checks if audit is enabled for sandbox', () => {
@@ -341,15 +342,98 @@ describe('ConfigurationModel', () => {
341342
});
342343

343344
it('returns empty array when no sandbox audits configured', () => {
344-
delete instance.state.sandboxAudits;
345+
instance.setSandboxAudits(null);
345346
expect(instance.getEnabledSandboxAudits()).to.deep.equal([]);
346347
});
347348

348349
it('handles updating non-existent sandbox config', () => {
349-
delete instance.state.sandboxAudits;
350+
instance.setSandboxAudits(null);
350351
instance.updateSandboxAuditConfig('new-audit', { expire: '5' });
351352
expect(instance.getSandboxAuditConfig('new-audit')).to.deep.equal({ expire: '5' });
352353
});
354+
355+
it('handles getSandboxAuditConfig when sandboxAudits is null', () => {
356+
instance.setSandboxAudits(null);
357+
expect(instance.getSandboxAuditConfig('any-audit')).to.be.null;
358+
});
359+
360+
it('handles getSandboxAuditConfig when sandboxAudits is undefined', () => {
361+
instance.setSandboxAudits(undefined);
362+
expect(instance.getSandboxAuditConfig('any-audit')).to.be.null;
363+
});
364+
365+
it('handles getSandboxAuditConfig when enabledAudits is null', () => {
366+
instance.setSandboxAudits({ enabledAudits: null });
367+
expect(instance.getSandboxAuditConfig('any-audit')).to.be.null;
368+
});
369+
370+
it('handles getEnabledSandboxAudits when sandboxAudits is null', () => {
371+
instance.setSandboxAudits(null);
372+
expect(instance.getEnabledSandboxAudits()).to.deep.equal([]);
373+
});
374+
375+
it('handles getEnabledSandboxAudits when sandboxAudits is undefined', () => {
376+
instance.setSandboxAudits(undefined);
377+
expect(instance.getEnabledSandboxAudits()).to.deep.equal([]);
378+
});
379+
380+
it('handles getEnabledSandboxAudits when enabledAudits is null', () => {
381+
instance.setSandboxAudits({ enabledAudits: null });
382+
expect(instance.getEnabledSandboxAudits()).to.deep.equal([]);
383+
});
384+
385+
it('handles isAuditEnabledForSandbox when sandboxAudits is null', () => {
386+
instance.setSandboxAudits(null);
387+
expect(instance.isAuditEnabledForSandbox('any-audit')).to.be.false;
388+
});
389+
390+
it('handles isAuditEnabledForSandbox when sandboxAudits is undefined', () => {
391+
instance.setSandboxAudits(undefined);
392+
expect(instance.isAuditEnabledForSandbox('any-audit')).to.be.false;
393+
});
394+
395+
it('handles isAuditEnabledForSandbox when enabledAudits is null', () => {
396+
instance.setSandboxAudits({ enabledAudits: null });
397+
expect(instance.isAuditEnabledForSandbox('any-audit')).to.be.false;
398+
});
399+
400+
it('handles removeSandboxAuditConfig when sandboxAudits is null', () => {
401+
instance.setSandboxAudits(null);
402+
// Should not throw error when trying to remove from null sandboxAudits
403+
instance.removeSandboxAuditConfig('any-audit');
404+
expect(instance.getSandboxAudits()).to.be.null;
405+
});
406+
407+
it('handles removeSandboxAuditConfig when sandboxAudits is undefined', () => {
408+
instance.setSandboxAudits(undefined);
409+
// Should not throw error when trying to remove from undefined sandboxAudits
410+
instance.removeSandboxAuditConfig('any-audit');
411+
expect(instance.getSandboxAudits()).to.be.undefined;
412+
});
413+
414+
it('handles removeSandboxAuditConfig when enabledAudits is null', () => {
415+
instance.setSandboxAudits({ enabledAudits: null });
416+
// Should not throw error when trying to remove from null enabledAudits
417+
instance.removeSandboxAuditConfig('any-audit');
418+
expect(instance.getSandboxAudits()).to.deep.equal({ enabledAudits: null });
419+
});
420+
});
421+
422+
describe('Handler Management', () => {
423+
it('handles disableHandlerForSite when handler is not enabled', () => {
424+
const mockSite = {
425+
getId: () => 'site2',
426+
getOrganizationId: () => 'org2',
427+
};
428+
// Should not throw error when trying to disable non-enabled handler
429+
expect(() => instance.disableHandlerForSite('cwv', mockSite)).to.not.throw();
430+
});
431+
432+
it('handles disableHandlerForOrg when handler is not enabled', () => {
433+
const mockOrg = { getId: () => 'org2' };
434+
// Should not throw error when trying to disable non-enabled handler
435+
expect(() => instance.disableHandlerForOrg('cwv', mockOrg)).to.not.throw();
436+
});
353437
});
354438

355439
describe('save', () => {

0 commit comments

Comments
 (0)