Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
updated import test cases
  • Loading branch information
naman-contentstack committed Dec 4, 2025
commit 7ecdfac2ec96a3e24b4b44506c16d7dd6f54abce
2 changes: 1 addition & 1 deletion .talismanrc
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ fileignoreconfig:
- filename: packages/contentstack-audit/src/modules/content-types.ts
checksum: ddf7b08e6a80af09c6a7019a637c26089fb76572c7c3d079a8af244b02985f16
- filename: packages/contentstack-import/test/unit/commands/cm/stacks/import.test.ts
checksum: b11e57f1b824d405f86438e9e7c59183f8c59b66b42d8d16dbeaf76195a30548
checksum: ead3c34bad34f912d8663599273d26a95bb48220e16d9e9e3d33f5c064a487a5
- filename: packages/contentstack-import/test/unit/utils/asset-helper.test.ts
checksum: 8e83200ac8028f9289ff1bd3a50d191b35c8e28f1854141c90fa1b0134d6bf8a
- filename: packages/contentstack-import/test/unit/import/modules/marketplace-apps.test.ts
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from 'chai';
import { fancy } from 'fancy-test';
import sinon from 'sinon';
import { managementSDKClient, configHandler, log, handleAndLogError, getLogPath } from '@contentstack/cli-utilities';
import { managementSDKClient, configHandler, log, handleAndLogError, getLogPath, createLogContext } from '@contentstack/cli-utilities';
import ImportCommand from '../../../../../src/commands/cm/stacks/import';
import { ModuleImporter } from '../../../../../src/import';
import { ImportConfig } from '../../../../../src/types';
Expand Down Expand Up @@ -201,18 +201,27 @@ describe('ImportCommand', () => {
});
});

describe('createImportContext', () => {
describe('createLogContext', () => {
let configHandlerStub: sinon.SinonStub;
let configHandlerSetStub: sinon.SinonStub;

beforeEach(() => {
configHandlerStub = sinon.stub(configHandler, 'get');
configHandlerStub.withArgs('userUid').returns('user-123');
configHandlerSetStub = sinon.stub(configHandler, 'set');
configHandlerStub.withArgs('clientId').returns('user-123');
configHandlerStub.withArgs('email').returns('[email protected]');
configHandlerStub.withArgs('sessionId').returns('test-session-123');
configHandlerStub.withArgs('oauthOrgUid').returns('org-123');
configHandlerStub.withArgs('authorisationType').returns('BASIC');
});

afterEach(() => {
configHandlerStub.restore();
configHandlerSetStub.restore();
});

it('should create context with all required properties', () => {
const context = command['createImportContext']('test', 'Basic Auth');
const context = createLogContext('cm:stacks:import', 'test', 'Basic Auth');

expect(context).to.have.property('command', 'cm:stacks:import');
expect(context).to.have.property('module', '');
Expand All @@ -222,10 +231,11 @@ describe('ImportCommand', () => {
expect(context).to.have.property('apiKey', 'test');
expect(context).to.have.property('orgId', 'org-123');
expect(context).to.have.property('authenticationMethod', 'Basic Auth');
expect(configHandlerSetStub.calledWith('apiKey', 'test')).to.be.true;
});

it('should use default authentication method when not provided', () => {
const context = command['createImportContext']('test');
const context = createLogContext('cm:stacks:import', 'test');

expect(context.authenticationMethod).to.equal('Basic Auth');
});
Expand All @@ -234,22 +244,22 @@ describe('ImportCommand', () => {
configHandlerStub.reset();
configHandlerStub.returns(undefined);

const context = command['createImportContext']('test', 'Management Token');
const context = createLogContext('cm:stacks:import', 'test', 'Management Token');

expect(context.userId).to.equal('');
expect(context.email).to.equal('');
expect(context.orgId).to.equal('');
expect(context.authenticationMethod).to.equal('Management Token');
});

it('should use context command when available', () => {
const context = command['createImportContext']('test');
it('should use provided command', () => {
const context = createLogContext('cm:stacks:import', 'test');

expect(context.command).to.equal('cm:stacks:import');
});

it('should handle empty apiKey', () => {
const context = command['createImportContext']('');
const context = createLogContext('cm:stacks:import', '');

expect(context.apiKey).to.equal('');
});
Expand Down Expand Up @@ -503,35 +513,43 @@ describe('ImportCommand', () => {
configHandlerStub = sinon.stub(configHandler, 'get');
});

it('should handle undefined context', () => {
(command as any).context = undefined;
afterEach(() => {
configHandlerStub.restore();
});

it('should handle command string directly', () => {
configHandlerStub.returns(undefined);

const context = command['createImportContext']('test');
const context = createLogContext('cm:stacks:import', 'test');

expect(context.command).to.equal('cm:stacks:import');
});

it('should handle context without info', () => {
(command as any).context = { sessionId: 'test-session' };
it('should use command string when provided', () => {
configHandlerStub.withArgs('clientId').returns('user-123');
configHandlerStub.withArgs('email').returns('[email protected]');
configHandlerStub.withArgs('sessionId').returns('test-session');
configHandlerStub.withArgs('oauthOrgUid').returns('org-123');
configHandlerStub.withArgs('authorisationType').returns('BASIC');

const context = command['createImportContext']('test');
const context = createLogContext('cm:stacks:import', 'test');

expect(context.command).to.equal('cm:stacks:import');
expect(context.sessionId).to.equal('test-session');
});

it('should handle context without sessionId', () => {
(command as any).context = { info: { command: 'test' } };
it('should handle missing sessionId from configHandler', () => {
configHandlerStub.returns(undefined);

const context = command['createImportContext']('test');
const context = createLogContext('cm:stacks:import', 'test');

expect(context.sessionId).to.be.undefined;
expect(context.sessionId).to.equal('');
});

it('should handle configHandler throwing errors', () => {
configHandlerStub.reset();
it('should handle configHandler returning undefined values', () => {
configHandlerStub.returns(undefined);

const context = command['createImportContext']('test');
const context = createLogContext('cm:stacks:import', 'test');

expect(context.userId).to.equal('');
expect(context.email).to.equal('');
Expand Down
Loading