-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaudit-base-command.test.ts
More file actions
615 lines (569 loc) · 23.4 KB
/
audit-base-command.test.ts
File metadata and controls
615 lines (569 loc) · 23.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
import fs from 'fs';
import winston from 'winston';
import sinon from 'sinon';
import { resolve } from 'path';
import { fancy } from 'fancy-test';
import { PassThrough } from 'stream';
import { expect } from 'chai';
import { ux, cliux, CLIProgressManager, configHandler, clearProgressModuleSetting } from '@contentstack/cli-utilities';
import { AuditBaseCommand } from '../../src/audit-base-command';
import {
ContentType,
Entries,
GlobalField,
Extensions,
Workflows,
CustomRoles,
Assets,
FieldRule,
} from '../../src/modules';
import { FileTransportInstance } from 'winston/lib/winston/transports';
import { $t, auditMsg } from '../../src/messages';
import { mockLogger } from './mock-logger';
describe('AuditBaseCommand class', () => {
class AuditCMD extends AuditBaseCommand {
async run() {
console.warn('WARN: Reports ready. Please find the reports at');
await this.init();
await this.start('cm:stacks:audit');
}
}
class AuditFixCMD extends AuditBaseCommand {
async run() {
await this.init();
await this.start('cm:stacks:audit:fix');
}
}
const fsTransport = class FsTransport {
filename!: string;
} as FileTransportInstance;
const createMockWinstonLogger = () => ({
log: (message: string) => process.stdout.write(message + '\n'),
error: (message: string) => process.stdout.write(`ERROR: ${message}\n`),
info: (message: string) => process.stdout.write(`INFO: ${message}\n`),
warn: (message: string) => process.stdout.write(`WARN: ${message}\n`),
debug: (message: string) => process.stdout.write(`DEBUG: ${message}\n`),
level: 'info'
});
let consoleWarnSpy: sinon.SinonSpy;
let consoleInfoSpy: sinon.SinonSpy;
beforeEach(() => {
consoleWarnSpy = sinon.spy(console, 'warn');
consoleInfoSpy = sinon.spy(console, 'info');
// Mock the logger for all tests
sinon.stub(require('@contentstack/cli-utilities'), 'log').value(mockLogger);
});
afterEach(() => {
consoleWarnSpy.restore();
consoleInfoSpy.restore();
sinon.restore(); // Restore all stubs and mocks
});
describe('Audit command flow', () => {
fancy
.stdout({ print: process.env.PRINT === 'true' || false })
.stub(winston.transports, 'File', () => fsTransport)
.stub(winston, 'createLogger', createMockWinstonLogger)
.stub(fs, 'mkdirSync', () => {})
.stub(fs, 'writeFileSync', () => {})
.stub(cliux, 'table', () => {})
.stub(ux.action, 'stop', () => {})
.stub(ux.action, 'start', () => {})
.stub(Entries.prototype, 'run', () => ({ entry_1: {} }))
.stub(ContentType.prototype, 'run', () => ({ ct_1: {} }))
.stub(GlobalField.prototype, 'run', () => ({ gf_1: {} }))
.stub(Extensions.prototype, 'run', () => ({ ext_1: {} }))
.stub(CustomRoles.prototype, 'run', () => ({ ext_1: {} }))
.stub(Assets.prototype, 'run', () => ({ ext_1: {} }))
.stub(FieldRule.prototype, 'run', () => ({ ext_1: {} }))
.stub(AuditBaseCommand.prototype, 'showOutputOnScreenWorkflowsAndExtension', () => {})
.stub(fs, 'createWriteStream', () => new PassThrough())
.it('should show audit report path', async () => {
await AuditCMD.run(['--data-dir', resolve(__dirname, 'mock', 'contents')]);
const warnOutput = consoleWarnSpy
.getCalls()
.map((call) => call.args[0])
.join('');
expect(warnOutput).to.includes('WARN: Reports ready. Please find the reports at');
});
fancy
.stdout({ print: process.env.PRINT === 'true' || false })
.stub(winston.transports, 'File', () => fsTransport)
.stub(winston, 'createLogger', createMockWinstonLogger)
.stub(fs, 'mkdirSync', () => {})
.stub(fs, 'writeFileSync', () => {})
.stub(ux, 'table', () => {})
.stub(ux.action, 'stop', () => {})
.stub(ux.action, 'start', () => {})
.stub(cliux, 'inquire', () => resolve(__dirname, 'mock', 'contents'))
.stub(AuditBaseCommand.prototype, 'scanAndFix', () => {
console.log('scanAndFix called, returning empty object');
return {
missingCtRefs: {},
missingGfRefs: {},
missingEntryRefs: {},
missingCtRefsInExtensions: {},
missingCtRefsInWorkflow: {},
missingSelectFeild: {},
missingMandatoryFields: {},
missingTitleFields: {},
missingRefInCustomRoles: {},
missingEnvLocalesInAssets: {},
missingEnvLocalesInEntries: {},
missingFieldRules: {},
missingMultipleFields: {}
};
})
.stub(Entries.prototype, 'run', () => ({ entry_1: {} }))
.stub(ContentType.prototype, 'run', () => ({ ct_1: {} }))
.stub(GlobalField.prototype, 'run', () => ({ gf_1: {} }))
.stub(Workflows.prototype, 'run', () => ({ wf_1: {} }))
.stub(Extensions.prototype, 'run', () => ({ ext_1: {} }))
.stub(CustomRoles.prototype, 'run', () => ({ ext_1: {} }))
.stub(Assets.prototype, 'run', () => ({ ext_1: {} }))
.stub(FieldRule.prototype, 'run', () => ({ ext_1: {} }))
.stub(fs, 'createWriteStream', () => new PassThrough())
.it('should print info of no ref found', async (ctx) => {
await AuditCMD.run([]);
expect(ctx.stdout).to.includes('INFO: No missing references found.');
});
});
describe('Audit fix command flow', () => {
fancy
.stdout({ print: process.env.PRINT === 'true' || false })
.stub(winston.transports, 'File', () => fsTransport)
.stub(winston, 'createLogger', createMockWinstonLogger)
.stub(fs, 'mkdirSync', () => {})
.stub(fs, 'writeFileSync', () => {})
.stub(AuditBaseCommand.prototype, 'showOutputOnScreenWorkflowsAndExtension', () => {})
.stub(ux, 'table', (...args: any) => {
args[1].missingRefs.get({ missingRefs: ['gf_0'] });
})
.stub(AuditBaseCommand.prototype, 'showOutputOnScreenWorkflowsAndExtension', () => {})
.stub(ux.action, 'stop', () => {})
.stub(ux.action, 'start', () => {})
.stub(AuditBaseCommand.prototype, 'scanAndFix', () => ({
missingCtRefs: { ct_1: {} },
missingGfRefs: { gf_1: {} },
missingEntryRefs: {
entry_1: {
name: 'T1',
display_name: 'T1',
data_type: 'reference',
missingRefs: ['gf_0'],
treeStr: 'T1 -> gf_0',
},
},
missingCtRefsInExtensions: {},
missingCtRefsInWorkflow: {},
missingSelectFeild: {},
missingMandatoryFields: {},
missingTitleFields: {},
missingRefInCustomRoles: {},
missingEnvLocalesInAssets: {},
missingEnvLocalesInEntries: {},
missingFieldRules: {},
missingMultipleFields: {}
}))
.stub(fs, 'createBackUp', () => {})
.stub(fs, 'createWriteStream', () => new PassThrough())
.stub(AuditBaseCommand.prototype, 'createBackUp', () => {})
.it('should print missing ref and fix status on table formate', async (ctx) => {
await AuditFixCMD.run(['--data-dir', resolve(__dirname, 'mock', 'contents')]);
expect(ctx.stdout).to.includes('WARN: You can locate the fixed content at');
});
fancy
.stdout({ print: process.env.PRINT === 'true' || false })
.stub(winston.transports, 'File', () => fsTransport)
.stub(winston, 'createLogger', createMockWinstonLogger)
.it('return the status column object ', async () => {
class FixCMD extends AuditBaseCommand {
async run() {
return this.fixStatus;
}
}
const res = await FixCMD.run(['--data-dir', resolve(__dirname, 'mock', 'contents')]);
expect(res.fixStatus).ownProperty('header');
expect(res.fixStatus.header).to.be.include('Fix Status');
expect(res.fixStatus.get({ fixStatus: 'Fixed' })).to.be.include('Fixed');
expect(res.fixStatus.get({ fixStatus: 'Not Fixed' })).to.be.include('Not Fixed');
});
});
describe('createBackUp method', () => {
fancy
.stdout({ print: process.env.PRINT === 'true' || false })
.stub(winston.transports, 'File', () => fsTransport)
.stub(winston, 'createLogger', createMockWinstonLogger)
.stub(AuditBaseCommand.prototype, 'promptQueue', async () => {})
.stub(AuditBaseCommand.prototype, 'scanAndFix', async () => ({}))
.stub(AuditBaseCommand.prototype, 'showOutputOnScreen', () => {})
.stub(fs, 'mkdirSync', () => {})
.stub(require('fs-extra'), 'copy', () => {})
.it('should create backup dir', async () => {
class CMD extends AuditBaseCommand {
async run() {
this.sharedConfig.flags.modules = [];
const mockPath = resolve(__dirname, 'mock', 'contents');
this.flags['copy-dir'] = true;
this.flags['data-dir'] = mockPath;
this.flags['report-path'] = mockPath;
this.sharedConfig.basePath = mockPath;
this.sharedConfig.reportPath = mockPath;
await this.start('cm:stacks:audit:fix');
return this.sharedConfig.basePath;
}
}
expect(await CMD.run([])).to.includes('test/unit/mock');
});
fancy
.stdout({ print: process.env.PRINT === 'true' || false })
.stub(winston.transports, 'File', () => fsTransport)
.stub(winston, 'createLogger', createMockWinstonLogger)
.stub(AuditBaseCommand.prototype, 'promptQueue', async () => {})
.stub(AuditBaseCommand.prototype, 'scanAndFix', async () => ({}))
.stub(AuditBaseCommand.prototype, 'showOutputOnScreen', () => {})
.stub(fs, 'mkdirSync', () => {})
.stub(require('fs-extra'), 'copy', () => {})
.it('should throw error if not valid path provided to create backup dir', async () => {
class CMD extends AuditBaseCommand {
async run() {
this.sharedConfig.flags.modules = [];
const mockPath = resolve(__dirname, 'mock', 'contents');
this.flags['copy-dir'] = true;
this.flags['data-dir'] = mockPath;
this.flags['report-path'] = mockPath;
this.sharedConfig.basePath = resolve(__dirname, 'mock', 'contents-1');
this.sharedConfig.reportPath = mockPath;
await this.start('cm:stacks:audit:fix');
return this.sharedConfig.basePath;
}
}
try {
await CMD.run([]);
} catch (error: any) {
expect(error.message).to.include(
$t(auditMsg.NOT_VALID_PATH, { path: resolve(__dirname, 'mock', 'contents-1') }),
);
}
});
});
describe('prepareCSV method', () => {
fancy
.stdout({ print: process.env.PRINT === 'true' || false })
.stub(winston.transports, 'File', () => fsTransport)
.stub(winston, 'createLogger', createMockWinstonLogger)
.stub(fs, 'createWriteStream', () => new PassThrough())
.it('should print missing ref and fix status on table formate', async () => {
class CMD extends AuditBaseCommand {
async run() {
this.sharedConfig.reportPath = resolve(__dirname, 'mock', 'contents');
return this.prepareCSV('content-types', {
t1: {
name: 'T1',
display_name: 'T1',
data_type: 'reference',
missingRefs: ['gf_0'],
treeStr: 'T1 -> gf_0',
},
t2: {
name: 'T2',
display_name: 'T2',
data_type: 'reference',
missingRefs: ['gf_0'],
treeStr: 'T2 -> gf_0',
},
});
}
}
expect(await CMD.run([])).to.be.undefined;
});
fancy
.stdout({ print: process.env.PRINT === 'true' || false })
.stub(winston.transports, 'File', () => fsTransport)
.stub(winston, 'createLogger', createMockWinstonLogger)
.stub(fs, 'createWriteStream', () => new PassThrough())
.it('should apply filter on output', async () => {
class CMD extends AuditBaseCommand {
async run() {
this.sharedConfig.reportPath = resolve(__dirname, 'mock', 'contents');
this.sharedConfig.flags.columns = 'Path';
this.sharedConfig.flags.filter = 'Title=T1';
return this.prepareCSV('content-types', {
t1: {
name: 'T1',
display_name: 'T1',
data_type: 'reference',
missingRefs: ['gf_0'],
treeStr: 'T1 -> gf_0',
},
t2: {
name: 'T2',
display_name: 'T2',
data_type: 'reference',
missingRefs: ['gf_0'],
treeStr: 'T2 -> gf_0',
},
});
}
}
expect(await CMD.run([])).to.be.undefined;
});
fancy
.stdout({ print: process.env.PRINT === 'true' || false })
.stub(winston.transports, 'File', () => fsTransport)
.stub(winston, 'createLogger', createMockWinstonLogger)
.it('should fail with error', async () => {
class CMD extends AuditBaseCommand {
async run() {
this.sharedConfig.reportPath = resolve(__dirname, 'mock', 'contents-1');
this.sharedConfig.flags.columns = 'Path';
this.sharedConfig.flags.filter = 'Title=T1';
return this.prepareCSV('content-types', { t1: {}, t2: {} });
}
}
try {
await CMD.run([]);
} catch (error: any) {
expect(error.message).to.be.include(
`ENOENT: no such file or directory, open '${resolve(__dirname, 'mock', 'contents-1')}/content-types.csv'`,
);
}
});
});
describe('getCtAndGfSchema method', () => {
fancy
.stdout({ print: process.env.PRINT === 'true' || false })
.stub(winston.transports, 'File', () => fsTransport)
.stub(winston, 'createLogger', createMockWinstonLogger)
.stub(fs, 'createWriteStream', () => new PassThrough())
.it('should log error and return empty array', async () => {
class CMD extends AuditBaseCommand {
async run() {
this.sharedConfig.reportPath = resolve(__dirname, 'mock', 'contents-1');
return this.getCtAndGfSchema();
}
}
expect(await CMD.run([])).to.be.deep.include({
ctSchema: [],
gfSchema: [],
});
});
});
describe('Progress Manager Integration', () => {
let configHandlerStub: sinon.SinonStub;
let initializeGlobalSummarySpy: sinon.SinonSpy;
let printGlobalSummarySpy: sinon.SinonSpy;
beforeEach(() => {
// Mock CLIProgressManager static methods
initializeGlobalSummarySpy = sinon.spy(CLIProgressManager, 'initializeGlobalSummary');
printGlobalSummarySpy = sinon.spy(CLIProgressManager, 'printGlobalSummary');
// Mock configHandler
configHandlerStub = sinon.stub(configHandler, 'get').returns({});
sinon.stub(configHandler, 'set');
});
afterEach(() => {
try {
if (initializeGlobalSummarySpy && typeof initializeGlobalSummarySpy.restore === 'function') {
initializeGlobalSummarySpy.restore();
}
} catch (e) {
// Ignore
}
try {
if (printGlobalSummarySpy && typeof printGlobalSummarySpy.restore === 'function') {
printGlobalSummarySpy.restore();
}
} catch (e) {
// Ignore
}
try {
if (configHandlerStub && typeof configHandlerStub.restore === 'function') {
configHandlerStub.restore();
}
} catch (e) {
// Ignore
}
try {
CLIProgressManager.clearGlobalSummary();
clearProgressModuleSetting();
} catch (e) {
// Ignore
}
try {
sinon.restore();
} catch (e) {
// Ignore
}
});
fancy
.stdout({ print: process.env.PRINT === 'true' || false })
.stub(winston.transports, 'File', () => fsTransport)
.stub(winston, 'createLogger', createMockWinstonLogger)
.stub(fs, 'mkdirSync', () => {})
.stub(fs, 'writeFileSync', () => {})
.stub(cliux, 'table', () => {})
.stub(ux.action, 'stop', () => {})
.stub(ux.action, 'start', () => {})
.stub(cliux, 'inquire', () => resolve(__dirname, 'mock', 'contents'))
.stub(AuditBaseCommand.prototype, 'scanAndFix', () => ({
missingCtRefs: {},
missingGfRefs: {},
missingEntryRefs: {},
missingCtRefsInExtensions: {},
missingCtRefsInWorkflow: {},
missingSelectFeild: {},
missingMandatoryFields: {},
missingTitleFields: {},
missingRefInCustomRoles: {},
missingEnvLocalesInAssets: {},
missingEnvLocalesInEntries: {},
missingFieldRules: {},
missingMultipleFields: {},
}))
.stub(AuditBaseCommand.prototype, 'showOutputOnScreenWorkflowsAndExtension', () => {})
.stub(fs, 'createWriteStream', () => new PassThrough())
.it('should initialize global summary when start is called', async () => {
await AuditCMD.run(['--data-dir', resolve(__dirname, 'mock', 'contents')]);
expect(initializeGlobalSummarySpy.calledOnce).to.be.true;
expect(initializeGlobalSummarySpy.calledWith('AUDIT', '', 'Auditing content...')).to.be.true;
});
fancy
.stdout({ print: process.env.PRINT === 'true' || false })
.stub(winston.transports, 'File', () => fsTransport)
.stub(winston, 'createLogger', createMockWinstonLogger)
.stub(fs, 'mkdirSync', () => {})
.stub(fs, 'writeFileSync', () => {})
.stub(cliux, 'table', () => {})
.stub(ux.action, 'stop', () => {})
.stub(ux.action, 'start', () => {})
.stub(cliux, 'inquire', () => resolve(__dirname, 'mock', 'contents'))
.stub(AuditBaseCommand.prototype, 'scanAndFix', () => ({
missingCtRefs: {},
missingGfRefs: {},
missingEntryRefs: {},
missingCtRefsInExtensions: {},
missingCtRefsInWorkflow: {},
missingSelectFeild: {},
missingMandatoryFields: {},
missingTitleFields: {},
missingRefInCustomRoles: {},
missingEnvLocalesInAssets: {},
missingEnvLocalesInEntries: {},
missingFieldRules: {},
missingMultipleFields: {},
}))
.stub(AuditBaseCommand.prototype, 'showOutputOnScreenWorkflowsAndExtension', () => {})
.stub(fs, 'createWriteStream', () => new PassThrough())
.it('should complete without printing global summary (summary display commented out)', async () => {
await AuditCMD.run(['--data-dir', resolve(__dirname, 'mock', 'contents')]);
expect(printGlobalSummarySpy.called).to.be.false;
});
});
describe('Spinner Message Conditional Display', () => {
let printSpy: sinon.SinonSpy | undefined;
let configHandlerGetStub: sinon.SinonStub | undefined;
beforeEach(() => {
// Clear any existing global summary
CLIProgressManager.clearGlobalSummary();
// Import print function from the correct path
const logModule = require('../../src/util/log');
printSpy = sinon.spy(logModule, 'print');
configHandlerGetStub = sinon.stub(configHandler, 'get');
});
afterEach(() => {
try {
// Clear global summary first
CLIProgressManager.clearGlobalSummary();
} catch (e) {
// Ignore errors
}
try {
if (printSpy) {
printSpy.restore();
}
} catch (e) {
// Ignore errors
}
try {
if (configHandlerGetStub) {
configHandlerGetStub.restore();
}
} catch (e) {
// Ignore errors
}
try {
// Restore all sinon stubs
sinon.restore();
} catch (e) {
// Ignore errors
}
});
fancy
.stdout({ print: process.env.PRINT === 'true' || false })
.stub(winston.transports, 'File', () => fsTransport)
.stub(winston, 'createLogger', createMockWinstonLogger)
.stub(fs, 'mkdirSync', () => {})
.stub(fs, 'writeFileSync', () => {})
.stub(cliux, 'table', () => {})
.stub(ux.action, 'stop', () => {})
.stub(ux.action, 'start', () => {})
.stub(cliux, 'inquire', () => resolve(__dirname, 'mock', 'contents'))
.stub(Entries.prototype, 'run', () => ({ entry_1: {} }))
.stub(ContentType.prototype, 'run', () => ({ ct_1: {} }))
.stub(GlobalField.prototype, 'run', () => ({ gf_1: {} }))
.stub(Extensions.prototype, 'run', () => ({ ext_1: {} }))
.stub(Workflows.prototype, 'run', () => ({ wf_1: {} }))
.stub(CustomRoles.prototype, 'run', () => ({ cr_1: {} }))
.stub(Assets.prototype, 'run', () => ({ assets_1: {} }))
.stub(FieldRule.prototype, 'run', () => ({ fr_1: {} }))
.stub(AuditBaseCommand.prototype, 'showOutputOnScreenWorkflowsAndExtension', () => {})
.stub(fs, 'createWriteStream', () => new PassThrough())
.it('should hide spinner messages when showConsoleLogs is false', async function() {
this.timeout(5000); // Set timeout to 5 seconds
if (!configHandlerGetStub || !printSpy) {
throw new Error('Spies not initialized');
}
configHandlerGetStub.returns({ showConsoleLogs: false });
await AuditCMD.run(['--data-dir', resolve(__dirname, 'mock', 'contents')]);
// Print should not be called for spinner messages when showConsoleLogs is false
const printCalls = printSpy.getCalls();
const spinnerCalls = printCalls.filter((call: any) =>
call.args[0]?.[0]?.message?.includes('scanning')
);
expect(spinnerCalls.length).to.equal(0);
});
fancy
.stdout({ print: process.env.PRINT === 'true' || false })
.stub(winston.transports, 'File', () => fsTransport)
.stub(winston, 'createLogger', createMockWinstonLogger)
.stub(fs, 'mkdirSync', () => {})
.stub(fs, 'writeFileSync', () => {})
.stub(cliux, 'table', () => {})
.stub(ux.action, 'stop', () => {})
.stub(ux.action, 'start', () => {})
.stub(cliux, 'inquire', () => resolve(__dirname, 'mock', 'contents'))
.stub(Entries.prototype, 'run', () => ({ entry_1: {} }))
.stub(ContentType.prototype, 'run', () => ({ ct_1: {} }))
.stub(GlobalField.prototype, 'run', () => ({ gf_1: {} }))
.stub(Extensions.prototype, 'run', () => ({ ext_1: {} }))
.stub(Workflows.prototype, 'run', () => ({ wf_1: {} }))
.stub(CustomRoles.prototype, 'run', () => ({ cr_1: {} }))
.stub(Assets.prototype, 'run', () => ({ assets_1: {} }))
.stub(FieldRule.prototype, 'run', () => ({ fr_1: {} }))
.stub(AuditBaseCommand.prototype, 'showOutputOnScreenWorkflowsAndExtension', () => {})
.stub(fs, 'createWriteStream', () => new PassThrough())
.it('should show spinner messages when showConsoleLogs is true', async function() {
this.timeout(5000); // Set timeout to 5 seconds
if (!configHandlerGetStub || !printSpy) {
throw new Error('Spies not initialized');
}
configHandlerGetStub.returns({ showConsoleLogs: true });
await AuditCMD.run(['--data-dir', resolve(__dirname, 'mock', 'contents')]);
// Print should be called for spinner messages when showConsoleLogs is true
const printCalls = printSpy.getCalls();
const spinnerCalls = printCalls.filter((call: any) =>
call.args[0]?.[0]?.message?.includes('scanning')
);
expect(spinnerCalls.length).to.be.greaterThan(0);
});
});
});