Skip to content

Commit

Permalink
Merge pull request #983 from contentstack/development
Browse files Browse the repository at this point in the history
Staging <- Development
  • Loading branch information
abhinav-from-contentstack authored Aug 10, 2023
2 parents c043238 + 16b4a12 commit 10f745c
Show file tree
Hide file tree
Showing 77 changed files with 2,456 additions and 275 deletions.
50 changes: 24 additions & 26 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/contentstack-auth/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ $ npm install -g @contentstack/cli-auth
$ csdx COMMAND
running command...
$ csdx (--version)
@contentstack/cli-auth/1.3.12 darwin-arm64 node-v20.3.1
@contentstack/cli-auth/1.3.12 darwin-arm64 node-v18.11.0
$ csdx --help [COMMAND]
USAGE
$ csdx COMMAND
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-bootstrap/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ $ npm install -g @contentstack/cli-cm-bootstrap
$ csdx COMMAND
running command...
$ csdx (--version)
@contentstack/cli-cm-bootstrap/1.4.13 darwin-arm64 node-v20.3.1
@contentstack/cli-cm-bootstrap/1.4.14 darwin-arm64 node-v18.11.0
$ csdx --help [COMMAND]
USAGE
$ csdx COMMAND
Expand Down
6 changes: 3 additions & 3 deletions packages/contentstack-bootstrap/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@contentstack/cli-cm-bootstrap",
"description": "Bootstrap contentstack apps",
"version": "1.4.13",
"version": "1.4.14",
"author": "Contentstack",
"bugs": "https://github.com/contentstack/cli/issues",
"scripts": {
Expand All @@ -17,7 +17,7 @@
"test:report": "nyc --reporter=lcov mocha \"test/**/*.test.js\""
},
"dependencies": {
"@contentstack/cli-cm-seed": "^1.4.13",
"@contentstack/cli-cm-seed": "^1.4.14",
"@contentstack/cli-command": "^1.2.11",
"@contentstack/cli-utilities": "^1.5.1",
"inquirer": "8.2.4",
Expand Down Expand Up @@ -73,4 +73,4 @@
}
},
"repository": "contentstack/cli"
}
}
2 changes: 1 addition & 1 deletion packages/contentstack-branches/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ $ npm install -g @contentstack/cli-cm-branches
$ csdx COMMAND
running command...
$ csdx (--version)
@contentstack/cli-cm-branches/1.0.10 darwin-arm64 node-v20.3.1
@contentstack/cli-cm-branches/1.0.10 darwin-arm64 node-v18.11.0
$ csdx --help [COMMAND]
USAGE
$ csdx COMMAND
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-bulk-publish/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ $ npm install -g @contentstack/cli-cm-bulk-publish
$ csdx COMMAND
running command...
$ csdx (--version)
@contentstack/cli-cm-bulk-publish/1.3.10 darwin-arm64 node-v20.3.1
@contentstack/cli-cm-bulk-publish/1.3.10 darwin-arm64 node-v18.11.0
$ csdx --help [COMMAND]
USAGE
$ csdx COMMAND
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ class UnpublishCommand extends Command {

if (await this.confirmFlags(updatedFlags)) {
try {
if (process.env.NODE_ENV === 'test') {
return;
}
if (!updatedFlags.retryFailed) {
await start(updatedFlags, stack, config);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const getSelectedCommand = async () => {
name: 'selectedOption',
loop: false,
}];
const { selectedOption } = await inquirer.prompt(inquirerOptions);
const selectedOption = await inquirer.prompt(inquirerOptions);
return COMMAND_CODE_MAP[selectedOption];
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,43 @@
const { describe, it } = require('mocha');
const AssetsPublish = require('../../../../src/commands/cm/assets/publish');
const { cliux } = require('@contentstack/cli-utilities');
const sinon = require('sinon');
const { expect } = require('chai');
const { config } = require('dotenv');

const { stub } = sinon;
const AssetsPublish = require('../../../../src/commands/cm/assets/publish');

config();

const environments = process.env.ENVIRONMENTS.split(',');
const locales = process.env.LOCALES.split(',');

describe('AssetsPublish', () => {
it('Should run the command when all the flags are passed', async function () {
it('Should run the command when all the flags are passed', async () => {
const args = ['--environments', environments[0], '--locales', locales[0], '--alias', process.env.MANAGEMENT_ALIAS, '--yes'];
const inquireStub = stub(cliux, 'inquire');
const assetPublishSpy = sinon.spy(AssetsPublish.prototype, 'run');
await AssetsPublish.run(args);
expect(assetPublishSpy.calledOnce).to.be.true;
assetPublishSpy.restore();
});

it('Should fail when alias and stack api key flags are not passed', async () => {
const args = ['--environments', environments[0], '--locales', locales[0], '--yes'];
const assetPublishSpy = sinon.spy(AssetsPublish.prototype, 'run');
const expectedError = 'Please use `--alias` or `--stack-api-key` to proceed.';
try {
await AssetsPublish.run(args);
} catch (error) {
expect(error).to.be.an.instanceOf(Error);
expect(error.message).to.equal(expectedError);
expect(assetPublishSpy.calledOnce).to.be.true;
}
assetPublishSpy.restore();
});

it('Should run successfully when user is logged in and stack api key is passed', async () => {
const args = ['--environments', environments[0], '--locales', locales[0], '--stack-api-key', process.env.STACK_API_KEY, '--yes'];
const assetPublishSpy = sinon.spy(AssetsPublish.prototype, 'run');
await AssetsPublish.run(args);
sinon.assert.notCalled(inquireStub);
inquireStub.restore();
expect(assetPublishSpy.calledOnce).to.be.true;
assetPublishSpy.restore();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ const { cliux } = require('@contentstack/cli-utilities');
const sinon = require('sinon');
const { config } = require('dotenv');
const { expect } = require('chai');

const AssetsUnpublish = require('../../../../src/commands/cm/assets/unpublish');
// const LogoutCommand = require('@contentstack/cli');
const { test } = require('@oclif/test');

const { stub } = sinon;

Expand All @@ -31,7 +30,7 @@ describe('AssetsUnpublish', () => {
inquireStub.restore();
});

it('Should fail when alias and stack api key flags are not passed', async function () {
it('Should fail when alias and stack api key flags are not passed', async () => {
const args = ['--environment', environments[0], '--locale', locales[0], '--yes'];
const inquireStub = stub(cliux, 'prompt');
const assetUnpublishSpy = sinon.spy(AssetsUnpublish.prototype, 'run');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const CrossPublish = require('../../../../src/commands/cm/bulk-publish/cross-pub
const { cliux } = require('@contentstack/cli-utilities');
const sinon = require('sinon');
const { config } = require('dotenv');
const { expect } = require('chai');

const { stub } = sinon;

Expand All @@ -14,9 +15,59 @@ const locales = process.env.LOCALES.split(',');
describe('CrossPublish', () => {
it('Should run the command when all the flags are passed', async function () {
const args = ['--source-env', environments[0], '--environments', process.env.DESTINATION_ENV, '--locale', locales[0], '--alias', process.env.MANAGEMENT_ALIAS, '--delivery-token', process.env.DELIVERY_TOKEN, '--onlyAssets', '--yes'];
const inquireStub = stub(cliux, 'inquire');
const inquireStub = stub(cliux, 'prompt');
await CrossPublish.run(args);
sinon.assert.notCalled(inquireStub);
inquireStub.restore();
});

it('Should ask for delivery token when the flag is not passed', async () => {
const args = ['--source-env', environments[0], '--environments', process.env.DESTINATION_ENV, '--locale', locales[0], '--alias', process.env.MANAGEMENT_ALIAS, '--onlyAssets', '--yes'];
const inquireStub = stub(cliux, 'prompt').resolves(process.env.DELIVERY_TOKEN);
await CrossPublish.run(args);
sinon.assert.calledOnce(inquireStub);
inquireStub.restore();
});

it('Should fail when alias and stack api key flags are not passed', async () => {
const args = ['--source-env', environments[0], '--environments', process.env.DESTINATION_ENV, '--locale', locales[0], '--delivery-token', process.env.DELIVERY_TOKEN, '--onlyAssets', '--yes'];
const inquireStub = stub(cliux, 'prompt');
const crossPublishSpy = sinon.spy(CrossPublish.prototype, 'run');
const expectedError = 'Please use `--alias` or `--stack-api-key` to proceed.';
try {
await CrossPublish.run(args);
} catch (error) {
expect(error).to.be.instanceOf(Error);
expect(error.message).to.equal(expectedError);
expect(crossPublishSpy.calledOnce).to.be.true;
}
sinon.assert.notCalled(inquireStub);
inquireStub.restore();
crossPublishSpy.restore();
});

it('Should run successfully when user is logged in and stack api key is passed', async () => {
const args = ['--source-env', environments[0], '--environments', process.env.DESTINATION_ENV, '--locale', locales[0], '--stack-api-key', process.env.STACK_API_KEY, '--delivery-token', process.env.DELIVERY_TOKEN, '--onlyAssets', '--yes'];
const inquireStub = stub(cliux, 'prompt');
await CrossPublish.run(args);
sinon.assert.notCalled(inquireStub);
inquireStub.restore();
});

it('Should fail when onlyAssets and onlyEntries flags are passed together', async () => {
const args = ['--source-env', environments[0], '--environments', process.env.DESTINATION_ENV, '--locale', locales[0], '--stack-api-key', process.env.STACK_API_KEY, '--delivery-token', process.env.DELIVERY_TOKEN, '--onlyAssets', '--onlyEntries', '--yes'];
const inquireStub = stub(cliux, 'prompt');
const crossPublishSpy = sinon.spy(CrossPublish.prototype, 'run');
const expectedError = 'The flags onlyAssets and onlyEntries need not be used at the same time. Unpublish command unpublishes entries and assts at the same time by default';
try {
await CrossPublish.run(args);
} catch (error) {
expect(error).to.be.instanceOf(Error);
expect(error.message).to.equal(expectedError);
expect(crossPublishSpy.calledOnce).to.be.true;
}
sinon.assert.notCalled(inquireStub);
inquireStub.restore();
crossPublishSpy.restore();
});
});
Loading

0 comments on commit 10f745c

Please sign in to comment.