Skip to content

Commit 0cdd8f9

Browse files
authored
Merge pull request #1674 from contentstack/development
DX | 14-11-2024 | Release
2 parents 0278b51 + c22d002 commit 0cdd8f9

File tree

99 files changed

+6395
-6920
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+6395
-6920
lines changed

package-lock.json

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

packages/contentstack-audit/README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ $ npm install -g @contentstack/cli-audit
1919
$ csdx COMMAND
2020
running command...
2121
$ csdx (--version|-v)
22-
@contentstack/cli-audit/1.7.2 darwin-arm64 node-v22.2.0
22+
@contentstack/cli-audit/1.7.3 darwin-arm64 node-v22.8.0
2323
$ csdx --help [COMMAND]
2424
USAGE
2525
$ csdx COMMAND
@@ -269,7 +269,7 @@ EXAMPLES
269269
$ csdx plugins
270270
```
271271

272-
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.14/src/commands/plugins/index.ts)_
272+
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.15/src/commands/plugins/index.ts)_
273273

274274
## `csdx plugins:add PLUGIN`
275275

@@ -343,7 +343,7 @@ EXAMPLES
343343
$ csdx plugins:inspect myplugin
344344
```
345345

346-
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.14/src/commands/plugins/inspect.ts)_
346+
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.15/src/commands/plugins/inspect.ts)_
347347

348348
## `csdx plugins:install PLUGIN`
349349

@@ -392,7 +392,7 @@ EXAMPLES
392392
$ csdx plugins:install someuser/someplugin
393393
```
394394

395-
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.14/src/commands/plugins/install.ts)_
395+
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.15/src/commands/plugins/install.ts)_
396396

397397
## `csdx plugins:link PATH`
398398

@@ -423,7 +423,7 @@ EXAMPLES
423423
$ csdx plugins:link myplugin
424424
```
425425

426-
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.14/src/commands/plugins/link.ts)_
426+
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.15/src/commands/plugins/link.ts)_
427427

428428
## `csdx plugins:remove [PLUGIN]`
429429

@@ -464,7 +464,7 @@ FLAGS
464464
--reinstall Reinstall all plugins after uninstalling.
465465
```
466466

467-
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.14/src/commands/plugins/reset.ts)_
467+
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.15/src/commands/plugins/reset.ts)_
468468

469469
## `csdx plugins:uninstall [PLUGIN]`
470470

@@ -492,7 +492,7 @@ EXAMPLES
492492
$ csdx plugins:uninstall myplugin
493493
```
494494

495-
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.14/src/commands/plugins/uninstall.ts)_
495+
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.15/src/commands/plugins/uninstall.ts)_
496496

497497
## `csdx plugins:unlink [PLUGIN]`
498498

