@@ -30,6 +30,13 @@ describe('Disable Import Audit Processor', () => {
3030 let mockSite ;
3131 let mockSiteConfig ;
3232 let mockConfiguration ;
33+ let toDynamoItemStub ;
34+
35+ const serializedConfigFixture = {
36+ slack : { } ,
37+ handlers : { } ,
38+ imports : [ ] ,
39+ } ;
3340
3441 beforeEach ( async ( ) => {
3542 // Reset all stubs
@@ -41,11 +48,16 @@ describe('Disable Import Audit Processor', () => {
4148 // Mock the say function
4249 mockSay = sandbox . stub ( ) . resolves ( ) ;
4350
51+ toDynamoItemStub = sandbox . stub ( ) . returns ( serializedConfigFixture ) ;
52+
4453 // Dynamic import with mocked dependencies
4554 const handlerModule = await esmock ( '../../../src/tasks/disable-import-audit-processor/handler.js' , {
4655 '../../../src/utils/slack-utils.js' : {
4756 say : mockSay ,
4857 } ,
58+ '@adobe/spacecat-shared-data-access' : {
59+ Config : { toDynamoItem : toDynamoItemStub } ,
60+ } ,
4961 } ) ;
5062 runDisableImportAuditProcessor = handlerModule . runDisableImportAuditProcessor ;
5163
@@ -56,6 +68,7 @@ describe('Disable Import Audit Processor', () => {
5668
5769 mockSite = {
5870 getConfig : sandbox . stub ( ) . returns ( mockSiteConfig ) ,
71+ setConfig : sandbox . stub ( ) ,
5972 save : sandbox . stub ( ) . resolves ( ) ,
6073 } ;
6174
@@ -114,6 +127,9 @@ describe('Disable Import Audit Processor', () => {
114127 expect ( mockSiteConfig . disableImport ) . to . have . been . calledWith ( 'screaming-frog' ) ;
115128 expect ( mockSiteConfig . disableImport ) . to . have . callCount ( 2 ) ;
116129
130+ expect ( toDynamoItemStub ) . to . have . been . calledOnceWith ( mockSiteConfig ) ;
131+ expect ( mockSite . setConfig ) . to . have . been . calledOnceWith ( serializedConfigFixture ) ;
132+
117133 // Verify audit types were disabled
118134 expect ( context . dataAccess . Configuration . findLatest ) . to . have . been . calledOnce ;
119135 expect ( mockConfiguration . disableHandlerForSite ) . to . have . been . calledWith ( 'cwv' , mockSite ) ;
@@ -160,6 +176,9 @@ describe('Disable Import Audit Processor', () => {
160176 expect ( mockSite . save ) . to . have . been . calledOnce ;
161177 expect ( mockConfiguration . save ) . to . have . been . calledOnce ;
162178
179+ expect ( toDynamoItemStub ) . to . have . been . calledOnceWith ( mockSiteConfig ) ;
180+ expect ( mockSite . setConfig ) . to . have . been . calledOnceWith ( serializedConfigFixture ) ;
181+
163182 // Verify Slack messages with "None" text
164183 expect ( mockSay . firstCall ) . to . have . been . calledWith (
165184 context . env ,
@@ -190,6 +209,9 @@ describe('Disable Import Audit Processor', () => {
190209 ':broom: *For site: https://example.com: Disabled imports*: None *and audits*: None' ,
191210 ) ;
192211
212+ expect ( toDynamoItemStub ) . to . have . been . calledOnceWith ( mockSiteConfig ) ;
213+ expect ( mockSite . setConfig ) . to . have . been . calledOnceWith ( serializedConfigFixture ) ;
214+
193215 expect ( result ) . to . exist ;
194216 } ) ;
195217
@@ -200,6 +222,8 @@ describe('Disable Import Audit Processor', () => {
200222
201223 // Should complete without error
202224 expect ( context . log . info ) . to . have . been . calledWith ( 'For site: https://example.com: Disabled imports and audits' ) ;
225+ expect ( toDynamoItemStub ) . to . have . been . calledOnceWith ( mockSiteConfig ) ;
226+ expect ( mockSite . setConfig ) . to . have . been . calledOnceWith ( serializedConfigFixture ) ;
203227 expect ( mockSay ) . to . have . been . calledTwice ;
204228 expect ( result ) . to . exist ;
205229 } ) ;
@@ -275,6 +299,7 @@ describe('Disable Import Audit Processor', () => {
275299 const result = await runDisableImportAuditProcessor ( message , context ) ;
276300
277301 expect ( context . log . error ) . to . have . been . calledWith ( 'Error in disable import and audit processor:' , sinon . match . instanceOf ( Error ) ) ;
302+ expect ( mockSite . setConfig ) . to . not . have . been . called ;
278303 expect ( mockSite . save ) . to . not . have . been . called ;
279304 expect ( mockConfiguration . save ) . to . not . have . been . called ;
280305
@@ -296,6 +321,8 @@ describe('Disable Import Audit Processor', () => {
296321 const result = await runDisableImportAuditProcessor ( message , context ) ;
297322
298323 expect ( context . log . error ) . to . have . been . calledWith ( 'Error in disable import and audit processor:' , saveError ) ;
324+ expect ( toDynamoItemStub ) . to . have . been . calledOnceWith ( mockSiteConfig ) ;
325+ expect ( mockSite . setConfig ) . to . have . been . calledOnceWith ( serializedConfigFixture ) ;
299326 expect ( mockSay ) . to . have . been . calledWith (
300327 context . env ,
301328 context . log ,
@@ -313,6 +340,8 @@ describe('Disable Import Audit Processor', () => {
313340 const result = await runDisableImportAuditProcessor ( message , context ) ;
314341
315342 expect ( context . log . error ) . to . have . been . calledWith ( 'Error in disable import and audit processor:' , saveError ) ;
343+ expect ( toDynamoItemStub ) . to . have . been . calledOnceWith ( mockSiteConfig ) ;
344+ expect ( mockSite . setConfig ) . to . have . been . calledOnceWith ( serializedConfigFixture ) ;
316345 expect ( mockSay ) . to . have . been . calledWith (
317346 context . env ,
318347 context . log ,
@@ -330,6 +359,7 @@ describe('Disable Import Audit Processor', () => {
330359 const result = await runDisableImportAuditProcessor ( message , context ) ;
331360
332361 expect ( context . log . error ) . to . have . been . calledWith ( 'Error in disable import and audit processor:' , lookupError ) ;
362+ expect ( mockSite . setConfig ) . to . not . have . been . called ;
333363 expect ( mockSay ) . to . have . been . calledWith (
334364 context . env ,
335365 context . log ,
@@ -347,6 +377,8 @@ describe('Disable Import Audit Processor', () => {
347377 const result = await runDisableImportAuditProcessor ( message , context ) ;
348378
349379 expect ( context . log . error ) . to . have . been . calledWith ( 'Error in disable import and audit processor:' , configError ) ;
380+ expect ( toDynamoItemStub ) . to . have . been . calledOnceWith ( mockSiteConfig ) ;
381+ expect ( mockSite . setConfig ) . to . have . been . calledOnceWith ( serializedConfigFixture ) ;
350382 expect ( mockSay ) . to . have . been . calledWith (
351383 context . env ,
352384 context . log ,
@@ -365,6 +397,8 @@ describe('Disable Import Audit Processor', () => {
365397 const result = await runDisableImportAuditProcessor ( message , context ) ;
366398
367399 // Should still complete successfully despite Slack error
400+ expect ( toDynamoItemStub ) . to . have . been . calledOnceWith ( mockSiteConfig ) ;
401+ expect ( mockSite . setConfig ) . to . have . been . calledOnceWith ( serializedConfigFixture ) ;
368402 expect ( mockSite . save ) . to . have . been . calledOnce ;
369403 expect ( mockConfiguration . save ) . to . have . been . calledOnce ;
370404 expect ( result ) . to . exist ;
@@ -421,6 +455,9 @@ describe('Disable Import Audit Processor', () => {
421455 ':broom: *For site: https://example.com: Disabled imports*: single-import *and audits*: single-audit' ,
422456 ) ;
423457
458+ expect ( toDynamoItemStub ) . to . have . been . calledOnceWith ( mockSiteConfig ) ;
459+ expect ( mockSite . setConfig ) . to . have . been . calledOnceWith ( serializedConfigFixture ) ;
460+
424461 expect ( result ) . to . exist ;
425462 } ) ;
426463 } ) ;
0 commit comments