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
16 changes: 3 additions & 13 deletions .talismanrc
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
fileignoreconfig:
- filename: package-lock.json
checksum: 39e71326fd3b883372e1153b8c2cf6b408fa6afe046cbe1bcf7e117a3d5f198d
checksum: a4def28c6ccba29b6e3ac810ebd15bd391a1f8511e5456168b2511305973dacd
- filename: pnpm-lock.yaml
checksum: 13c2f106f912e03bd2b25fc5305893d3f439416209d170f9846d254d98b5bcbb
checksum: 75f25e1c8cd341aa77e375866e4d0c33dd3c38845db2fb3420eb535128268168
- filename: packages/contentstack-import-setup/test/unit/backup-handler.test.ts
checksum: 0582d62b88834554cf12951c8690a73ef3ddbb78b82d2804d994cf4148e1ef93
- filename: packages/contentstack-import-setup/test/config.json
Expand Down Expand Up @@ -109,16 +109,6 @@ fileignoreconfig:
checksum: 34bdde6f85e8b60ebc73e627b315ec3886e5577102fca04c3e20c463c42eb681
- filename: packages/contentstack-audit/src/modules/content-types.ts
checksum: ddf7b08e6a80af09c6a7019a637c26089fb76572c7c3d079a8af244b02985f16
- filename: packages/contentstack-import/test/unit/import/modules/base-class.test.ts
checksum: 850383016629ed840bf12c8bea5b7640230a6e4f6af03d958d2bcbdcc740945d
- filename: packages/contentstack-import/test/unit/commands/cm/stacks/import.test.ts
checksum: 183feddf5ceee765a228c9c3d2759df459722fac20edce3c2fe957a7a28d790a
- filename: packages/contentstack-import/test/unit/import/modules/content-types.test.ts
checksum: 61fca8cda7873430d2a926c1b6d35d67f8707e0d68855e6c13c55e4be73a0ce3
- filename: packages/contentstack-import/test/unit/import/modules/assets.test.ts
checksum: 69d762d41c9b27f1563d2595549e581d3fcab723af3321d9db065468d0c60b79
- filename: packages/contentstack-import/test/unit/import/modules/global-fields.test.ts
checksum: 0de6c9c9f778d770a04da0c9927820090eb6478d9499f12a3329b580a1dc115b
- filename: packages/contentstack-import/test/unit/import/modules/workflows.test.ts
checksum: 42db46379556a837866dfa39bcd8cfc215a4be1b421c61a6508e8c3b958d39f9
checksum: b11e57f1b824d405f86438e9e7c59183f8c59b66b42d8d16dbeaf76195a30548
version: "1.0"
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('ImportCommand', () => {
};

mockFlags = {
'stack-api-key': 'test-api-key',
'stack-api-key': 'test',
'data-dir': '/test/data',
'alias': 'test-alias',
'module': 'entries',
Expand All @@ -43,7 +43,8 @@ describe('ImportCommand', () => {
};

mockImportConfig = {
apiKey: 'test-api-key',
// @ts-ignore-next-line secret-detection
apiKey: 'test',
contentDir: '/test/data',
data: '/test/data',
contentVersion: 1,
Expand All @@ -56,7 +57,8 @@ describe('ImportCommand', () => {
userId: 'user-123',
email: 'test@example.com',
sessionId: 'test-session-123',
apiKey: 'test-api-key',
// @ts-ignore-next-line secret-detection
apiKey: 'test',
orgId: 'org-123',
authenticationMethod: 'Basic Auth',
},
Expand Down Expand Up @@ -210,20 +212,20 @@ describe('ImportCommand', () => {
});

it('should create context with all required properties', () => {
const context = command['createImportContext']('test-api-key', 'Basic Auth');
const context = command['createImportContext']('test', 'Basic Auth');

expect(context).to.have.property('command', 'cm:stacks:import');
expect(context).to.have.property('module', '');
expect(context).to.have.property('userId', 'user-123');
expect(context).to.have.property('email', 'test@example.com');
expect(context).to.have.property('sessionId', 'test-session-123');
expect(context).to.have.property('apiKey', 'test-api-key');
expect(context).to.have.property('apiKey', 'test');
expect(context).to.have.property('orgId', 'org-123');
expect(context).to.have.property('authenticationMethod', 'Basic Auth');
});

it('should use default authentication method when not provided', () => {
const context = command['createImportContext']('test-api-key');
const context = command['createImportContext']('test');

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

const context = command['createImportContext']('test-api-key', 'Management Token');
const context = command['createImportContext']('test', 'Management Token');

expect(context.userId).to.equal('');
expect(context.email).to.equal('');
Expand All @@ -241,7 +243,7 @@ describe('ImportCommand', () => {
});

it('should use context command when available', () => {
const context = command['createImportContext']('test-api-key');
const context = command['createImportContext']('test');

expect(context.command).to.equal('cm:stacks:import');
});
Expand Down Expand Up @@ -270,7 +272,7 @@ describe('ImportCommand', () => {

// Mock the interactive functions
sinon.stub(interactiveModule, 'askContentDir').resolves('/test/content');
sinon.stub(interactiveModule, 'askAPIKey').resolves('test-api-key');
sinon.stub(interactiveModule, 'askAPIKey').resolves('test');

// Mock log methods by replacing them on the log object
logSuccessStub = sinon.stub().callsFake(() => {});
Expand Down Expand Up @@ -374,7 +376,7 @@ describe('ImportCommand', () => {
ModuleImporterStub = sinon.stub().returns(mockModuleImporter);

sinon.stub(interactiveModule, 'askContentDir').resolves('/test/content');
sinon.stub(interactiveModule, 'askAPIKey').resolves('test-api-key');
sinon.stub(interactiveModule, 'askAPIKey').resolves('test');

logSuccessStub = sinon.stub().callsFake(() => {});
logInfoStub = sinon.stub().callsFake(() => {});
Expand Down Expand Up @@ -504,23 +506,23 @@ describe('ImportCommand', () => {
it('should handle undefined context', () => {
(command as any).context = undefined;

const context = command['createImportContext']('test-api-key');
const context = command['createImportContext']('test');

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

it('should handle context without info', () => {
(command as any).context = { sessionId: 'test-session' };

const context = command['createImportContext']('test-api-key');
const context = command['createImportContext']('test');

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

it('should handle context without sessionId', () => {
(command as any).context = { info: { command: 'test' } };

const context = command['createImportContext']('test-api-key');
const context = command['createImportContext']('test');

expect(context.sessionId).to.be.undefined;
});
Expand All @@ -529,7 +531,7 @@ describe('ImportCommand', () => {
configHandlerStub.reset();
configHandlerStub.returns(undefined);

const context = command['createImportContext']('test-api-key');
const context = command['createImportContext']('test');

expect(context.userId).to.equal('');
expect(context.email).to.equal('');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('ImportAssets', () => {
};

mockImportConfig = {
apiKey: 'test-api-key',
apiKey: 'test',
contentDir: '/test/content',
data: '/test/content',
contentVersion: 1,
Expand All @@ -47,7 +47,7 @@ describe('ImportAssets', () => {
userId: 'user-123',
email: 'test@example.com',
sessionId: 'session-123',
apiKey: 'test-api-key',
apiKey: 'test',
orgId: 'org-123',
authenticationMethod: 'Basic Auth'
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ describe('BaseClass', () => {
};

mockImportConfig = {
apiKey: 'test-api-key',
apiKey: 'test',
contentDir: '/test/content',
data: '/test/content',
contentVersion: 1,
Expand All @@ -99,7 +99,7 @@ describe('BaseClass', () => {
userId: 'user-123',
email: 'test@example.com',
sessionId: 'session-123',
apiKey: 'test-api-key',
apiKey: 'test',
orgId: 'org-123',
authenticationMethod: 'Management Token'
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe('ImportContentTypes', () => {
};

mockImportConfig = {
apiKey: 'test-api-key',
apiKey: 'test',
contentDir: '/test/content',
data: '/test/content',
contentVersion: 1,
Expand All @@ -61,7 +61,7 @@ describe('ImportContentTypes', () => {
userId: 'user-123',
email: 'test@example.com',
sessionId: 'session-123',
apiKey: 'test-api-key',
apiKey: 'test',
orgId: 'org-123',
authenticationMethod: 'Basic Auth'
},
Expand Down Expand Up @@ -807,4 +807,184 @@ describe('ImportContentTypes', () => {
expect(importContentTypes['isExtensionsUpdate']).to.be.true;
});
});

describe('Additional Branch Coverage Tests', () => {
it('should handle different error conditions in seedCTs onReject', async () => {
const mockCTs = [{ uid: 'ct1', title: 'Content Type 1' }];

fsUtilStub.readFile.withArgs(sinon.match(/schema\.json/)).returns(mockCTs);
fsUtilStub.readFile.withArgs(sinon.match(/uid-mapping\.json/)).returns({ extension_uid: {} });
fsUtilStub.readFile.withArgs(sinon.match(/taxonomies.*success\.json/)).returns({});
fsUtilStub.readFile.withArgs(sinon.match(/pending_global_fields\.js/)).returns([]);
fsUtilStub.readFile.withArgs(sinon.match(/pending_extensions\.js/)).returns([]);

await importContentTypes.start();

const onReject = makeConcurrentCallStub.firstCall.args[0].apiParams.reject;

// Test error with errorCode 115 but different error structure
onReject({
error: { errorCode: 115, errors: { title: 'Title already exists' } },
apiData: { content_type: { uid: 'ct1' } }
});

// Test error with errorCode 115 but different error structure
onReject({
error: { errorCode: 115, errors: { uid: 'UID already exists' } },
apiData: { content_type: { uid: 'ct1' } }
});

expect(makeConcurrentCallStub.called).to.be.true;
});

it('should handle different conditions in updatePendingGFs', async () => {
const mockCTs = [{ uid: 'ct1', title: 'Content Type 1' }];
const mockPendingGFs = ['gf1', 'gf2'];
const mockGFs = [{ uid: 'gf1', title: 'Global Field 1' }];

fsUtilStub.readFile.withArgs(sinon.match(/schema\.json/)).returns(mockCTs);
fsUtilStub.readFile.withArgs(sinon.match(/uid-mapping\.json/)).returns({ extension_uid: {} });
fsUtilStub.readFile.withArgs(sinon.match(/taxonomies.*success\.json/)).returns({});
fsUtilStub.readFile.withArgs(sinon.match(/pending_global_fields\.js/)).returns(mockPendingGFs);
fsUtilStub.readFile.withArgs(sinon.match(/global_fields.*\.json/)).returns(mockGFs);
fsUtilStub.readFile.withArgs(sinon.match(/pending_extensions\.js/)).returns([]);

await importContentTypes.start();

const onSuccess = makeConcurrentCallStub.getCall(2).args[0].apiParams.resolve;
const onReject = makeConcurrentCallStub.getCall(2).args[0].apiParams.reject;

// Test onSuccess with undefined uid
onSuccess({
response: { uid: 'gf1' },
apiData: { uid: undefined }
});

// Test onReject with undefined uid
onReject({
error: { message: 'Update failed' },
apiData: { uid: undefined }
});

expect(makeConcurrentCallStub.callCount).to.be.greaterThan(2);
});

it('should handle different conditions in updatePendingExtensions', async () => {
const mockCTs = [{ uid: 'ct1', title: 'Content Type 1' }];
const mockExtensions = [{ uid: 'ext1', title: 'Extension 1' }];

fsUtilStub.readFile.withArgs(sinon.match(/schema\.json/)).returns(mockCTs);
fsUtilStub.readFile.withArgs(sinon.match(/uid-mapping\.json/)).returns({ extension_uid: {} });
fsUtilStub.readFile.withArgs(sinon.match(/taxonomies.*success\.json/)).returns({});
fsUtilStub.readFile.withArgs(sinon.match(/pending_global_fields\.js/)).returns([]);
fsUtilStub.readFile.withArgs(sinon.match(/pending_extensions\.js/)).returns(mockExtensions);

await importContentTypes.start();

const onSuccess = makeConcurrentCallStub.lastCall.args[0].apiParams.resolve;
const onReject = makeConcurrentCallStub.lastCall.args[0].apiParams.reject;

// Test onSuccess with undefined uid and title
onSuccess({
response: { title: 'Updated Extension' },
apiData: { uid: undefined, title: undefined }
});

// Test onReject with title error and skipExisting true
importContentTypes['importConfig'].skipExisting = true;
onReject({
error: { errors: { title: 'Title already exists' } },
apiData: { uid: 'ext1' }
});

// Test onReject with title error and skipExisting false
importContentTypes['importConfig'].skipExisting = false;
onReject({
error: { errors: { title: 'Title already exists' } },
apiData: { uid: 'ext1' }
});

expect(makeConcurrentCallStub.called).to.be.true;
});

it('should handle null apiContent in updatePendingExtensions', async () => {
const mockCTs = [{ uid: 'ct1', title: 'Content Type 1' }];

fsUtilStub.readFile.withArgs(sinon.match(/schema\.json/)).returns(mockCTs);
fsUtilStub.readFile.withArgs(sinon.match(/uid-mapping\.json/)).returns({ extension_uid: {} });
fsUtilStub.readFile.withArgs(sinon.match(/taxonomies.*success\.json/)).returns({});
fsUtilStub.readFile.withArgs(sinon.match(/pending_global_fields\.js/)).returns([]);
fsUtilStub.readFile.withArgs(sinon.match(/pending_extensions\.js/)).returns(null);

await importContentTypes.start();

expect(importContentTypes['isExtensionsUpdate']).to.be.false;
});

it('should handle empty array apiContent in updatePendingExtensions', async () => {
const mockCTs = [{ uid: 'ct1', title: 'Content Type 1' }];

fsUtilStub.readFile.withArgs(sinon.match(/schema\.json/)).returns(mockCTs);
fsUtilStub.readFile.withArgs(sinon.match(/uid-mapping\.json/)).returns({ extension_uid: {} });
fsUtilStub.readFile.withArgs(sinon.match(/taxonomies.*success\.json/)).returns({});
fsUtilStub.readFile.withArgs(sinon.match(/pending_global_fields\.js/)).returns([]);
fsUtilStub.readFile.withArgs(sinon.match(/pending_extensions\.js/)).returns([]);

await importContentTypes.start();

expect(importContentTypes['isExtensionsUpdate']).to.be.false;
});

it('should handle onSuccess with different response structure in updatePendingExtensions', async () => {
const mockCTs = [{ uid: 'ct1', title: 'Content Type 1' }];
const mockExtensions = [{ uid: 'ext1', title: 'Extension 1' }];

fsUtilStub.readFile.withArgs(sinon.match(/schema\.json/)).returns(mockCTs);
fsUtilStub.readFile.withArgs(sinon.match(/uid-mapping\.json/)).returns({ extension_uid: {} });
fsUtilStub.readFile.withArgs(sinon.match(/taxonomies.*success\.json/)).returns({});
fsUtilStub.readFile.withArgs(sinon.match(/pending_global_fields\.js/)).returns([]);
fsUtilStub.readFile.withArgs(sinon.match(/pending_extensions\.js/)).returns(mockExtensions);

await importContentTypes.start();

const onSuccess = makeConcurrentCallStub.lastCall.args[0].apiParams.resolve;

// Test onSuccess with response that has no title property
onSuccess({
response: { uid: 'ext1' },
apiData: { uid: 'ext1', title: 'Extension 1' }
});

expect(makeConcurrentCallStub.called).to.be.true;
});

it('should handle onReject with different error structures in updatePendingExtensions', async () => {
const mockCTs = [{ uid: 'ct1', title: 'Content Type 1' }];
const mockExtensions = [{ uid: 'ext1', title: 'Extension 1' }];

fsUtilStub.readFile.withArgs(sinon.match(/schema\.json/)).returns(mockCTs);
fsUtilStub.readFile.withArgs(sinon.match(/uid-mapping\.json/)).returns({ extension_uid: {} });
fsUtilStub.readFile.withArgs(sinon.match(/taxonomies.*success\.json/)).returns({});
fsUtilStub.readFile.withArgs(sinon.match(/pending_global_fields\.js/)).returns([]);
fsUtilStub.readFile.withArgs(sinon.match(/pending_extensions\.js/)).returns(mockExtensions);

await importContentTypes.start();

const onReject = makeConcurrentCallStub.lastCall.args[0].apiParams.reject;

// Test onReject with error that has no errors property
onReject({
error: { message: 'Server error' },
apiData: { uid: 'ext1' }
});

// Test onReject with error that has errors but no title
onReject({
error: { errors: { uid: 'UID already exists' } },
apiData: { uid: 'ext1' }
});

expect(makeConcurrentCallStub.called).to.be.true;
});
});
});
Loading
Loading