Skip to content

Commit 5345b14

Browse files
committed
Fixed global field prompt when empty global fields
1 parent 66db3e1 commit 5345b14

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,11 @@ export default class ContentType extends BaseClass {
222222
let canWrite = true;
223223

224224
if (!this.inMemoryFix && this.fix) {
225+
if (Array.isArray(this.schema) && this.schema.length === 0) {
226+
log.debug('No schemas to write, skipping writeFixContent', this.config.auditContext);
227+
return;
228+
}
229+
225230
log.debug('Fix mode enabled, checking write permissions', this.config.auditContext);
226231
if (!this.config.flags['copy-dir'] && !this.config.flags['external-config']?.skipConfirm) {
227232
log.debug('Asking user for confirmation to write fix content', this.config.auditContext);

packages/contentstack-audit/test/unit/modules/content-types.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,24 @@ describe('Content types', () => {
164164
.it('should prompt and ask confirmation', async () => {
165165
sinon.replace(cliux, 'confirm', async () => false);
166166
const ctInstance = new ContentType({ ...constructorParam, fix: true });
167+
(ctInstance as any).schema = constructorParam.ctSchema?.length ? [constructorParam.ctSchema[0]] : [{ uid: 'ct1', title: 'T' } as ContentTypeStruct];
167168
const spy = sinon.spy(cliux, 'confirm');
168169
await ctInstance.writeFixContent();
169170
expect(spy.callCount).to.be.equals(1);
170171
});
172+
173+
fancy
174+
.stdout({ print: process.env.PRINT === 'true' || false })
175+
.stub(fs, 'writeFileSync', () => {})
176+
.it('should not prompt or write when schema is empty in fix mode', async () => {
177+
const ctInstance = new ContentType({ ...constructorParam, fix: true });
178+
(ctInstance as any).schema = [];
179+
const confirmSpy = sinon.spy(cliux, 'confirm');
180+
const fsSpy = sinon.spy(fs, 'writeFileSync');
181+
await ctInstance.writeFixContent();
182+
expect(confirmSpy.callCount).to.be.equals(0);
183+
expect(fsSpy.callCount).to.be.equals(0);
184+
});
171185
});
172186

173187
describe('lookForReference method', () => {

0 commit comments

Comments
 (0)