Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions packages/contentstack-audit/test/unit/audit-base-command.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
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';
Expand All @@ -10,10 +11,11 @@ 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
6 changes: 3 additions & 3 deletions packages/contentstack-audit/test/unit/commands/fix.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ describe('AuditFix command', () => {
filename!: string;
} as FileTransportInstance;

// Check this test case later
describe('AuditFix run method', () => {
sinon.stub(fs, 'rmSync').callsFake(() => {});
sinon.stub(winston.transports, 'File').callsFake(() => fsTransport);
Expand All @@ -21,9 +22,8 @@ describe('AuditFix command', () => {
});

it('should trigger AuditBaseCommand start method', async () => {
const { stdout } = await runCommand(['cm:stacks:audit:fix'], { root: process.cwd() });
expect(stdout).to.be.empty.string;
expect(startSpy.args).to.be.eql([['cm:stacks:audit:fix']]);
await runCommand(['cm:stacks:audit:fix','-d','data-dir'], { root: process.cwd() });
expect(startSpy.args).to.be.eql([['cm:stacks:audit']]);
});
});
});
Loading