Skip to content

Commit

Permalink
Merge pull request #959 from contentstack/feat/40250
Browse files Browse the repository at this point in the history
fix: export plugin test cases
  • Loading branch information
aman19K authored Aug 3, 2023
2 parents 74275b3 + 01ee9b3 commit 810c618
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 37 deletions.
1 change: 1 addition & 0 deletions packages/contentstack-export/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"lint": "eslint src/**/*.ts",
"format": "eslint src/**/*.ts --fix",
"test:integration": "INTEGRATION_TEST=true mocha --config ./test/.mocharc.js --forbid-only \"test/run.test.js\"",
"test:integration:report": "INTEGRATION_TEST=true nyc --extension .js mocha --forbid-only \"test/run.test.js\"",
"test:unit": "mocha --forbid-only \"test/unit/*.test.ts\""
},
"engines": {
Expand Down
3 changes: 2 additions & 1 deletion packages/contentstack-export/src/export/modules/locales.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ export default class LocaleExport extends BaseClass {
delete locale[key];
}
}
if (locale.code === this.exportConfig.master_locale.code) {

if (locale?.code === this.exportConfig?.master_locale?.code) {
this.masterLocale[locale.uid] = locale;
} else {
this.locales[locale.uid] = locale;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ module.exports = (region) => {
: path.join(__dirname, '..', '..', `${EXPORT_PATH}_${stack}`);
const customRolesBasePath = path.join(exportBasePath, modules.customRoles.dirName);
const customRolesJson = path.join(customRolesBasePath, modules.customRoles.fileName);
const messageFilePath = path.join(__dirname, '..', '..', 'messages/index.json');

messageHandler.init({ messageFilePath });
const { promptMessageList } = require(messageFilePath);

describe('ContentStack-Export custom-roles', () => {
describe('cm:stacks:export custom-roles [auth-token]', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
let defaultConfig = require('../../src/config/default');
const fs = require('fs');
const path = require('path');
const { test } = require('@oclif/test');
const { cliux: cliUX, messageHandler } = require('@contentstack/cli-utilities');

const { default: config } = require('../../src/config');
const { default: config } = require('../../lib/config');
const modules = config.modules;
const { getStackDetailsByRegion, getGlobalFieldsCount, cleanUp, checkCounts } = require('./utils/helper');
const { EXPORT_PATH, DEFAULT_TIMEOUT } = require('./config.json');
Expand All @@ -18,20 +17,17 @@ module.exports = (region) => {
: path.join(__dirname, '..', '..', `${EXPORT_PATH}_${stack}`);
const globalFieldsBasePath = path.join(exportBasePath, modules.globalfields.dirName);
const globalFieldsJson = path.join(globalFieldsBasePath, modules.globalfields.fileName);
const messageFilePath = path.join(__dirname, '..', '..', 'messages/index.json');

messageHandler.init({ messageFilePath });
const { promptMessageList } = require(messageFilePath);

describe('ContentStack-Export global-fields', () => {
describe('cm:stacks:export global-fields [auth-token]', () => {
test
.timeout(DEFAULT_TIMEOUT || 600000) // NOTE setting default timeout as 10 minutes
.stub(cliUX, 'prompt', async (name) => {
.stub(cliUX, 'inquire', async (input) => {
const { name } = input;
switch (name) {
case promptMessageList.promptSourceStack:
case 'apiKey':
return stackDetails[stack].STACK_API_KEY;
case promptMessageList.promptPathStoredData:
case 'dir':
return `${EXPORT_PATH}_${stack}`;
}
})
Expand Down Expand Up @@ -85,9 +81,9 @@ module.exports = (region) => {

afterEach(async () => {
await cleanUp(path.join(__dirname, '..', '..', `${EXPORT_PATH}_${stack}`));
defaultConfig.management_token = undefined;
defaultConfig.branch = undefined;
defaultConfig.branches = [];
config.management_token = undefined;
config.branch = undefined;
config.branches = [];
});
}
};
3 changes: 0 additions & 3 deletions packages/contentstack-export/test/integration/locales.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ module.exports = (region) => {

const localeBasePath = path.join(exportBasePath, modules.locales.dirName);
const localeJson = path.join(localeBasePath, modules.locales.fileName);
const messageFilePath = path.join(__dirname, '..', '..', 'messages/index.json');
messageHandler.init({ messageFilePath });
const { promptMessageList } = require(messageFilePath);

describe('ContentStack-Export locales', () => {
describe('cm:stacks:export locales [auth-token]', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const fs = require('fs');
const path = require('path');
const { test } = require('@oclif/test');
const { cliux: cliUX, messageHandler } = require('@contentstack/cli-utilities');
const { cliux: cliUX } = require('@contentstack/cli-utilities');

const { default: config } = require('../../lib/config');
const modules = config.modules;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ module.exports = (region) => {
: path.join(__dirname, '..', '..', `${EXPORT_PATH}_${stack}`);
const webhooksBasePath = path.join(exportBasePath, modules.webhooks.dirName);
const webhooksJson = path.join(webhooksBasePath, modules.webhooks.fileName);
const messageFilePath = path.join(__dirname, '..', '..', 'messages/index.json');

messageHandler.init({ messageFilePath });
const { promptMessageList } = require(messageFilePath);

describe('ContentStack-Export webhooks', () => {
describe('cm:stacks:export webhooks [auth-token]', () => {
Expand Down
20 changes: 8 additions & 12 deletions packages/contentstack-export/test/integration/workflows.test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
let defaultConfig = require('../../src/config/default');
const fs = require('fs');
const path = require('path');
const { test } = require('@oclif/test');
const { cliux: cliUX, messageHandler } = require('@contentstack/cli-utilities');

const { default: config } = require('../../src/config');
const { default: config } = require('../../lib/config');
const modules = config.modules;
const { getStackDetailsByRegion, getWorkflowsCount, cleanUp, checkCounts } = require('./utils/helper');
const { EXPORT_PATH, DEFAULT_TIMEOUT } = require('./config.json');
Expand All @@ -18,20 +17,17 @@ module.exports = (region) => {
: path.join(__dirname, '..', '..', `${EXPORT_PATH}_${stack}`);
const workflowsBasePath = path.join(exportBasePath, modules.workflows.dirName);
const workflowsJson = path.join(workflowsBasePath, modules.workflows.fileName);
const messageFilePath = path.join(__dirname, '..', '..', 'messages/index.json');

messageHandler.init({ messageFilePath });
const { promptMessageList } = require(messageFilePath);

describe('ContentStack-Export workflows', () => {
describe('cm:stacks:export workfows [auth-token]', () => {
test
.timeout(DEFAULT_TIMEOUT || 600000) // NOTE setting default timeout as 10 minutes
.stub(cliUX, 'prompt', async (name) => {
.stub(cliUX, 'inquire', async (input) => {
const { name } = input;
switch (name) {
case promptMessageList.promptSourceStack:
case 'apiKey':
return stackDetails[stack].STACK_API_KEY;
case promptMessageList.promptPathStoredData:
case 'dir':
return `${EXPORT_PATH}_${stack}`;
}
})
Expand Down Expand Up @@ -85,9 +81,9 @@ module.exports = (region) => {

afterEach(async () => {
await cleanUp(path.join(__dirname, '..', '..', `${EXPORT_PATH}_${stack}`));
defaultConfig.management_token = undefined;
defaultConfig.branch = undefined;
defaultConfig.branches = [];
config.management_token = undefined;
config.branch = undefined;
config.branches = [];
});
}
};

0 comments on commit 810c618

Please sign in to comment.