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
4 changes: 4 additions & 0 deletions .talismanrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
fileignoreconfig:
- filename: src/commands/launch/index.test.ts
checksum: 9db6c02ad35a0367343cd753b916dd64db4a9efd24838201d2e1113ed19c9b62
version: "1.0"
35 changes: 33 additions & 2 deletions src/commands/launch/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,27 @@ import { BaseCommand } from '../../base-command';
import { FileUpload, GitHub, PreCheck } from '../../adapters';
import { cliux } from '@contentstack/cli-utilities';

jest.mock('@contentstack/cli-utilities');

jest.mock('../../base-command');

jest.mock('@contentstack/cli-utilities', () => {
const actual = jest.requireActual('@contentstack/cli-utilities');
return {
...actual,
configHandler: {
get: jest.fn((key) => {
if (key === 'authtoken') return 'dummy-token';
if (key === 'authorisationType') return 'OAuth';
if (key === 'oauthAccessToken') return 'dummy-oauth-token';
return undefined;
}),
},
cliux: {
...actual.cliux,
inquire: jest.fn(), // mock `inquire` explicitly
},
};
});

describe('Run', () => {
let launchCommandInstance: Launch;
let prepareApiClientsMock: jest.SpyInstance;
Expand Down Expand Up @@ -89,4 +106,18 @@ describe('Run', () => {
message: 'Choose a project type to proceed',
});
});

it('should successfully run launch command when its a new project, and provider is passed as flag', async () => {
const githubRunMock = jest.spyOn(GitHub.prototype, 'run').mockResolvedValueOnce(undefined);
BaseCommand.prototype['sharedConfig'] = {isExistingProject: false} as any;
BaseCommand.prototype['flags'] = { init: false, type: 'GitHub' };
launchCommandInstance = new Launch([], {} as any);

await launchCommandInstance.run();

expect(prepareApiClientsMock).toHaveBeenCalled();
expect(preCheckRunMock).toHaveBeenCalled();
expect(githubRunMock).toHaveBeenCalled();
expect(cliux.inquire).not.toHaveBeenCalled();
});
});
18 changes: 17 additions & 1 deletion src/commands/launch/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,13 @@ export default class Launch extends BaseCommand<typeof Launch> {
'<%= config.bin %> <%= command.id %> --data-dir <path/of/current/working/dir> --redeploy-last-upload',
'<%= config.bin %> <%= command.id %> --config <path/to/launch/config/file> --type <options: GitHub|FileUpload>',
'<%= config.bin %> <%= command.id %> --environment=<value> --redeploy-latest',
// eslint-disable-next-line max-len
'<%= config.bin %> <%= command.id %> --config <path/to/launch/config/file> --type <options: GitHub|FileUpload> --name=<value> --environment=<value> --branch=<value> --build-command=<value> --framework=<option> --org=<value> --out-dir=<value>',
// eslint-disable-next-line max-len
'<%= config.bin %> <%= command.id %> --config <path/to/launch/config/file> --type <options: GitHub|FileUpload> --name=<value> --environment=<value> --branch=<value> --build-command=<value> --framework=<option> --org=<value> --out-dir=<value> --server-command=<value>',
// eslint-disable-next-line max-len
'<%= config.bin %> <%= command.id %> --config <path/to/launch/config/file> --type <options: GitHub|FileUpload> --name=<value> --environment=<value> --branch=<value> --build-command=<value> --framework=<option> --org=<value> --out-dir=<value> --variable-type="Import variables from a stack" --alias=<value>',
// eslint-disable-next-line max-len
'<%= config.bin %> <%= command.id %> --config <path/to/launch/config/file> --type <options: GitHub|FileUpload> --name=<value> --environment=<value> --branch=<value> --build-command=<value> --framework=<option> --org=<value> --out-dir=<value> --variable-type="Manually add custom variables to the list" --env-variables="APP_ENV:prod, TEST_ENV:testVal"',
];

Expand Down Expand Up @@ -62,6 +66,7 @@ export default class Launch extends BaseCommand<typeof Launch> {
'variable-type': Flags.string({
options: [...config.variablePreparationTypeOptions],
description:
// eslint-disable-next-line max-len
'[optional] Provide a variable type. <options: Import variables from a stack|Manually add custom variables to the list|Import variables from the .env.local file|Skip adding environment variables>',
}),
'show-variables': Flags.boolean({
Expand All @@ -79,6 +84,7 @@ export default class Launch extends BaseCommand<typeof Launch> {
}),
'env-variables': Flags.string({
description:
// eslint-disable-next-line max-len
'[optional] Provide the environment variables in the key:value format, separated by comma. For example: APP_ENV:prod, TEST_ENV:testVal.',
}),
'redeploy-latest': Flags.boolean({
Expand All @@ -103,7 +109,7 @@ export default class Launch extends BaseCommand<typeof Launch> {
// NOTE pre-check: manage flow and set the provider value
await this.preCheckAndInitConfig();
if (!this.sharedConfig.isExistingProject) {
await this.selectProjectType();
await this.setProviderType();
}
await this.manageFlowBasedOnProvider();
}
Expand Down Expand Up @@ -182,4 +188,14 @@ export default class Launch extends BaseCommand<typeof Launch> {

this.sharedConfig.provider = selectedProvider;
}

private async setProviderType(): Promise<void> {
const providerTypeFlag = this.flags.type;

if (providerTypeFlag) {
this.sharedConfig.provider = providerTypeFlag as Providers;
return;
}
await this.selectProjectType();
}
}