Skip to content

Commit 7be7eb7

Browse files
committed
Fixed Test cases
1 parent 89a9854 commit 7be7eb7

File tree

6 files changed

+47
-29
lines changed

6 files changed

+47
-29
lines changed

package-lock.json

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

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

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,19 @@ import { expect } from 'chai';
88
import { ux, cliux } from '@contentstack/cli-utilities';
99

1010
import { AuditBaseCommand } from '../../src/audit-base-command';
11-
import { ContentType, Entries, GlobalField, Extensions, Workflows } from '../../src/modules';
11+
import {
12+
ContentType,
13+
Entries,
14+
GlobalField,
15+
Extensions,
16+
Workflows,
17+
CustomRoles,
18+
Assets,
19+
FieldRule,
20+
} from '../../src/modules';
1221
import { FileTransportInstance } from 'winston/lib/winston/transports';
1322
import { $t, auditMsg } from '../../src/messages';
1423
describe('AuditBaseCommand class', () => {
15-
1624
class AuditCMD extends AuditBaseCommand {
1725
async run() {
1826
console.warn('warn Reports ready. Please find the reports at');
@@ -45,13 +53,16 @@ describe('AuditBaseCommand class', () => {
4553
.stub(winston, 'createLogger', () => ({ log: console.log, error: console.error }))
4654
.stub(fs, 'mkdirSync', () => {})
4755
.stub(fs, 'writeFileSync', () => {})
48-
.stub(ux, 'table', () => {})
56+
.stub(cliux, 'table', () => {})
4957
.stub(ux.action, 'stop', () => {})
5058
.stub(ux.action, 'start', () => {})
5159
.stub(Entries.prototype, 'run', () => ({ entry_1: {} }))
5260
.stub(ContentType.prototype, 'run', () => ({ ct_1: {} }))
5361
.stub(GlobalField.prototype, 'run', () => ({ gf_1: {} }))
5462
.stub(Extensions.prototype, 'run', () => ({ ext_1: {} }))
63+
.stub(CustomRoles.prototype, 'run', () => ({ ext_1: {} }))
64+
.stub(Assets.prototype, 'run', () => ({ ext_1: {} }))
65+
.stub(FieldRule.prototype, 'run', () => ({ ext_1: {} }))
5566
.stub(AuditBaseCommand.prototype, 'showOutputOnScreenWorkflowsAndExtension', () => {})
5667
.stub(fs, 'createWriteStream', () => new PassThrough())
5768
.it('should show audit report path', async () => {
@@ -79,6 +90,9 @@ describe('AuditBaseCommand class', () => {
7990
.stub(GlobalField.prototype, 'run', () => ({ gf_1: {} }))
8091
.stub(Workflows.prototype, 'run', () => ({ wf_1: {} }))
8192
.stub(Extensions.prototype, 'run', () => ({ ext_1: {} }))
93+
.stub(CustomRoles.prototype, 'run', () => ({ ext_1: {} }))
94+
.stub(Assets.prototype, 'run', () => ({ ext_1: {} }))
95+
.stub(FieldRule.prototype, 'run', () => ({ ext_1: {} }))
8296
.stub(fs, 'createWriteStream', () => new PassThrough())
8397
.it('should print info of no ref found', async (ctx) => {
8498
await AuditCMD.run([]);
@@ -113,6 +127,9 @@ describe('AuditBaseCommand class', () => {
113127
.stub(GlobalField.prototype, 'run', () => ({ gf_1: {} }))
114128
.stub(Workflows.prototype, 'run', () => ({ wf_1: {} }))
115129
.stub(Extensions.prototype, 'run', () => ({ ext_1: {} }))
130+
.stub(CustomRoles.prototype, 'run', () => ({ ext_1: {} }))
131+
.stub(Assets.prototype, 'run', () => ({ ext_1: {} }))
132+
.stub(FieldRule.prototype, 'run', () => ({ ext_1: {} }))
116133
.stub(fs, 'createBackUp', () => {})
117134
.stub(fs, 'createWriteStream', () => new PassThrough())
118135
.stub(AuditBaseCommand.prototype, 'createBackUp', () => {})

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ describe('Audit command', () => {
1717
.stub(winston, 'createLogger', () => ({ log: () => {}, error: () => {} }))
1818
.stub(AuditBaseCommand.prototype, 'start', () => {})
1919
.it('should trigger AuditBaseCommand start method', async () => {
20-
const { stdout } = await runCommand(['cm:stacks:audit'], { root: process.cwd() });
20+
const { stdout } = await runCommand(['cm:stacks:audit', 'd', 'mock'], { root: process.cwd() });
2121
expect(stdout).to.be.string;
2222
});
2323

@@ -28,19 +28,19 @@ describe('Audit command', () => {
2828
.stub(winston, 'createLogger', () => ({ log: console.log, error: console.error }))
2929
.stub(AuditBaseCommand.prototype, 'start', () => Promise.reject('process failed'))
3030
.it('should log any error and exit with status code 1', async () => {
31-
await runCommand(['cm:stacks:audit'], { root: process.cwd() });
31+
await runCommand(['cm:stacks:audit', 'd', 'mock'], { root: process.cwd() });
3232
});
3333

3434
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 }))
39-
.stub(AuditBaseCommand.prototype, 'start', () => {
40-
throw Error('process failed');
39+
.stub(AuditBaseCommand.prototype, 'start', async () => {
40+
Promise.reject('process failed');
4141
})
4242
.it('should log the error objet message and exit with status code 1', async () => {
43-
await runCommand(['cm:stacks:audit'], { root: process.cwd() });
43+
await runCommand(['cm:stacks:audit', 'd', 'mock'], { root: process.cwd() });
4444
});
4545
});
4646
});

packages/contentstack-audit/test/unit/modules/entries.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import fs from 'fs';
22
import { resolve } from 'path';
33
import { expect } from 'chai';
44
import cloneDeep from 'lodash/cloneDeep';
5-
import { ux } from '@contentstack/cli-utilities';
5+
import { cliux } from '@contentstack/cli-utilities';
66
import fancy from 'fancy-test';
77
import Sinon from 'sinon';
88
import config from '../../../src/config';
@@ -112,7 +112,7 @@ describe('Entries module', () => {
112112
fancy
113113
.stdout({ print: process.env.PRINT === 'true' || false })
114114
.stub(fs, 'writeFileSync', () => {})
115-
.stub(ux, 'confirm', async () => true)
115+
.stub(cliux, 'confirm', async () => true)
116116
.it('should ask confirmation adn write content in given path', async ({}) => {
117117
const writeFileSync = Sinon.spy(fs, 'writeFileSync');
118118
const ctInstance = new Entries({ ...constructorParam, fix: true });

packages/contentstack-audit/test/unit/modules/extensions.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { resolve } from 'path';
22
import { fancy } from 'fancy-test';
33
import { expect } from 'chai';
44
import cloneDeep from 'lodash/cloneDeep';
5-
import { ux } from '@contentstack/cli-utilities';
5+
import { ux, cliux } from '@contentstack/cli-utilities';
66

77
import config from '../../../src/config';
88
import { Extensions } from '../../../src/modules';
@@ -255,7 +255,7 @@ describe('Extensions scope containing content_types uids', () => {
255255

256256
fancy
257257
.stdout({ print: process.env.PRINT === 'true' || true })
258-
.stub(ux, 'confirm', async () => true)
258+
.stub(cliux, 'confirm', async () => true)
259259
.stub(ext, 'writeFileSync', () => {})
260260
.it(
261261
'missingCts in extension to extensionSchema containing, extensions with fixed scope, missing Cts to the Cts that are not present in Ct Schema, And the fixed extensions that would be overwritten in the file',
@@ -342,9 +342,10 @@ describe('Extensions scope containing content_types uids', () => {
342342
});
343343
fancy
344344
.stdout({ print: process.env.PRINT === 'true' || true })
345-
.stub(ux, 'confirm', async () => true)
345+
.stub(cliux, 'confirm', async () => true)
346346
.stub(ext, 'writeFixContent', async () => {})
347347
.stub(ext, 'writeFileSync', () => {})
348+
.stub(ext, 'writeFixContent', async () => {})
348349
.it(
349350
'missingCts in extension to extensionSchema containing, extensions with fixed scope, missing Cts to the Cts that are not present in Ct Schema, Not overwriting to the file',
350351
async () => {

pnpm-lock.yaml

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

0 commit comments

Comments
 (0)