Skip to content

Commit

Permalink
Merge pull request #1676 from contentstack/staging
Browse files Browse the repository at this point in the history
DX | 14-11-2024 | Release
  • Loading branch information
cs-raj authored Nov 14, 2024
2 parents 8d59fa0 + 0cdd8f9 commit 7c78837
Show file tree
Hide file tree
Showing 99 changed files with 6,395 additions and 6,920 deletions.
4,067 changes: 1,379 additions & 2,688 deletions package-lock.json

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions packages/contentstack-audit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ $ npm install -g @contentstack/cli-audit
$ csdx COMMAND
running command...
$ csdx (--version|-v)
@contentstack/cli-audit/1.7.2 darwin-arm64 node-v22.2.0
@contentstack/cli-audit/1.7.3 darwin-arm64 node-v22.8.0
$ csdx --help [COMMAND]
USAGE
$ csdx COMMAND
Expand Down Expand Up @@ -269,7 +269,7 @@ EXAMPLES
$ csdx plugins
```

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

## `csdx plugins:add PLUGIN`

Expand Down Expand Up @@ -343,7 +343,7 @@ EXAMPLES
$ csdx plugins:inspect myplugin
```

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

## `csdx plugins:install PLUGIN`

Expand Down Expand Up @@ -392,7 +392,7 @@ EXAMPLES
$ csdx plugins:install someuser/someplugin
```

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

## `csdx plugins:link PATH`

Expand Down Expand Up @@ -423,7 +423,7 @@ EXAMPLES
$ csdx plugins:link myplugin
```

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

## `csdx plugins:remove [PLUGIN]`

Expand Down Expand Up @@ -464,7 +464,7 @@ FLAGS
--reinstall Reinstall all plugins after uninstalling.
```

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

## `csdx plugins:uninstall [PLUGIN]`

Expand Down Expand Up @@ -492,7 +492,7 @@ EXAMPLES
$ csdx plugins:uninstall myplugin
```

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

## `csdx plugins:unlink [PLUGIN]`

