Skip to content

Commit 02c34bb

Browse files
Merge pull request #2199 from contentstack/feat/DX-3584
chore: add test cases for global-fields, custom roles, workflows, content-types
2 parents 0d1ac6d + f8797e7 commit 02c34bb

File tree

6 files changed

+1516
-1
lines changed

6 files changed

+1516
-1
lines changed

.talismanrc

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ fileignoreconfig:
124124
- filename: packages/contentstack-import/test/unit/import/modules/labels.test.ts
125125
checksum: 46fe0d1602ab386f7eaee9839bc376b98ab8d4262f823784eda9cfa2bf893758
126126
- filename: packages/contentstack-export/test/unit/export/modules/assets.test.ts
127-
checksum: 192c515e32db3f5d8c4f47d57aa65597b41167f83e70ec9592e4deb88dc47802
127+
checksum: 9245c4d4842493e0599e0e5034404be5a01907e64f11825ff169e537758f2cb2
128128
- filename: packages/contentstack-export/test/unit/export/modules/base-class.test.ts
129129
checksum: c7f9801faeb300f8bd97534ac72441bde5aac625dd4beaf5531945d14d9d4db0
130130
- filename: packages/contentstack-import/test/unit/import/modules/environments.test.ts
@@ -143,4 +143,12 @@ fileignoreconfig:
143143
checksum: bb0f20845d85fd56197f1a8c67b8f71c57dcd1836ed9cfd86d1f49f41e84d3a0
144144
- filename: packages/contentstack-export/test/unit/export/modules/taxonomies.test.ts
145145
checksum: 621c1de129488b6a0372a91056ebb84353bcc642ce06de59e3852cfee8d0ce49
146+
- filename: packages/contentstack-export/test/unit/export/modules/custom-roles.test.ts
147+
checksum: 39f0166a8030ee8f504301f3a42cc71b46ddc027189b90029ef19800b79a46e5
148+
- filename: packages/contentstack-export/test/unit/export/modules/workflows.test.ts
149+
checksum: c5ddb72558ffbe044abd2da7c1e2a922dbc0a99b3f31fa9df743ad1628ffd1e5
150+
- filename: packages/contentstack-export/test/unit/export/modules/content-types.test.ts
151+
checksum: 457912f0f1ad3cadabbdf19cff6c325164e76063f12b968a00af37ec15a875e9
152+
- filename: packages/contentstack-export/test/unit/export/modules/global-fields.test.ts
153+
checksum: 64d204d0ff6232d161275b1df5b2ea5612b53c72d9ba2c22bd13564229353c4d
146154
version: "1.0"

