Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
14 commits
Select commit Hold shift + click to select a range
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
6 changes: 6 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,10 @@ export default tseslint.config(
]
},
},
{
files: ['src/**/*.test.ts'],
rules: {
'max-len': 'off',
},
},
);
1,683 changes: 683 additions & 1,000 deletions package-lock.json

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@contentstack/cli-launch",
"version": "1.9.8",
"version": "1.9.9",
"description": "Launch related operations",
"author": "Contentstack CLI",
"bin": {
Expand All @@ -21,8 +21,8 @@
],
"dependencies": {
"@apollo/client": "^3.14.0",
"@contentstack/cli-command": "^1.8.1",
"@contentstack/cli-utilities": "^1.18.2",
"@contentstack/cli-command": "^1.8.2",
"@contentstack/cli-utilities": "^1.18.3",
"@oclif/core": "^4.2.7",
"@oclif/plugin-help": "^6.2.25",
"@rollup/plugin-commonjs": "^28.0.2",
Expand Down Expand Up @@ -107,7 +107,6 @@
},
"overrides": {
"lodash": "^4.18.1",
"axios": "^1.13.5",
"form-data": "4.0.4",
"ajv": "^8.18.0",
"eslint": {
Expand Down
14 changes: 5 additions & 9 deletions src/adapters/base-class.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import { baseClassAdapter as cliUtilitiesJestMock } from '../test/mocks/cli-utilities';
import BaseClass from './base-class';
import { cliux as ux, ContentstackClient } from '@contentstack/cli-utilities';
import config from '../config';
import { FILE_UPLOAD_SIZE_LIMIT_USER_MESSAGE } from '../util/deployment-errors';

jest.mock('@contentstack/cli-utilities', () => ({
cliux: {
inquire: jest.fn(),
table: jest.fn(),
},
}));
jest.mock('@contentstack/cli-utilities', () => cliUtilitiesJestMock);

Comment thread
SakshiKoli-CS marked this conversation as resolved.
describe('BaseClass', () => {
let baseClass: BaseClass;
Expand Down Expand Up @@ -121,7 +117,7 @@ describe('BaseClass', () => {

expect(exitMock).not.toHaveBeenCalled();
expect(logMock).not.toHaveBeenCalledWith(
"The 'Skip adding environment variables' option cannot be combined with other environment variable options. Please choose either 'Skip adding environment variables' or one or more of the other available options.",
'The \'Skip adding environment variables\' option cannot be combined with other environment variable options. Please choose either \'Skip adding environment variables\' or one or more of the other available options.',
'error',
);
});
Expand Down Expand Up @@ -233,7 +229,7 @@ describe('BaseClass', () => {
await baseClass.handleEnvImportFlow();

expect(logMock).toHaveBeenCalledWith(
"The 'Skip adding environment variables' option cannot be combined with other environment variable options. Please choose either 'Skip adding environment variables' or one or more of the other available options.",
'The \'Skip adding environment variables\' option cannot be combined with other environment variable options. Please choose either \'Skip adding environment variables\' or one or more of the other available options.',
'error',
);
expect(exitMock).toHaveBeenCalledWith(1);
Expand Down Expand Up @@ -271,7 +267,7 @@ describe('BaseClass', () => {
await expect(baseClass.handleEnvImportFlow()).rejects.toThrow('Exit called');

expect(logMock).toHaveBeenCalledWith(
"The 'Skip adding environment variables' option cannot be combined with other environment variable options. Please choose either 'Skip adding environment variables' or one or more of the other available options.",
'The \'Skip adding environment variables\' option cannot be combined with other environment variable options. Please choose either \'Skip adding environment variables\' or one or more of the other available options.',
'error',
);

Expand Down
14 changes: 2 additions & 12 deletions src/adapters/file-upload.test.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,10 @@
import { fileUploadAdapter as cliUtilitiesJestMock } from '../test/mocks/cli-utilities';
import FileUpload from './file-upload';
import BaseClass from './base-class';
import { cliux } from '@contentstack/cli-utilities';
import { DeploymentStatus } from '../types/launch';

jest.mock('@contentstack/cli-utilities', () => ({
...jest.requireActual('@contentstack/cli-utilities'),
cliux: {
inquire: jest.fn(),
loader: jest.fn(),
print: jest.fn(),
},
configHandler: {
get: jest.fn(),
},
HttpClient: jest.fn(),
}));
jest.mock('@contentstack/cli-utilities', () => cliUtilitiesJestMock);

Comment thread
SakshiKoli-CS marked this conversation as resolved.
describe('FileUpload Adapter', () => {
let logMock: jest.Mock;
Expand Down
12 changes: 2 additions & 10 deletions src/adapters/github.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { githubAdapter as cliUtilitiesJestMock } from '../test/mocks/cli-utilities';
import GitHub from './github';
import { getRemoteUrls } from '../util/create-git-meta';
import { repositoriesQuery, userConnectionsQuery } from '../graphql';
Expand All @@ -6,16 +7,7 @@ import { existsSync } from 'fs';
import { DeploymentStatus } from '../types';
import { cliux as ux } from '@contentstack/cli-utilities';

jest.mock('@contentstack/cli-utilities', () => ({
...jest.requireActual('@contentstack/cli-utilities'),
cliux: {
inquire: jest.fn(),
print: jest.fn(),
},
configHandler: {
get: jest.fn(),
},
}));
jest.mock('@contentstack/cli-utilities', () => cliUtilitiesJestMock);

Comment thread
SakshiKoli-CS marked this conversation as resolved.
jest.mock('../util/create-git-meta');
jest.mock('fs', () => ({
Expand Down
3 changes: 3 additions & 0 deletions src/commands/launch/functions.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { functionsCommand as cliUtilitiesJestMock } from '../../test/mocks/cli-utilities';
import Functions from './functions';
import { Logger } from '../../util';
import { Contentfly } from '../../util/cloud-function/contentfly';

jest.mock('@contentstack/cli-utilities', () => cliUtilitiesJestMock);
Comment thread
SakshiKoli-CS marked this conversation as resolved.

jest.mock('../../util');
jest.mock('../../util/cloud-function/contentfly');

Expand Down
39 changes: 15 additions & 24 deletions src/commands/launch/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,26 @@
import { launchCommand as cliUtilitiesJestMock } from '../../test/mocks/cli-utilities';
import Launch from './index';
import { BaseCommand } from '../../base-command';
import { FileUpload, GitHub, PreCheck } from '../../adapters';
import { cliux } from '@contentstack/cli-utilities';
import { cliux, configHandler } from '@contentstack/cli-utilities';

jest.mock('../../base-command');
jest.mock('@contentstack/cli-utilities', () => cliUtilitiesJestMock);

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
},
};
});
const LaunchWithArgv = Launch as unknown as new (argv: string[], config: unknown) => Launch;
Comment thread
SakshiKoli-CS marked this conversation as resolved.

describe('Run', () => {
let launchCommandInstance: Launch;
let prepareApiClientsMock: jest.SpyInstance;
let preCheckRunMock: jest.SpyInstance;

beforeEach(() => {
(configHandler.get as jest.Mock).mockImplementation((key: string) => {
if (key === 'authtoken') return 'dummy-token';
if (key === 'authorisationType') return 'OAuth';
if (key === 'oauthAccessToken') return 'dummy-oauth-token';
return undefined;
});
prepareApiClientsMock = jest.spyOn(BaseCommand.prototype, 'prepareApiClients').mockResolvedValueOnce(undefined);
// @ts-expect-error - Override readonly property context on BaseCommand for testing
BaseCommand.prototype['context'] = { analyticsInfo: {} } as any;
Expand All @@ -45,7 +36,7 @@ describe('Run', () => {
const githubRunMock = jest.spyOn(GitHub.prototype, 'run').mockResolvedValueOnce(undefined);
BaseCommand.prototype['sharedConfig'] = { provider: 'GitHub', isExistingProject: true } as any;
BaseCommand.prototype['flags'] = { init: false };
launchCommandInstance = new Launch([], {} as any);
launchCommandInstance = new LaunchWithArgv([], {} as any);

await launchCommandInstance.run();

Expand All @@ -58,7 +49,7 @@ describe('Run', () => {
const fileUploadRunMock = jest.spyOn(FileUpload.prototype, 'run').mockResolvedValueOnce(undefined);
BaseCommand.prototype['sharedConfig'] = { provider: 'FileUpload', isExistingProject: true } as any;
BaseCommand.prototype['flags'] = { init: false };
launchCommandInstance = new Launch([], {} as any);
launchCommandInstance = new LaunchWithArgv([], {} as any);

await launchCommandInstance.run();

Expand All @@ -73,7 +64,7 @@ describe('Run', () => {
.mockResolvedValueOnce(undefined);
BaseCommand.prototype['sharedConfig'] = { provider: 'OtherProvider', isExistingProject: true } as any;
BaseCommand.prototype['flags'] = { init: false };
launchCommandInstance = new Launch([], {} as any);
launchCommandInstance = new LaunchWithArgv([], {} as any);

await launchCommandInstance.run();

Expand All @@ -89,7 +80,7 @@ describe('Run', () => {
BaseCommand.prototype['sharedConfig'] = { provider: 'GitHub', isExistingProject: false } as any;
BaseCommand.prototype['flags'] = { init: false };
(cliux.inquire as jest.Mock).mockResolvedValueOnce('GitHub');
launchCommandInstance = new Launch([], {} as any);
launchCommandInstance = new LaunchWithArgv([], {} as any);

await launchCommandInstance.run();

Expand All @@ -111,7 +102,7 @@ describe('Run', () => {
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);
launchCommandInstance = new LaunchWithArgv([], {} as any);

await launchCommandInstance.run();

Expand Down
94 changes: 94 additions & 0 deletions src/test/mocks/cli-utilities.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import { Args, Command, Errors, Flags, Interfaces } from '@oclif/core';

class CLIError extends Error {}

export const launchCommand = {
Args,
Command,
Errors,
Flags,
Interfaces,
CLIError,
cliux: {
inquire: jest.fn(),
print: jest.fn(),
loader: jest.fn(),
registerSearchPlugin: jest.fn(),
},
configHandler: { get: jest.fn() },
authHandler: {
compareOAuthExpiry: jest.fn().mockResolvedValue(undefined),
host: '',
},
HttpClient: jest.fn(),
ContentstackClient: jest.fn(),
isAuthenticated: jest.fn().mockReturnValue(true),
managementSDKClient: jest.fn(),
managementSDKInitiator: jest.fn(),
};

export const fileUploadAdapter = {
cliux: {
inquire: jest.fn(),
loader: jest.fn(),
print: jest.fn(),
registerSearchPlugin: jest.fn(),
confirm: jest.fn(),
prompt: jest.fn(),
styledJSON: jest.fn(),
table: jest.fn(),
},
configHandler: { get: jest.fn() },
HttpClient: jest.fn(),
ContentstackClient: jest.fn(),
authHandler: {
compareOAuthExpiry: jest.fn().mockResolvedValue(undefined),
host: '',
},
};

export const githubAdapter = {
cliux: {
inquire: jest.fn(),
print: jest.fn(),
loader: jest.fn(),
registerSearchPlugin: jest.fn(),
confirm: jest.fn(),
prompt: jest.fn(),
styledJSON: jest.fn(),
table: jest.fn(),
},
configHandler: { get: jest.fn() },
ContentstackClient: jest.fn(),
authHandler: {
compareOAuthExpiry: jest.fn().mockResolvedValue(undefined),
host: '',
},
};

export const baseClassAdapter = {
cliux: {
inquire: jest.fn(),
table: jest.fn(),
print: jest.fn(),
loader: jest.fn(),
registerSearchPlugin: jest.fn(),
confirm: jest.fn(),
prompt: jest.fn(),
styledJSON: jest.fn(),
},
ContentstackClient: jest.fn(),
configHandler: { get: jest.fn() },
authHandler: {
compareOAuthExpiry: jest.fn().mockResolvedValue(undefined),
host: '',
},
};

export const functionsCommand = {};

export const logPolling = {
cliux: {
loaderV2: jest.fn(() => ({})),
},
};
4 changes: 4 additions & 0 deletions src/util/logs-polling-utilities.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { logPolling as cliUtilitiesJestMock } from '../test/mocks/cli-utilities';

type LogPollingCtor = typeof import('./logs-polling-utilities').default;

jest.mock('@contentstack/cli-utilities', () => cliUtilitiesJestMock);
Comment thread
SakshiKoli-CS marked this conversation as resolved.

const CONFIG = {
deployment: 'd1',
environment: 'e1',
Expand Down
3 changes: 3 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,8 @@
},
"include": [
"src/**/*"
],
"exclude": [
"src/test/**"
]
}
Loading