Expand Down Expand Up @@ -536,5 +536,5 @@ DESCRIPTION
Update installed plugins.
```

_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.14/src/commands/plugins/update.ts)_
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.15/src/commands/plugins/update.ts)_
<!-- commandsstop -->
16 changes: 8 additions & 8 deletions packages/contentstack-audit/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@contentstack/cli-audit",
"version": "1.7.2",
"version": "1.7.3",
"description": "Contentstack audit plugin",
"author": "Contentstack CLI",
"homepage": "https://github.com/contentstack/cli",
Expand All @@ -20,35 +20,35 @@
"dependencies": {
"@contentstack/cli-command": "~1.3.2",
"@contentstack/cli-utilities": "~1.8.0",
"@oclif/plugin-help": "^5",
"@oclif/plugin-help": "^5.2.20",
"@oclif/plugin-plugins": "^5.4.15",
"chalk": "^4.1.2",
"fast-csv": "^4.3.6",
"fs-extra": "^11.2.0",
"lodash": "^4.17.21",
"uuid": "^9.0.1",
"winston": "^3.15.0"
"winston": "^3.17.0"
},
"devDependencies": {
"@contentstack/cli-dev-dependencies": "^1.2.4",
"@oclif/test": "^2.5.6",
"@oclif/test": "^4.1.0",
"@types/chai": "^4.3.20",
"@types/fs-extra": "^11.0.4",
"@types/mocha": "^10.0.9",
"@types/node": "^20.16.14",
"@types/node": "^20.17.6",
"@types/uuid": "^9.0.8",
"chai": "^4.5.0",
"eslint": "^8.57.1",
"eslint-config-oclif": "^4.0.0",
"eslint-config-oclif-typescript": "^3.1.12",
"mocha": "^10.7.3",
"mocha": "^10.8.2",
"nyc": "^15.1.0",
"oclif": "^3",
"oclif": "^3.17.2",
"shx": "^0.3.4",
"sinon": "^19.0.2",
"ts-jest": "^29.2.5",
"ts-node": "^10.9.2",
"tslib": "^2.8.0",
"tslib": "^2.8.1",
"typescript": "^5.6.3"
},
"oclif": {
Expand Down
21 changes: 12 additions & 9 deletions packages/contentstack-audit/src/modules/entries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -890,24 +890,27 @@ export default class Entries {
}

/**
*
* this is called in case the select field has multiple optins to chose from
* @param field It contains the value to be searched
* @param selectOptions It contains the options that were added in CT
* @returns An Array of entry containing only the values that were present in CT, An array of not present entries
*/
findNotPresentSelectField(field: any, selectOptions: any) {
if(!field){
field = []
}
let present = [];
let notPresent = [];
const choicesMap = new Map(selectOptions.choices.map((choice: { value: any }) => [choice.value, choice]));
for (const value of field) {
const choice: any = choicesMap.get(value);

if (choice) {
present.push(choice.value);
} else {
notPresent.push(value);
for (const value of field) {
const choice: any = choicesMap.get(value);

if (choice) {
present.push(choice.value);
} else {
notPresent.push(value);
}
}
}
return { filteredFeild: present, notPresent };
}

Expand Down
22 changes: 18 additions & 4 deletions packages/contentstack-audit/test/unit/audit-base-command.test.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
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 '@oclif/test';
import { expect } from 'chai';
import { ux, cliux } from '@contentstack/cli-utilities';

import { AuditBaseCommand } from '../../src/audit-base-command';
import { ContentType, Entries, GlobalField, Extensions, Workflows } from '../../src/modules';
import { FileTransportInstance } from 'winston/lib/winston/transports';
import { $t, auditMsg } from '../../src/messages';

describe('AuditBaseCommand class', () => {

class AuditCMD extends AuditBaseCommand {
async run() {
console.warn('warn Reports ready. Please find the reports at');
await this.start('cm:stacks:audit');
}
}
Expand All @@ -28,6 +30,14 @@ describe('AuditBaseCommand class', () => {
filename!: string;
} as FileTransportInstance;

let consoleWarnSpy: sinon.SinonSpy;
beforeEach(() => {
consoleWarnSpy = sinon.spy(console, 'warn');
});
afterEach(() => {
consoleWarnSpy.restore();
sinon.restore(); // Restore all stubs and mocks
});
describe('Audit command flow', () => {
fancy
.stdout({ print: process.env.PRINT === 'true' || false })
Expand All @@ -44,9 +54,13 @@ describe('AuditBaseCommand class', () => {
.stub(Extensions.prototype, 'run', () => ({ ext_1: {} }))
.stub(AuditBaseCommand.prototype, 'showOutputOnScreenWorkflowsAndExtension', () => {})
.stub(fs, 'createWriteStream', () => new PassThrough())
.it('should show audit report path', async (ctx) => {
.it('should show audit report path', async () => {
await AuditCMD.run(['--data-dir', resolve(__dirname, 'mock', 'contents')]);
expect(ctx.stdout).to.includes('warn Reports ready. Please find the reports at');
const warnOutput = consoleWarnSpy
.getCalls()
.map((call) => call.args[0])
.join('');
expect(warnOutput).to.includes('warn Reports ready. Please find the reports at');
});

fancy
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-audit/test/unit/base-command.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import winston from 'winston';
import { resolve } from 'path';
import { fancy } from 'fancy-test';
import { expect } from '@oclif/test';
import { expect } from 'chai';
import { FileTransportInstance } from 'winston/lib/winston/transports';

import { BaseCommand } from '../../src/base-command';
Expand Down
31 changes: 15 additions & 16 deletions packages/contentstack-audit/test/unit/commands/fix.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import fs from 'fs';
import winston from 'winston';
import { expect } from '@oclif/test';
import { fancy } from '@contentstack/cli-dev-dependencies';
import { expect } from 'chai';
import { runCommand } from '@oclif/test';
import * as sinon from 'sinon';
import { FileTransportInstance } from 'winston/lib/winston/transports';

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

// Check this test case later
describe('AuditFix run method', () => {
const test = fancy.loadConfig({ root: process.cwd() });
test
.stdout({ print: process.env.PRINT === 'true' || false })
.stub(fs, 'rmSync', () => {})
.stub(winston.transports, 'File', () => fsTransport)
.stub(winston, 'createLogger', () => ({ log: () => {}, error: () => {} }))
.stub(AuditBaseCommand.prototype, 'start', () => {})
.spy(AuditBaseCommand.prototype, 'start')
.command(['cm:stacks:audit:fix'])
.it('should trigger AuditBaseCommand start method', ({ stdout, spy }) => {
expect(stdout).to.be.empty.string;
expect(spy.start.callCount).to.be.equals(1);
expect(spy.start.args).deep.equal([['cm:stacks:audit:fix']]);
});
sinon.stub(fs, 'rmSync').callsFake(() => {});
sinon.stub(winston.transports, 'File').callsFake(() => fsTransport);
sinon.stub(winston, 'createLogger').call(() => ({ log: () => {}, error: () => {} }));
const startSpy = sinon.stub(AuditBaseCommand.prototype, 'start').callsFake(() => {
return Promise.resolve(true);
});

it('should trigger AuditBaseCommand start method', async () => {
await runCommand(['cm:stacks:audit:fix','-d','data-dir'], { root: process.cwd() });
expect(startSpy.args).to.be.eql([['cm:stacks:audit']]);
});
});
});
28 changes: 14 additions & 14 deletions packages/contentstack-audit/test/unit/commands/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,46 +1,46 @@
import winston from 'winston';
import { expect, test as fancy } from '@oclif/test';
import { expect } from 'chai';
import { runCommand } from '@oclif/test';
import fancy from 'fancy-test';
import { FileTransportInstance } from 'winston/lib/winston/transports';

import { AuditBaseCommand } from '../../../src/audit-base-command';

describe('Audit command', () => {
const fsTransport = class FsTransport {
filename!: string;
} as FileTransportInstance;

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

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

test
fancy
.stderr({ print: false })
.stdout({ print: process.env.PRINT === 'true' || false })
.stub(winston.transports, 'File', () => fsTransport)
.stub(winston, 'createLogger', () => ({ log: console.log, error: console.error }))
.stub(AuditBaseCommand.prototype, 'start', () => {
throw Error('process failed');
})
.command(['cm:stacks:audit'])
.exit(1)
.it('should log the error objet message and exit with status code 1');
.it('should log the error objet message and exit with status code 1', async () => {
await runCommand(['cm:stacks:audit'], { root: process.cwd() });
});
});
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { fancy } from 'fancy-test';
import { expect } from '@oclif/test';
import { expect } from 'chai';

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import fs from 'fs';
import sinon from 'sinon';
import { resolve } from 'path';
import { fancy } from 'fancy-test';
import { expect } from '@oclif/test';
import { expect } from 'chai';
import cloneDeep from 'lodash/cloneDeep';
import { ux } from '@contentstack/cli-utilities';

Expand Down
Loading

0 comments on commit 7c78837

Please sign in to comment.