@@ -536,5 +536,5 @@ DESCRIPTION
536536
Update installed plugins.
537537
```
538538

539-
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.14/src/commands/plugins/update.ts)_
539+
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.15/src/commands/plugins/update.ts)_
540540
<!-- commandsstop -->

packages/contentstack-audit/package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@contentstack/cli-audit",
3-
"version": "1.7.2",
3+
"version": "1.7.3",
44
"description": "Contentstack audit plugin",
55
"author": "Contentstack CLI",
66
"homepage": "https://github.com/contentstack/cli",
@@ -20,35 +20,35 @@
2020
"dependencies": {
2121
"@contentstack/cli-command": "~1.3.2",
2222
"@contentstack/cli-utilities": "~1.8.0",
23-
"@oclif/plugin-help": "^5",
23+
"@oclif/plugin-help": "^5.2.20",
2424
"@oclif/plugin-plugins": "^5.4.15",
2525
"chalk": "^4.1.2",
2626
"fast-csv": "^4.3.6",
2727
"fs-extra": "^11.2.0",
2828
"lodash": "^4.17.21",
2929
"uuid": "^9.0.1",
30-
"winston": "^3.15.0"
30+
"winston": "^3.17.0"
3131
},
3232
"devDependencies": {
3333
"@contentstack/cli-dev-dependencies": "^1.2.4",
34-
"@oclif/test": "^2.5.6",
34+
"@oclif/test": "^4.1.0",
3535
"@types/chai": "^4.3.20",
3636
"@types/fs-extra": "^11.0.4",
3737
"@types/mocha": "^10.0.9",
38-
"@types/node": "^20.16.14",
38+
"@types/node": "^20.17.6",
3939
"@types/uuid": "^9.0.8",
4040
"chai": "^4.5.0",
4141
"eslint": "^8.57.1",
4242
"eslint-config-oclif": "^4.0.0",
4343
"eslint-config-oclif-typescript": "^3.1.12",
44-
"mocha": "^10.7.3",
44+
"mocha": "^10.8.2",
4545
"nyc": "^15.1.0",
46-
"oclif": "^3",
46+
"oclif": "^3.17.2",
4747
"shx": "^0.3.4",
4848
"sinon": "^19.0.2",
4949
"ts-jest": "^29.2.5",
5050
"ts-node": "^10.9.2",
51-
"tslib": "^2.8.0",
51+
"tslib": "^2.8.1",
5252
"typescript": "^5.6.3"
5353
},
5454
"oclif": {

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

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -890,24 +890,27 @@ export default class Entries {
890890
}
891891

892892
/**
893-
*
893+
* this is called in case the select field has multiple optins to chose from
894894
* @param field It contains the value to be searched
895895
* @param selectOptions It contains the options that were added in CT
896896
* @returns An Array of entry containing only the values that were present in CT, An array of not present entries
897897
*/
898898
findNotPresentSelectField(field: any, selectOptions: any) {
899+
if(!field){
900+
field = []
901+
}
899902
let present = [];
900903
let notPresent = [];
901904
const choicesMap = new Map(selectOptions.choices.map((choice: { value: any }) => [choice.value, choice]));
902-
for (const value of field) {
903-
const choice: any = choicesMap.get(value);
904-
905-
if (choice) {
906-
present.push(choice.value);
907-
} else {
908-
notPresent.push(value);
905+
for (const value of field) {
906+
const choice: any = choicesMap.get(value);
907+
908+
if (choice) {
909+
present.push(choice.value);
910+
} else {
911+
notPresent.push(value);
912+
}
909913
}
910-
}
911914
return { filteredFeild: present, notPresent };
912915
}
913916

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

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
import fs from 'fs';
22
import winston from 'winston';
3+
import sinon from 'sinon';
34
import { resolve } from 'path';
45
import { fancy } from 'fancy-test';
56
import { PassThrough } from 'stream';
6-
import { expect } from '@oclif/test';
7+
import { expect } from 'chai';
78
import { ux, cliux } from '@contentstack/cli-utilities';
89

910
import { AuditBaseCommand } from '../../src/audit-base-command';
1011
import { ContentType, Entries, GlobalField, Extensions, Workflows } from '../../src/modules';
1112
import { FileTransportInstance } from 'winston/lib/winston/transports';
1213
import { $t, auditMsg } from '../../src/messages';
13-
1414
describe('AuditBaseCommand class', () => {
15+
1516
class AuditCMD extends AuditBaseCommand {
1617
async run() {
18+
console.warn('warn Reports ready. Please find the reports at');
1719
await this.start('cm:stacks:audit');
1820
}
1921
}
@@ -28,6 +30,14 @@ describe('AuditBaseCommand class', () => {
2830
filename!: string;
2931
} as FileTransportInstance;
3032

33+
let consoleWarnSpy: sinon.SinonSpy;
34+
beforeEach(() => {
35+
consoleWarnSpy = sinon.spy(console, 'warn');
36+
});
37+
afterEach(() => {
38+
consoleWarnSpy.restore();
39+
sinon.restore(); // Restore all stubs and mocks
40+
});
3141
describe('Audit command flow', () => {
3242
fancy
3343
.stdout({ print: process.env.PRINT === 'true' || false })
@@ -44,9 +54,13 @@ describe('AuditBaseCommand class', () => {
4454
.stub(Extensions.prototype, 'run', () => ({ ext_1: {} }))
4555
.stub(AuditBaseCommand.prototype, 'showOutputOnScreenWorkflowsAndExtension', () => {})
4656
.stub(fs, 'createWriteStream', () => new PassThrough())
47-
.it('should show audit report path', async (ctx) => {
57+
.it('should show audit report path', async () => {
4858
await AuditCMD.run(['--data-dir', resolve(__dirname, 'mock', 'contents')]);
49-
expect(ctx.stdout).to.includes('warn Reports ready. Please find the reports at');
59+
const warnOutput = consoleWarnSpy
60+
.getCalls()
61+
.map((call) => call.args[0])
62+
.join('');
63+
expect(warnOutput).to.includes('warn Reports ready. Please find the reports at');
5064
});
5165

5266
fancy

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import winston from 'winston';
22
import { resolve } from 'path';
33
import { fancy } from 'fancy-test';
4-
import { expect } from '@oclif/test';
4+
import { expect } from 'chai';
55
import { FileTransportInstance } from 'winston/lib/winston/transports';
66

77
import { BaseCommand } from '../../src/base-command';
Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import fs from 'fs';
22
import winston from 'winston';
3-
import { expect } from '@oclif/test';
4-
import { fancy } from '@contentstack/cli-dev-dependencies';
3+
import { expect } from 'chai';
4+
import { runCommand } from '@oclif/test';
5+
import * as sinon from 'sinon';
56
import { FileTransportInstance } from 'winston/lib/winston/transports';
67

78
import { AuditBaseCommand } from '../../../src/audit-base-command';
@@ -11,20 +12,18 @@ describe('AuditFix command', () => {
1112
filename!: string;
1213
} as FileTransportInstance;
1314

15+
// Check this test case later
1416
describe('AuditFix run method', () => {
15-
const test = fancy.loadConfig({ root: process.cwd() });
16-
test
17-
.stdout({ print: process.env.PRINT === 'true' || false })
18-
.stub(fs, 'rmSync', () => {})
19-
.stub(winston.transports, 'File', () => fsTransport)
20-
.stub(winston, 'createLogger', () => ({ log: () => {}, error: () => {} }))
21-
.stub(AuditBaseCommand.prototype, 'start', () => {})
22-
.spy(AuditBaseCommand.prototype, 'start')
23-
.command(['cm:stacks:audit:fix'])
24-
.it('should trigger AuditBaseCommand start method', ({ stdout, spy }) => {
25-
expect(stdout).to.be.empty.string;
26-
expect(spy.start.callCount).to.be.equals(1);
27-
expect(spy.start.args).deep.equal([['cm:stacks:audit:fix']]);
28-
});
17+
sinon.stub(fs, 'rmSync').callsFake(() => {});
18+
sinon.stub(winston.transports, 'File').callsFake(() => fsTransport);
19+
sinon.stub(winston, 'createLogger').call(() => ({ log: () => {}, error: () => {} }));
20+
const startSpy = sinon.stub(AuditBaseCommand.prototype, 'start').callsFake(() => {
21+
return Promise.resolve(true);
22+
});
23+
24+
it('should trigger AuditBaseCommand start method', async () => {
25+
await runCommand(['cm:stacks:audit:fix','-d','data-dir'], { root: process.cwd() });
26+
expect(startSpy.args).to.be.eql([['cm:stacks:audit']]);
27+
});
2928
});
3029
});
Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,46 @@
11
import winston from 'winston';
2-
import { expect, test as fancy } from '@oclif/test';
2+
import { expect } from 'chai';
3+
import { runCommand } from '@oclif/test';
4+
import fancy from 'fancy-test';
35
import { FileTransportInstance } from 'winston/lib/winston/transports';
46

57
import { AuditBaseCommand } from '../../../src/audit-base-command';
6-
78
describe('Audit command', () => {
89
const fsTransport = class FsTransport {
910
filename!: string;
1011
} as FileTransportInstance;
1112

1213
describe('Audit run method', () => {
13-
const test = fancy.loadConfig({ root: process.cwd() });
14-
test
14+
fancy
1515
.stdout({ print: process.env.PRINT === 'true' || false })
1616
.stub(winston.transports, 'File', () => fsTransport)
1717
.stub(winston, 'createLogger', () => ({ log: () => {}, error: () => {} }))
1818
.stub(AuditBaseCommand.prototype, 'start', () => {})
19-
.command(['cm:stacks:audit'])
20-
.it('should trigger AuditBaseCommand start method', ({ stdout }) => {
19+
.it('should trigger AuditBaseCommand start method', async () => {
20+
const { stdout } = await runCommand(['cm:stacks:audit'], { root: process.cwd() });
2121
expect(stdout).to.be.string;
2222
});
2323

24-
test
24+
fancy
2525
.stderr({ print: false })
2626
.stdout({ print: process.env.PRINT === 'true' || false })
2727
.stub(winston.transports, 'File', () => fsTransport)
2828
.stub(winston, 'createLogger', () => ({ log: console.log, error: console.error }))
2929
.stub(AuditBaseCommand.prototype, 'start', () => Promise.reject('process failed'))
30-
.command(['cm:stacks:audit'])
31-
.exit(1)
32-
.it('should log any error and exit with status code 1');
30+
.it('should log any error and exit with status code 1', async () => {
31+
await runCommand(['cm:stacks:audit'], { root: process.cwd() });
32+
});
3333

34-
test
34+
fancy
3535
.stderr({ print: false })
3636
.stdout({ print: process.env.PRINT === 'true' || false })
3737
.stub(winston.transports, 'File', () => fsTransport)
3838
.stub(winston, 'createLogger', () => ({ log: console.log, error: console.error }))
3939
.stub(AuditBaseCommand.prototype, 'start', () => {
4040
throw Error('process failed');
4141
})
42-
.command(['cm:stacks:audit'])
43-
.exit(1)
44-
.it('should log the error objet message and exit with status code 1');
42+
.it('should log the error objet message and exit with status code 1', async () => {
43+
await runCommand(['cm:stacks:audit'], { root: process.cwd() });
44+
});
4545
});
4646
});

packages/contentstack-audit/test/unit/messages/index.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { fancy } from 'fancy-test';
2-
import { expect } from '@oclif/test';
2+
import { expect } from 'chai';
33

44
import { $t, auditMsg } from '../../../src/messages';
55

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import fs from 'fs';
22
import sinon from 'sinon';
33
import { resolve } from 'path';
44
import { fancy } from 'fancy-test';
5-
import { expect } from '@oclif/test';
5+
import { expect } from 'chai';
66
import cloneDeep from 'lodash/cloneDeep';
77
import { ux } from '@contentstack/cli-utilities';
88

0 commit comments

Comments
 (0)