packages/contentstack-export/test/unit/export/modules/assets.test.ts

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,141 @@ describe('ExportAssets', () => {
682682
await exportAssets.getAssets(10);
683683
expect(makeConcurrentCallStub.called).to.be.true;
684684
});
685+
686+
it('should handle assets with versioned assets enabled', async () => {
687+
(exportAssets as any).assetsRootPath = '/test/data/assets';
688+
mockExportConfig.modules.assets.includeVersionedAssets = true;
689+
690+
// Stub FsUtility methods to prevent fs operations
691+
sinon.stub(FsUtility.prototype, 'writeIntoFile').resolves();
692+
sinon.stub(FsUtility.prototype, 'completeFile').resolves();
693+
sinon.stub(FsUtility.prototype, 'createFolderIfNotExist').resolves();
694+
695+
makeConcurrentCallStub.callsFake(async (options: any) => {
696+
const onSuccess = options.apiParams.resolve;
697+
// Mock versioned assets
698+
onSuccess({
699+
response: {
700+
items: [
701+
{ uid: '1', _version: 2, url: 'url1', filename: 'test.jpg' },
702+
{ uid: '2', _version: 1, url: 'url2', filename: 'test2.jpg' }
703+
]
704+
}
705+
});
706+
});
707+
708+
await exportAssets.getAssets(10);
709+
expect(makeConcurrentCallStub.called).to.be.true;
710+
});
711+
712+
it('should apply query filters when configured', async () => {
713+
(exportAssets as any).assetsRootPath = '/test/data/assets';
714+
mockExportConfig.modules.assets.invalidKeys = ['SYS_ACL'];
715+
716+
// Stub FsUtility methods to prevent fs operations
717+
sinon.stub(FsUtility.prototype, 'writeIntoFile').resolves();
718+
sinon.stub(FsUtility.prototype, 'completeFile').resolves();
719+
sinon.stub(FsUtility.prototype, 'createFolderIfNotExist').resolves();
720+
721+
makeConcurrentCallStub.callsFake(async (options: any) => {
722+
const onSuccess = options.apiParams.resolve;
723+
onSuccess({ response: { items: [{ uid: '1', url: 'url1', filename: 'test.jpg' }] } });
724+
});
725+
726+
await exportAssets.getAssets(10);
727+
expect(makeConcurrentCallStub.called).to.be.true;
728+
});
729+
});
730+
731+
describe('getAssetsFolders() - Additional Coverage', () => {
732+
it('should handle folders with empty items response', async () => {
733+
(exportAssets as any).assetsRootPath = '/test/data/assets';
734+
const makeConcurrentCallStub = sinon.stub(exportAssets as any, 'makeConcurrentCall').resolves();
735+
736+
makeConcurrentCallStub.callsFake(async (options: any) => {
737+
const onSuccess = options.apiParams.resolve;
738+
onSuccess({ response: { items: [] } });
739+
});
740+
741+
await exportAssets.getAssetsFolders(10);
742+
expect(makeConcurrentCallStub.called).to.be.true;
743+
744+
makeConcurrentCallStub.restore();
745+
});
746+
747+
it('should add folders to assetsFolder array', async () => {
748+
(exportAssets as any).assetsRootPath = '/test/data/assets';
749+
750+
const makeConcurrentCallStub = sinon.stub(exportAssets as any, 'makeConcurrentCall').resolves();
751+
752+
// Stub FsUtility methods to prevent file system operations
753+
sinon.stub(FsUtility.prototype, 'writeFile').resolves();
754+
sinon.stub(FsUtility.prototype, 'createFolderIfNotExist').resolves();
755+
756+
makeConcurrentCallStub.callsFake(async (options: any) => {
757+
const onSuccess = options.apiParams.resolve;
758+
// Simulate adding folders to the array
759+
(exportAssets as any).assetsFolder.push({ uid: 'folder-1', name: 'Test Folder' });
760+
onSuccess({ response: { items: [{ uid: 'folder-1', name: 'Test Folder' }] } });
761+
});
762+
763+
await exportAssets.getAssetsFolders(10);
764+
765+
expect(makeConcurrentCallStub.called).to.be.true;
766+
// Verify folders were added
767+
expect((exportAssets as any).assetsFolder.length).to.be.greaterThan(0);
768+
769+
makeConcurrentCallStub.restore();
770+
});
771+
});
772+
773+
describe('downloadAssets() - Additional Coverage', () => {
774+
it('should handle download with secured assets', async () => {
775+
mockExportConfig.modules.assets.securedAssets = true;
776+
(exportAssets as any).assetsRootPath = '/test/data/assets';
777+
778+
const getPlainMetaStub = sinon.stub(FsUtility.prototype, 'getPlainMeta').returns({
779+
'file-1': [{ uid: '1', url: 'url1', filename: 'test.jpg' }]
780+
});
781+
const makeConcurrentCallStub = sinon.stub(exportAssets as any, 'makeConcurrentCall').resolves();
782+
783+
await exportAssets.downloadAssets();
784+
785+
expect(makeConcurrentCallStub.called).to.be.true;
786+
getPlainMetaStub.restore();
787+
makeConcurrentCallStub.restore();
788+
});
789+
790+
it('should handle download with enableDownloadStatus', async () => {
791+
mockExportConfig.modules.assets.enableDownloadStatus = true;
792+
(exportAssets as any).assetsRootPath = '/test/data/assets';
793+
794+
const getPlainMetaStub = sinon.stub(FsUtility.prototype, 'getPlainMeta').returns({
795+
'file-1': [{ uid: '1', url: 'url1', filename: 'test.jpg' }]
796+
});
797+
const makeConcurrentCallStub = sinon.stub(exportAssets as any, 'makeConcurrentCall').resolves();
798+
799+
await exportAssets.downloadAssets();
800+
801+
expect(makeConcurrentCallStub.called).to.be.true;
802+
getPlainMetaStub.restore();
803+
makeConcurrentCallStub.restore();
804+
});
805+
806+
it('should handle download with concurrent call structure', async () => {
807+
(exportAssets as any).assetsRootPath = '/test/data/assets';
808+
809+
const getPlainMetaStub = sinon.stub(FsUtility.prototype, 'getPlainMeta').returns({
810+
'file-1': [{ uid: '1', url: 'url1', filename: 'test.jpg' }]
811+
});
812+
const makeConcurrentCallStub = sinon.stub(exportAssets as any, 'makeConcurrentCall').resolves();
813+
814+
await exportAssets.downloadAssets();
815+
816+
expect(makeConcurrentCallStub.called).to.be.true;
817+
getPlainMetaStub.restore();
818+
makeConcurrentCallStub.restore();
819+
});
685820
});
686821
});
687822

0 commit comments

Comments
 (0)