Skip to content

Commit 40d6f4f

Browse files
authored
Merge pull request #19 from contentstack/fix/DX-4902
fix: progress manager / audit summary fixes + Assets module unit tests (90% coverage)
2 parents 72cd33f + 34ae6a4 commit 40d6f4f

11 files changed

Lines changed: 418 additions & 9 deletions

File tree

packages/contentstack-audit/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
*-debug.log
22
*-error.log
33
/.nyc_output
4+
/coverage
45
/dist
56
/lib
67
/package-lock.json
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"extension": [".ts"],
3+
"include": ["src/**/*.ts"],
4+
"exclude": [
5+
"lib/**",
6+
"**/*.test.ts",
7+
"**/*.d.ts",
8+
"node_modules/**",
9+
"test/**"
10+
],
11+
"reporter": ["text"],
12+
"all": true
13+
}

packages/contentstack-audit/src/audit-base-command.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,8 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
174174
}
175175
}
176176

177-
// Print comprehensive summary at the end
178-
CLIProgressManager.printGlobalSummary();
177+
// Print comprehensive summary at the end (commented out - Summary table above has the counts; progress bars show completion)
178+
// CLIProgressManager.printGlobalSummary();
179179

180180
// Clear progress module setting now that audit is complete
181181
clearProgressModuleSetting();

packages/contentstack-audit/src/modules/assets.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,12 +204,14 @@ export default class Assets extends BaseClass {
204204
if (this.assets[assetUid]?.publish_details && !Array.isArray(this.assets[assetUid].publish_details)) {
205205
log.debug(`Asset ${assetUid} has invalid publish_details format`, this.config.auditContext);
206206
cliux.print($t(auditMsg.ASSET_NOT_EXIST, { uid: assetUid }), { color: 'red' });
207+
this.assets[assetUid].publish_details = [];
207208
}
208209

209210
const publishDetails = this.assets[assetUid]?.publish_details;
210211
log.debug(`Asset ${assetUid} has ${publishDetails?.length || 0} publish details`, this.config.auditContext);
211212

212-
this.assets[assetUid].publish_details = this.assets[assetUid]?.publish_details.filter((pd: any) => {
213+
if (Array.isArray(this.assets[assetUid].publish_details)) {
214+
this.assets[assetUid].publish_details = this.assets[assetUid].publish_details.filter((pd: any) => {
213215
log.debug(`Checking publish detail: locale=${pd?.locale}, environment=${pd?.environment}`, this.config.auditContext);
214216

215217
if (this.locales?.includes(pd?.locale) && this.environments?.includes(pd?.environment)) {
@@ -239,6 +241,7 @@ export default class Assets extends BaseClass {
239241
return false;
240242
}
241243
});
244+
}
242245

243246
const remainingPublishDetails = this.assets[assetUid].publish_details?.length || 0;
244247
log.debug(`Asset ${assetUid} now has ${remainingPublishDetails} valid publish details`, this.config.auditContext);

packages/contentstack-audit/src/modules/content-types.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,13 @@ export default class ContentType extends BaseClass {
9191
this.schema = this.moduleName === 'content-types' ? this.ctSchema : this.gfSchema;
9292
log.debug(`Found ${this.schema?.length || 0} ${this.moduleName} schemas to audit`, this.config.auditContext);
9393

94-
// Load prerequisite data with loading spinner
95-
await this.withLoadingSpinner(`${this.moduleName.toUpperCase()}: Loading prerequisite data...`, async () => {
94+
// Load prerequisite data with loading spinner.
95+
// When run as prerequisite (returnFixSchema), use a neutral message so the global
96+
// progress summary is not overwritten with 0 items for this module.
97+
const spinnerMessage = returnFixSchema
98+
? 'Loading schema for entries...'
99+
: `${this.moduleName.toUpperCase()}: Loading prerequisite data...`;
100+
await this.withLoadingSpinner(spinnerMessage, async () => {
96101
await this.prerequisiteData();
97102
});
98103

packages/contentstack-audit/src/modules/field_rules.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ export default class FieldRule extends BaseClass {
119119

120120
// Create progress manager if we have a total count
121121
if (totalCount && totalCount > 0) {
122-
const progress = this.createSimpleProgress(this.moduleName, totalCount);
122+
const progress = this.createSimpleProgress('field-rules', totalCount);
123123
progress.updateStatus('Validating field rules...');
124124
}
125125

@@ -155,6 +155,10 @@ export default class FieldRule extends BaseClass {
155155
$t(auditMsg.SCAN_CT_SUCCESS_MSG, { title, module: this.config.moduleConfig[this.moduleName].name }),
156156
this.config.auditContext,
157157
);
158+
159+
if (this.progressManager) {
160+
this.progressManager.tick(true, `field-rules: ${title}`, null);
161+
}
158162
}
159163

160164
if (this.fix) {

packages/contentstack-audit/test/unit/audit-base-command.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -486,10 +486,10 @@ describe('AuditBaseCommand class', () => {
486486
}))
487487
.stub(AuditBaseCommand.prototype, 'showOutputOnScreenWorkflowsAndExtension', () => {})
488488
.stub(fs, 'createWriteStream', () => new PassThrough())
489-
.it('should print global summary at the end of start method', async () => {
489+
.it('should complete without printing global summary (summary display commented out)', async () => {
490490
await AuditCMD.run(['--data-dir', resolve(__dirname, 'mock', 'contents')]);
491-
492-
expect(printGlobalSummarySpy.calledOnce).to.be.true;
491+
492+
expect(printGlobalSummarySpy.called).to.be.false;
493493
});
494494

495495
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"1": "chunk0-assets.json"}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"asset_uid_1": {
3+
"uid": "asset_uid_1",
4+
"title": "Test Asset",
5+
"publish_details": [
6+
{ "locale": "en-us", "environment": "env1" }
7+
]
8+
},
9+
"asset_uid_invalid": {
10+
"uid": "asset_uid_invalid",
11+
"title": "Invalid Env Locale",
12+
"publish_details": [
13+
{ "locale": "en-us", "environment": "env1" },
14+
{ "locale": "de-de", "environment": "env99" }
15+
]
16+
},
17+
"asset_uid_two_invalid": {
18+
"uid": "asset_uid_two_invalid",
19+
"title": "Two Invalid Pds",
20+
"publish_details": [
21+
{ "locale": "de-de", "environment": "env99" },
22+
{ "locale": "fr-fr", "environment": "env99" }
23+
]
24+
}
25+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"env1": {
3+
"name": "Environment 1",
4+
"uid": "env-uid-1"
5+
},
6+
"env2": {
7+
"name": "Environment 2",
8+
"uid": "env-uid-2"
9+
}
10+
}

0 commit comments

Comments
 (0)