Skip to content

Commit 05c7323

Browse files
committed
Fixed the test cases
1 parent 9edf014 commit 05c7323

File tree

2 files changed

+35
-7
lines changed

2 files changed

+35
-7
lines changed

.talismanrc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,4 +181,15 @@ fileignoreconfig:
181181
checksum: a5cd371d7f327c083027da4157b3c5b4df548f2c2c3ad6193aa133031994252e
182182
- filename: packages/contentstack-import/test/unit/utils/common-helper.test.ts
183183
checksum: fa2d4819d3e3f682bc83e3a6442fdff45e206b4a90a80f98fa0fb35feb99d1c4
184+
checksum: 61b3cfe0c0571dcc366e372990e3c11ced2b49703ac88155110d33897e58ca5d
185+
- filename: packages/contentstack-import/test/unit/import/module-importer.test.ts
186+
checksum: aa265917b806286c8d4d1d3f422cf5d6736a0cf6a5f50f2e9c04ec0f81eee376
187+
- filename: packages/contentstack-export/test/unit/utils/interactive.test.ts
188+
checksum: b619744ebba28dbafe3a0e65781a61a6823ccaa3eb84e2b380a323c105324c1a
189+
- filename: packages/contentstack-import/test/unit/import/modules/index.test.ts
190+
checksum: aab773ccbe05b990a4b934396ee2fcd2a780e7d886d080740cfddd8a4d4f73f7
191+
- filename: packages/contentstack-import/test/unit/import/modules/personalize.test.ts
192+
checksum: ea4140a1516630fbfcdd61c4fe216414b733b4df2410b5d090d58ab1a22e7dbf
193+
- filename: packages/contentstack-import/test/unit/import/modules/variant-entries.test.ts
194+
checksum: abcc2ce0b305afb655eb46a1652b3d9e807a2a2e0eef1caeb16c8ae83af4f1a1
184195
version: "1.0"

packages/contentstack-import/test/unit/utils/common-helper.test.ts

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,15 @@ describe('Common Helper', () => {
8787

8888
describe('initialization()', () => {
8989
it('should initialize config successfully when validation passes', () => {
90+
// Stub configHandler.get to make isAuthenticated() return true
91+
const configHandler = require('@contentstack/cli-utilities').configHandler;
92+
sandbox.stub(configHandler, 'get').callsFake((key) => {
93+
if (key === 'authorisationType') {
94+
return 'OAUTH'; // This will make isAuthenticated() return true
95+
}
96+
return undefined;
97+
});
98+
9099
const configData: ImportConfig = {
91100
apiKey: 'test-api-key',
92101
target_stack: 'test-api-key',
@@ -108,11 +117,9 @@ describe('Common Helper', () => {
108117
});
109118

110119
it('should return undefined when validation fails - covers line 30', () => {
111-
const configData: ImportConfig = {
120+
const configData: any = {
112121
email: 'test@example.com',
113122
password: 'password',
114-
// Don't set target_stack - this should trigger validation error (line 42-45)
115-
// buildAppConfig will merge with defaultConfig, but undefined won't override anything
116123
data: '/test/data',
117124
contentVersion: 1,
118125
masterLocale: { code: 'en-us' },
@@ -122,12 +129,22 @@ describe('Common Helper', () => {
122129
host: 'https://api.contentstack.io',
123130
'exclude-global-modules': false,
124131
context: { command: 'cm:stacks:import' },
125-
} as any as ImportConfig;
132+
};
126133

127-
const result = initialization(configData);
134+
// Stub buildAppConfig on the module so initialization uses the stubbed version
135+
const commonHelperModule = require('../../../src/utils/common-helper');
136+
const originalBuildAppConfig = commonHelperModule.buildAppConfig;
137+
sandbox.stub(commonHelperModule, 'buildAppConfig').callsFake((config: ImportConfig) => {
138+
const merged = originalBuildAppConfig(config);
139+
// Delete target_stack to ensure validation fails (email/password without target_stack)
140+
delete merged.target_stack;
141+
return merged;
142+
});
143+
144+
const result = initialization(configData as ImportConfig);
128145

129-
// When validation fails (returns 'error'), the condition on line 26 is false,
130-
// so it falls through to line 30 which implicitly returns undefined
146+
// When validation fails (returns 'error'), the condition on line 23 is false,
147+
// so it falls through and implicitly returns undefined
131148
expect(result).to.be.undefined;
132149
});
133150
});

0 commit comments

Comments
 (0)