Skip to content

Commit

Permalink
Fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
camden11 committed Nov 22, 2024
1 parent 5135d0c commit 99d58d9
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 18 deletions.
19 changes: 11 additions & 8 deletions commands/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@ const {
addConfigOptions,
addAccountOptions,
addOverwriteOptions,
addModeOptions,
addCmsPublishModeOptions,
addUseEnvironmentOptions,
getAccountId,
getMode,
getCmsPublishMode,
} = require('../lib/commonOpts');
const { resolveLocalPath } = require('../lib/filesystem');
const { validateMode, loadAndValidateOptions } = require('../lib/validation');
const {
validateCmsPublishMode,
loadAndValidateOptions,
} = require('../lib/validation');
const { trackCommandUsage } = require('../lib/usageTracking');
const { i18n } = require('../lib/lang');

Expand All @@ -27,7 +30,7 @@ exports.handler = async options => {

await loadAndValidateOptions(options);

if (!validateMode(options)) {
if (!validateCmsPublishMode(options)) {
process.exit(EXIT_CODES.ERROR);
}

Expand All @@ -37,17 +40,17 @@ exports.handler = async options => {
}

const accountId = getAccountId(options);
const mode = getMode(options);
const cmsPublishMode = getCmsPublishMode(options);

trackCommandUsage('fetch', { mode }, accountId);
trackCommandUsage('fetch', { mode: cmsPublishMode }, accountId);

try {
// Fetch and write file/folder.
await downloadFileOrFolder(
accountId,
src,
resolveLocalPath(dest),
mode,
cmsPublishMode,
options
);
} catch (err) {
Expand All @@ -60,7 +63,7 @@ exports.builder = yargs => {
addConfigOptions(yargs);
addAccountOptions(yargs);
addOverwriteOptions(yargs);
addModeOptions(yargs, { read: true });
addCmsPublishModeOptions(yargs, { read: true });
addUseEnvironmentOptions(yargs);

yargs.positional('src', {
Expand Down
20 changes: 11 additions & 9 deletions lib/__tests__/commonOpts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('lib/commonOpts', () => {
};
const configWithDefaultCmsPublishMode = {
...config,
defaultCmsPublishMode: MODE.draft,
defaultCmsPublishMode: CMS_PUBLISH_MODE.draft,
};

afterEach(() => {
Expand All @@ -48,15 +48,17 @@ describe('lib/commonOpts', () => {
describe('cms publish mode option precedence', () => {
describe('1. --cmsPublishMode', () => {
it('should return the cms publish mode specified by the command option if present.', () => {
getAndLoadConfigIfNeeded.mockReturnValue(configWithDefaultMode);
getAccountConfig.mockReturnValue(devAccountConfig);
expect(getMode({ cmsPublishMode: CMS_PUBLISH_MODE.draft })).toBe(
CMS_PUBLISH_MODE.draft
);
expect(getMode({ cmsPublishMode: CMS_PUBLISH_MODE.publish })).toBe(
CMS_PUBLISH_MODE.publish
getAndLoadConfigIfNeeded.mockReturnValue(
configWithDefaultCmsPublishMode
);
expect(getMode({ cmsPublishMode: 'undefined-mode' })).toBe(
getAccountConfig.mockReturnValue(devAccountConfig);
expect(
getCmsPublishMode({ cmsPublishMode: CMS_PUBLISH_MODE.draft })
).toBe(CMS_PUBLISH_MODE.draft);
expect(
getCmsPublishMode({ cmsPublishMode: CMS_PUBLISH_MODE.publish })
).toBe(CMS_PUBLISH_MODE.publish);
expect(getCmsPublishMode({ cmsPublishMode: 'undefined-mode' })).toBe(
'undefined-mode'
);
});
Expand Down
2 changes: 1 addition & 1 deletion lib/commonOpts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export function getCmsPublishMode(
// 4. DEFAULT_MODE
const config = getAndLoadConfigIfNeeded();
return (
(config && (config.defaultMode as CmsPublishMode)) ||
(config && (config.defaultCmsPublishMode as CmsPublishMode)) ||
DEFAULT_CMS_PUBLISH_MODE
);
}
Expand Down

0 comments on commit 99d58d9

Please sign in to comment.