From 7c3a0c8db7e1f01873400145cbaf0c04a99f2aa6 Mon Sep 17 00:00:00 2001 From: Chhavi-Mandowara Date: Wed, 30 Apr 2025 15:41:43 +0530 Subject: [PATCH] fix: allow --type flag to create new project without prompting to select provider --- .talismanrc | 4 ++++ src/commands/launch/index.test.ts | 35 +++++++++++++++++++++++++++++-- src/commands/launch/index.ts | 18 +++++++++++++++- 3 files changed, 54 insertions(+), 3 deletions(-) create mode 100644 .talismanrc diff --git a/.talismanrc b/.talismanrc new file mode 100644 index 00000000..4087709 --- /dev/null +++ b/.talismanrc @@ -0,0 +1,4 @@ +fileignoreconfig: +- filename: src/commands/launch/index.test.ts + checksum: 9db6c02ad35a0367343cd753b916dd64db4a9efd24838201d2e1113ed19c9b62 +version: "1.0" \ No newline at end of file diff --git a/src/commands/launch/index.test.ts b/src/commands/launch/index.test.ts index c5f0547..006c4ec 100644 --- a/src/commands/launch/index.test.ts +++ b/src/commands/launch/index.test.ts @@ -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; @@ -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(); + }); }); diff --git a/src/commands/launch/index.ts b/src/commands/launch/index.ts index b2fe6b4..21b34b7 100755 --- a/src/commands/launch/index.ts +++ b/src/commands/launch/index.ts @@ -21,9 +21,13 @@ export default class Launch extends BaseCommand { '<%= config.bin %> <%= command.id %> --data-dir --redeploy-last-upload', '<%= config.bin %> <%= command.id %> --config --type ', '<%= config.bin %> <%= command.id %> --environment= --redeploy-latest', + // eslint-disable-next-line max-len '<%= config.bin %> <%= command.id %> --config --type --name= --environment= --branch= --build-command= --framework=