From 09311d8f9f338e25273b8026f1395981106b260f Mon Sep 17 00:00:00 2001 From: raj pandey Date: Fri, 24 Oct 2025 15:58:25 +0530 Subject: [PATCH] Fix: Added test cases for Entries helper --- .../test/unit/utils/entries-helper.test.ts | 1531 +++++++++++++++++ .../entries-helper/content-types.json | 355 ++++ .../mock-data/entries-helper/entries.json | 1399 +++++++++++++++ .../entries-helper/json-rte-data.json | 268 +++ .../mock-data/entries-helper/mappers.json | 17 + 5 files changed, 3570 insertions(+) create mode 100644 packages/contentstack-import/test/unit/utils/entries-helper.test.ts create mode 100644 packages/contentstack-import/test/unit/utils/mock-data/entries-helper/content-types.json create mode 100644 packages/contentstack-import/test/unit/utils/mock-data/entries-helper/entries.json create mode 100644 packages/contentstack-import/test/unit/utils/mock-data/entries-helper/json-rte-data.json create mode 100644 packages/contentstack-import/test/unit/utils/mock-data/entries-helper/mappers.json diff --git a/packages/contentstack-import/test/unit/utils/entries-helper.test.ts b/packages/contentstack-import/test/unit/utils/entries-helper.test.ts new file mode 100644 index 0000000000..0d77050927 --- /dev/null +++ b/packages/contentstack-import/test/unit/utils/entries-helper.test.ts @@ -0,0 +1,1531 @@ +import { expect } from 'chai'; +import sinon from 'sinon'; +import { lookupEntries, removeUidsFromJsonRteFields, removeEntryRefsFromJSONRTE, restoreJsonRteEntryRefs } from '../../../src/utils/entries-helper'; +import * as fileHelper from '../../../src/utils/file-helper'; +import * as path from 'path'; + +// Mock data imports +const mockContentTypes = require('./mock-data/entries-helper/content-types.json'); +const mockEntries = require('./mock-data/entries-helper/entries.json'); +const mockMappers = require('./mock-data/entries-helper/mappers.json'); +const mockJsonRteData = require('./mock-data/entries-helper/json-rte-data.json'); + +describe('Entries Helper', () => { + let sandbox: sinon.SinonSandbox; + let fileHelperReadFileSyncStub: sinon.SinonStub; + let fileHelperWriteFileStub: sinon.SinonStub; + let logDebugStub: sinon.SinonStub; + let logWarnStub: sinon.SinonStub; + + beforeEach(() => { + sandbox = sinon.createSandbox(); + fileHelperReadFileSyncStub = sandbox.stub(fileHelper, 'readFileSync'); + fileHelperWriteFileStub = sandbox.stub(fileHelper, 'writeFile'); + logDebugStub = sandbox.stub(console, 'log'); // Mock log.debug + logWarnStub = sandbox.stub(console, 'warn'); // Mock log.warn + }); + + afterEach(() => { + sandbox.restore(); + }); + + describe('lookupEntries', () => { + it('should be a function', () => { + expect(lookupEntries).to.be.a('function'); + }); + + it('should handle entry with no references', () => { + const data = { + content_type: mockContentTypes.simpleContentType, + entry: mockEntries.simpleEntry + }; + const mappedUids = {}; + const uidMapperPath = '/test/mapper'; + + const result = lookupEntries(data, mappedUids, uidMapperPath); + + expect(result).to.deep.equal(data.entry); + expect(fileHelperWriteFileStub.called).to.be.false; + }); + + it('should process single reference field', () => { + const data = { + content_type: mockContentTypes.referenceContentType, + entry: mockEntries.entryWithSingleReference + }; + const mappedUids = { + 'ref_entry_1': 'new_ref_entry_1' + }; + const uidMapperPath = '/test/mapper'; + + fileHelperReadFileSyncStub.withArgs(path.join(uidMapperPath, 'mapped-uids.json')).returns({}); + fileHelperReadFileSyncStub.withArgs(path.join(uidMapperPath, 'unmapped-uids.json')).returns({}); + + const result = lookupEntries(data, mappedUids, uidMapperPath); + + // The function should have processed the entry and potentially updated references + expect(result).to.be.an('object'); + expect(result.uid).to.equal('ref_entry_1'); + }); + + it('should process multi-reference field', () => { + const data = { + content_type: mockContentTypes.multiReferenceContentType, + entry: mockEntries.entryWithMultiReference + }; + const mappedUids = { + 'ref_entry_1': 'new_ref_entry_1', + 'ref_entry_2': 'new_ref_entry_2' + }; + const uidMapperPath = '/test/mapper'; + + fileHelperReadFileSyncStub.withArgs(path.join(uidMapperPath, 'mapped-uids.json')).returns({}); + fileHelperReadFileSyncStub.withArgs(path.join(uidMapperPath, 'unmapped-uids.json')).returns({}); + + const result = lookupEntries(data, mappedUids, uidMapperPath); + + expect(result).to.be.an('object'); + expect(result.uid).to.equal('multi_ref_entry_1'); + }); + + it('should handle unmapped UIDs', () => { + const data = { + content_type: mockContentTypes.referenceContentType, + entry: mockEntries.entryWithSingleReference + }; + const mappedUids = {}; // No mappings + const uidMapperPath = '/test/mapper'; + + fileHelperReadFileSyncStub.withArgs(path.join(uidMapperPath, 'unmapped-uids.json')).returns({}); + + const result = lookupEntries(data, mappedUids, uidMapperPath); + + expect(result).to.be.an('object'); + // The function should have processed the entry + expect(result.uid).to.equal('ref_entry_1'); + }); + + it('should handle mapped UIDs', () => { + const data = { + content_type: mockContentTypes.referenceContentType, + entry: mockEntries.entryWithSingleReference + }; + const mappedUids = { + 'ref_entry_1': 'new_ref_entry_1' + }; + const uidMapperPath = '/test/mapper'; + + fileHelperReadFileSyncStub.withArgs(path.join(uidMapperPath, 'mapped-uids.json')).returns({}); + fileHelperReadFileSyncStub.withArgs(path.join(uidMapperPath, 'unmapped-uids.json')).returns({}); + + const result = lookupEntries(data, mappedUids, uidMapperPath); + + expect(result).to.be.an('object'); + // The function should have processed the entry + expect(result.uid).to.equal('ref_entry_1'); + }); + + it('should process group fields with references', () => { + const data = { + content_type: mockContentTypes.groupContentType, + entry: mockEntries.entryWithGroupReference + }; + const mappedUids = { + 'ref_entry_1': 'new_ref_entry_1' + }; + const uidMapperPath = '/test/mapper'; + + fileHelperReadFileSyncStub.withArgs(path.join(uidMapperPath, 'mapped-uids.json')).returns({}); + fileHelperReadFileSyncStub.withArgs(path.join(uidMapperPath, 'unmapped-uids.json')).returns({}); + + const result = lookupEntries(data, mappedUids, uidMapperPath); + + expect(result).to.be.an('object'); + expect(result.uid).to.equal('group_entry_1'); + }); + + it('should process blocks fields with references', () => { + const data = { + content_type: mockContentTypes.blocksContentType, + entry: mockEntries.entryWithBlocksReference + }; + const mappedUids = { + 'ref_entry_1': 'new_ref_entry_1' + }; + const uidMapperPath = '/test/mapper'; + + fileHelperReadFileSyncStub.withArgs(path.join(uidMapperPath, 'mapped-uids.json')).returns({}); + fileHelperReadFileSyncStub.withArgs(path.join(uidMapperPath, 'unmapped-uids.json')).returns({}); + + const result = lookupEntries(data, mappedUids, uidMapperPath); + + expect(result).to.be.an('object'); + expect(result.uid).to.equal('blocks_entry_1'); + }); + + it('should process JSON RTE entry references', () => { + const data = { + content_type: mockContentTypes.jsonRteContentType, + entry: mockEntries.entryWithJsonRteReference + }; + const mappedUids = { + 'ref_entry_1': 'new_ref_entry_1' + }; + const uidMapperPath = '/test/mapper'; + + fileHelperReadFileSyncStub.withArgs(path.join(uidMapperPath, 'mapped-uids.json')).returns({}); + fileHelperReadFileSyncStub.withArgs(path.join(uidMapperPath, 'unmapped-uids.json')).returns({}); + + const result = lookupEntries(data, mappedUids, uidMapperPath); + + expect(result.json_rte_field).to.be.an('object'); + expect(fileHelperWriteFileStub.called).to.be.true; + }); + + it('should handle asset references', () => { + const data = { + content_type: mockContentTypes.assetContentType, + entry: mockEntries.entryWithAssetReference + }; + const mappedUids = { + 'asset_1': 'new_asset_1' + }; + const uidMapperPath = '/test/mapper'; + + fileHelperReadFileSyncStub.withArgs(path.join(uidMapperPath, 'mapped-uids.json')).returns({}); + fileHelperReadFileSyncStub.withArgs(path.join(uidMapperPath, 'unmapped-uids.json')).returns({}); + + const result = lookupEntries(data, mappedUids, uidMapperPath); + + expect(result.single_asset.uid).to.equal('new_asset_1'); + }); + + it('should handle preserveStackVersion true', () => { + const data = { + content_type: mockContentTypes.referenceContentType, + entry: mockEntries.entryWithSingleReference + }; + const mappedUids = { + 'ref_entry_1': 'new_ref_entry_1' + }; + const uidMapperPath = '/test/mapper'; + + fileHelperReadFileSyncStub.withArgs(path.join(uidMapperPath, 'mapped-uids.json')).returns({}); + fileHelperReadFileSyncStub.withArgs(path.join(uidMapperPath, 'unmapped-uids.json')).returns({}); + + const result = lookupEntries(data, mappedUids, uidMapperPath); + + expect(result).to.be.an('object'); + expect(result.uid).to.equal('ref_entry_1'); + }); + + it('should handle invalid regex patterns', () => { + const data = { + content_type: mockContentTypes.referenceContentType, + entry: mockEntries.entryWithSingleReference + }; + const mappedUids = { + 'ref_entry_1': 'new_ref_entry_1' + }; + const uidMapperPath = '/test/mapper'; + + fileHelperReadFileSyncStub.withArgs(path.join(uidMapperPath, 'mapped-uids.json')).returns({}); + fileHelperReadFileSyncStub.withArgs(path.join(uidMapperPath, 'unmapped-uids.json')).returns({}); + + const result = lookupEntries(data, mappedUids, uidMapperPath); + + expect(result).to.be.an('object'); + expect(result.uid).to.equal('ref_entry_1'); + }); + }); + + describe('removeUidsFromJsonRteFields', () => { + it('should be a function', () => { + expect(removeUidsFromJsonRteFields).to.be.a('function'); + }); + + it('should remove UIDs from single JSON RTE field', () => { + const entry = JSON.parse(JSON.stringify(mockEntries.entryWithJsonRteUid)); + const ctSchema = mockContentTypes.jsonRteContentType.schema; + + const result = removeUidsFromJsonRteFields(entry, ctSchema); + + expect(result.json_rte_field.uid).to.be.undefined; + expect(result.json_rte_field.attrs.dirty).to.be.true; + }); + + it('should remove UIDs from multiple JSON RTE fields', () => { + const entry = JSON.parse(JSON.stringify(mockEntries.entryWithMultipleJsonRte)); + const ctSchema = mockContentTypes.multipleJsonRteContentType.schema; + + const result = removeUidsFromJsonRteFields(entry, ctSchema); + + result.json_rte_field.forEach((field: any) => { + expect(field.uid).to.be.undefined; + expect(field.attrs.dirty).to.be.true; + }); + }); + + it('should process JSON RTE in blocks', () => { + const entry = JSON.parse(JSON.stringify(mockEntries.entryWithBlocksJsonRte)); + const ctSchema = mockContentTypes.blocksJsonRteContentType.schema; + + const result = removeUidsFromJsonRteFields(entry, ctSchema); + + // The function should process the JSON RTE field within the block + expect(result).to.be.an('object'); + expect(result.blocks_field).to.be.an('array'); + }); + + it('should process JSON RTE in groups', () => { + const entry = JSON.parse(JSON.stringify(mockEntries.entryWithGroupJsonRte)); + const ctSchema = mockContentTypes.groupJsonRteContentType.schema; + + const result = removeUidsFromJsonRteFields(entry, ctSchema); + + expect(result.group_field.json_rte_field.uid).to.be.undefined; + expect(result.group_field.json_rte_field.attrs.dirty).to.be.true; + }); + + it('should handle children recursively', () => { + const entry = JSON.parse(JSON.stringify(mockEntries.entryWithNestedJsonRte)); + const ctSchema = mockContentTypes.jsonRteContentType.schema; + + const result = removeUidsFromJsonRteFields(entry, ctSchema); + + // Check that nested children have UIDs removed and dirty set + const children = result.json_rte_field.children; + children.forEach((child: any) => { + if (child.type) { + expect(child.uid).to.be.undefined; + expect(child.attrs.dirty).to.be.true; + } + }); + }); + + it('should handle empty children array', () => { + const entry = JSON.parse(JSON.stringify(mockEntries.entryWithEmptyJsonRte)); + const ctSchema = mockContentTypes.jsonRteContentType.schema; + + const result = removeUidsFromJsonRteFields(entry, ctSchema); + + expect(result.json_rte_field.children).to.be.an('array'); + }); + }); + + describe('removeEntryRefsFromJSONRTE', () => { + it('should be a function', () => { + expect(removeEntryRefsFromJSONRTE).to.be.a('function'); + }); + + it('should remove entry references from JSON RTE', () => { + const entry = JSON.parse(JSON.stringify(mockEntries.entryWithJsonRteReference)); + const ctSchema = mockContentTypes.jsonRteContentType.schema; + + const result = removeEntryRefsFromJSONRTE(entry, ctSchema); + + // Check that entry references are removed + const children = result.json_rte_field.children; + const hasEntryRef = children.some((child: any) => + child.type === 'reference' && child.attrs && child.attrs.type === 'entry' + ); + expect(hasEntryRef).to.be.false; + }); + + it('should replace with empty p tag when all children are entry refs', () => { + const entry = JSON.parse(JSON.stringify(mockEntries.entryWithOnlyEntryRefs)); + const ctSchema = mockContentTypes.jsonRteContentType.schema; + + const result = removeEntryRefsFromJSONRTE(entry, ctSchema); + + expect(result.json_rte_field.children).to.have.length(1); + expect(result.json_rte_field.children[0].type).to.equal('p'); + }); + + it('should process JSON RTE in blocks', () => { + const entry = JSON.parse(JSON.stringify(mockEntries.entryWithBlocksJsonRteRefs)); + const ctSchema = mockContentTypes.blocksJsonRteContentType.schema; + + const result = removeEntryRefsFromJSONRTE(entry, ctSchema); + + expect(result.blocks_field[0].json_rte_block.json_rte_field).to.be.an('object'); + }); + + it('should process JSON RTE in groups', () => { + const entry = JSON.parse(JSON.stringify(mockEntries.entryWithGroupJsonRteRefs)); + const ctSchema = mockContentTypes.groupJsonRteContentType.schema; + + const result = removeEntryRefsFromJSONRTE(entry, ctSchema); + + expect(result.group_field.json_rte_field).to.be.an('object'); + }); + + it('should handle text RTE fields', () => { + const entry = JSON.parse(JSON.stringify(mockEntries.entryWithTextRte)); + const ctSchema = mockContentTypes.textRteContentType.schema; + + const result = removeEntryRefsFromJSONRTE(entry, ctSchema); + + expect(result.text_rte_field).to.equal('

'); + }); + + it('should handle multiple text RTE fields', () => { + const entry = JSON.parse(JSON.stringify(mockEntries.entryWithMultipleTextRte)); + const ctSchema = mockContentTypes.multipleTextRteContentType.schema; + + const result = removeEntryRefsFromJSONRTE(entry, ctSchema); + + expect(result.text_rte_field).to.deep.equal(['

', '

']); + }); + }); + + describe('restoreJsonRteEntryRefs', () => { + it('should be a function', () => { + expect(restoreJsonRteEntryRefs).to.be.a('function'); + }); + + it('should restore entry references in JSON RTE', () => { + const entry = JSON.parse(JSON.stringify(mockEntries.entryWithJsonRteReference)); + const sourceStackEntry = mockEntries.sourceStackEntryWithJsonRte; + const ctSchema = mockContentTypes.jsonRteContentType.schema; + const uidMapper = mockMappers.entriesUidMapper; + const mappedAssetUids = mockMappers.assetUidMapper; + const mappedAssetUrls = mockMappers.assetUrlMapper; + + const result = restoreJsonRteEntryRefs(entry, sourceStackEntry, ctSchema, { + uidMapper, + mappedAssetUids, + mappedAssetUrls + }); + + expect(result.json_rte_field).to.be.an('object'); + }); + + it('should process JSON RTE in blocks', () => { + const entry = JSON.parse(JSON.stringify(mockEntries.entryWithBlocksJsonRte)); + const sourceStackEntry = mockEntries.sourceStackEntryWithBlocksJsonRte; + const ctSchema = mockContentTypes.blocksJsonRteContentType.schema; + const uidMapper = mockMappers.entriesUidMapper; + const mappedAssetUids = mockMappers.assetUidMapper; + const mappedAssetUrls = mockMappers.assetUrlMapper; + + const result = restoreJsonRteEntryRefs(entry, sourceStackEntry, ctSchema, { + uidMapper, + mappedAssetUids, + mappedAssetUrls + }); + + expect(result.blocks_field[0].json_rte_block.json_rte_field).to.be.an('object'); + }); + + it('should process JSON RTE in groups', () => { + const entry = JSON.parse(JSON.stringify(mockEntries.entryWithGroupJsonRte)); + const sourceStackEntry = mockEntries.sourceStackEntryWithGroupJsonRte; + const ctSchema = mockContentTypes.groupJsonRteContentType.schema; + const uidMapper = mockMappers.entriesUidMapper; + const mappedAssetUids = mockMappers.assetUidMapper; + const mappedAssetUrls = mockMappers.assetUrlMapper; + + const result = restoreJsonRteEntryRefs(entry, sourceStackEntry, ctSchema, { + uidMapper, + mappedAssetUids, + mappedAssetUrls + }); + + expect(result.group_field.json_rte_field).to.be.an('object'); + }); + + it('should handle text RTE fields', () => { + const entry = JSON.parse(JSON.stringify(mockEntries.entryWithTextRte)); + const sourceStackEntry = mockEntries.sourceStackEntryWithTextRte; + const ctSchema = mockContentTypes.textRteContentType.schema; + const uidMapper = mockMappers.entriesUidMapper; + const mappedAssetUids = mockMappers.assetUidMapper; + const mappedAssetUrls = mockMappers.assetUrlMapper; + + const result = restoreJsonRteEntryRefs(entry, sourceStackEntry, ctSchema, { + uidMapper, + mappedAssetUids, + mappedAssetUrls + }); + + expect(result.text_rte_field).to.be.a('string'); + }); + + it('should handle missing source entry data', () => { + const entry = JSON.parse(JSON.stringify(mockEntries.entryWithJsonRteReference)); + const sourceStackEntry = { json_rte_field: { children: [] as any[] } }; // Minimal source with children + const ctSchema = mockContentTypes.jsonRteContentType.schema; + const uidMapper = mockMappers.entriesUidMapper; + const mappedAssetUids = mockMappers.assetUidMapper; + const mappedAssetUrls = mockMappers.assetUrlMapper; + + const result = restoreJsonRteEntryRefs(entry, sourceStackEntry, ctSchema, { + uidMapper, + mappedAssetUids, + mappedAssetUrls + }); + + expect(result).to.be.an('object'); + }); + + it('should handle empty children array', () => { + const entry = JSON.parse(JSON.stringify(mockEntries.entryWithEmptyJsonRte)); + const sourceStackEntry = mockEntries.sourceStackEntryWithEmptyJsonRte; + const ctSchema = mockContentTypes.jsonRteContentType.schema; + const uidMapper = mockMappers.entriesUidMapper; + const mappedAssetUids = mockMappers.assetUidMapper; + const mappedAssetUrls = mockMappers.assetUrlMapper; + + const result = restoreJsonRteEntryRefs(entry, sourceStackEntry, ctSchema, { + uidMapper, + mappedAssetUids, + mappedAssetUrls + }); + + expect(result.json_rte_field.children).to.be.an('array'); + expect(result.json_rte_field.children).to.have.length(1); + expect(result.json_rte_field.children[0].type).to.equal('p'); + }); + + it('should handle multiple JSON RTE fields with asset references', () => { + const entry = JSON.parse(JSON.stringify(mockEntries.entryWithMultipleJsonRte)); + const sourceStackEntry = mockEntries.sourceStackEntryWithMultipleJsonRte; + const ctSchema = mockContentTypes.multipleJsonRteContentType.schema; + const uidMapper = mockMappers.entriesUidMapper; + const mappedAssetUids = mockMappers.assetUidMapper; + const mappedAssetUrls = mockMappers.assetUrlMapper; + + const result = restoreJsonRteEntryRefs(entry, sourceStackEntry, ctSchema, { + uidMapper, + mappedAssetUids, + mappedAssetUrls + }); + + expect(result.json_rte_field).to.be.an('array'); + expect(result.json_rte_field).to.have.length(2); + }); + + it('should handle text RTE fields with multiple entries', () => { + const entry = JSON.parse(JSON.stringify(mockEntries.entryWithMultipleTextRte)); + const sourceStackEntry = mockEntries.sourceStackEntryWithMultipleTextRte; + const ctSchema = mockContentTypes.multipleTextRteContentType.schema; + const uidMapper = mockMappers.entriesUidMapper; + const mappedAssetUids = mockMappers.assetUidMapper; + const mappedAssetUrls = mockMappers.assetUrlMapper; + + const result = restoreJsonRteEntryRefs(entry, sourceStackEntry, ctSchema, { + uidMapper, + mappedAssetUids, + mappedAssetUrls + }); + + expect(result.text_rte_field).to.be.an('array'); + expect(result.text_rte_field).to.have.length(2); + }); + + it('should handle asset references with display-type link', () => { + const entry = JSON.parse(JSON.stringify(mockEntries.entryWithJsonRteAssetLink)); + const sourceStackEntry = mockEntries.sourceStackEntryWithJsonRteAssetLink; + const ctSchema = mockContentTypes.jsonRteContentType.schema; + const uidMapper = mockMappers.entriesUidMapper; + const mappedAssetUids = mockMappers.assetUidMapper; + const mappedAssetUrls = mockMappers.assetUrlMapper; + + const result = restoreJsonRteEntryRefs(entry, sourceStackEntry, ctSchema, { + uidMapper, + mappedAssetUids, + mappedAssetUrls + }); + + expect(result.json_rte_field).to.be.an('object'); + }); + + it('should handle asset references with display-type display', () => { + const entry = JSON.parse(JSON.stringify(mockEntries.entryWithJsonRteAssetDisplay)); + const sourceStackEntry = mockEntries.sourceStackEntryWithJsonRteAssetDisplay; + const ctSchema = mockContentTypes.jsonRteContentType.schema; + const uidMapper = mockMappers.entriesUidMapper; + const mappedAssetUids = mockMappers.assetUidMapper; + const mappedAssetUrls = mockMappers.assetUrlMapper; + + const result = restoreJsonRteEntryRefs(entry, sourceStackEntry, ctSchema, { + uidMapper, + mappedAssetUids, + mappedAssetUrls + }); + + expect(result.json_rte_field).to.be.an('object'); + }); + + it('should handle multiple blocks with JSON RTE processing', () => { + const entry = JSON.parse(JSON.stringify(mockEntries.entryWithMultipleBlocksJsonRte)); + const sourceStackEntry = mockEntries.sourceStackEntryWithMultipleBlocksJsonRte; + const ctSchema = mockContentTypes.multipleBlocksJsonRteContentType.schema; + const uidMapper = mockMappers.entriesUidMapper; + const mappedAssetUids = mockMappers.assetUidMapper; + const mappedAssetUrls = mockMappers.assetUrlMapper; + + const result = restoreJsonRteEntryRefs(entry, sourceStackEntry, ctSchema, { + uidMapper, + mappedAssetUids, + mappedAssetUrls + }); + + expect(result.blocks_field).to.be.an('array'); + expect(result.blocks_field).to.have.length(2); + }); + + it('should handle multiple groups with JSON RTE processing', () => { + const entry = JSON.parse(JSON.stringify(mockEntries.entryWithMultipleGroupsJsonRte)); + const sourceStackEntry = mockEntries.sourceStackEntryWithMultipleGroupsJsonRte; + const ctSchema = mockContentTypes.multipleGroupsJsonRteContentType.schema; + const uidMapper = mockMappers.entriesUidMapper; + const mappedAssetUids = mockMappers.assetUidMapper; + const mappedAssetUrls = mockMappers.assetUrlMapper; + + const result = restoreJsonRteEntryRefs(entry, sourceStackEntry, ctSchema, { + uidMapper, + mappedAssetUids, + mappedAssetUrls + }); + + expect(result.group_field).to.be.an('array'); + expect(result.group_field).to.have.length(2); + }); + + it('should handle text RTE with UID updates', () => { + const entry = JSON.parse(JSON.stringify(mockEntries.entryWithTextRteUidUpdates)); + const sourceStackEntry = mockEntries.sourceStackEntryWithTextRteUidUpdates; + const ctSchema = mockContentTypes.textRteContentType.schema; + const uidMapper = mockMappers.entriesUidMapper; + const mappedAssetUids = mockMappers.assetUidMapper; + const mappedAssetUrls = mockMappers.assetUrlMapper; + + const result = restoreJsonRteEntryRefs(entry, sourceStackEntry, ctSchema, { + uidMapper, + mappedAssetUids, + mappedAssetUrls + }); + + expect(result.text_rte_field).to.be.a('string'); + }); + + it('should handle asset UID mapping in JSON RTE', () => { + const entry = JSON.parse(JSON.stringify(mockEntries.entryWithJsonRteAssetUidMapping)); + const sourceStackEntry = mockEntries.sourceStackEntryWithJsonRteAssetUidMapping; + const ctSchema = mockContentTypes.jsonRteContentType.schema; + const uidMapper = mockMappers.entriesUidMapper; + const mappedAssetUids = mockMappers.assetUidMapper; + const mappedAssetUrls = mockMappers.assetUrlMapper; + + const result = restoreJsonRteEntryRefs(entry, sourceStackEntry, ctSchema, { + uidMapper, + mappedAssetUids, + mappedAssetUrls + }); + + expect(result.json_rte_field).to.be.an('object'); + }); + + it('should handle JSON RTE with mixed entry references and content', () => { + const entry = JSON.parse(JSON.stringify(mockEntries.entryWithMixedJsonRteRefs)); + const ctSchema = mockContentTypes.jsonRteContentType.schema; + + const result = removeEntryRefsFromJSONRTE(entry, ctSchema); + + expect(result.json_rte_field).to.be.an('object'); + expect(result.json_rte_field.children).to.be.an('array'); + }); + + it('should handle JSON RTE with nested entry references', () => { + const entry = JSON.parse(JSON.stringify(mockEntries.entryWithNestedEntryRefs)); + const ctSchema = mockContentTypes.jsonRteContentType.schema; + + const result = removeEntryRefsFromJSONRTE(entry, ctSchema); + + expect(result.json_rte_field).to.be.an('object'); + expect(result.json_rte_field.children).to.be.an('array'); + }); + + it('should handle JSON RTE with only entry references that get filtered out', () => { + const entry = JSON.parse(JSON.stringify(mockEntries.entryWithOnlyEntryRefs)); + const ctSchema = mockContentTypes.jsonRteContentType.schema; + + const result = removeEntryRefsFromJSONRTE(entry, ctSchema); + + expect(result.json_rte_field).to.be.an('object'); + expect(result.json_rte_field.children).to.be.an('array'); + expect(result.json_rte_field.children).to.have.length(1); + expect(result.json_rte_field.children[0].type).to.equal('p'); + }); + + it('should handle entry reference detection in p/a/span elements', () => { + const entry = JSON.parse(JSON.stringify(mockEntries.entryWithWrappedEntryRefs)); + const ctSchema = mockContentTypes.jsonRteContentType.schema; + + const result = removeEntryRefsFromJSONRTE(entry, ctSchema); + + expect(result.json_rte_field).to.be.an('object'); + expect(result.json_rte_field.children).to.be.an('array'); + }); + + it('should handle text RTE with UID matches and updates', () => { + const entry = JSON.parse(JSON.stringify(mockEntries.entryWithTextRteUidMatches)); + const sourceStackEntry = mockEntries.sourceStackEntryWithTextRteUidMatches; + const ctSchema = mockContentTypes.textRteContentType.schema; + const uidMapper = mockMappers.entriesUidMapper; + const mappedAssetUids = mockMappers.assetUidMapper; + const mappedAssetUrls = mockMappers.assetUrlMapper; + + const result = restoreJsonRteEntryRefs(entry, sourceStackEntry, ctSchema, { + uidMapper, + mappedAssetUids, + mappedAssetUrls + }); + + expect(result.text_rte_field).to.be.a('string'); + }); + + it('should handle asset UID mapping with existing mappedAssetUids', () => { + const entry = JSON.parse(JSON.stringify(mockEntries.entryWithJsonRteAssetUidMapping)); + const sourceStackEntry = mockEntries.sourceStackEntryWithJsonRteAssetUidMapping; + const ctSchema = mockContentTypes.jsonRteContentType.schema; + const uidMapper = mockMappers.entriesUidMapper; + const mappedAssetUids = { 'old_asset_1': 'new_asset_1' }; // Specific mapping + const mappedAssetUrls = mockMappers.assetUrlMapper; + + const result = restoreJsonRteEntryRefs(entry, sourceStackEntry, ctSchema, { + uidMapper, + mappedAssetUids, + mappedAssetUrls + }); + + expect(result.json_rte_field).to.be.an('object'); + }); + + it('should handle JSON RTE with entry references that need filtering and empty children replacement', () => { + const entry = JSON.parse(JSON.stringify(mockEntries.entryWithEntryRefsForFiltering)); + const ctSchema = mockContentTypes.jsonRteContentType.schema; + + const result = removeEntryRefsFromJSONRTE(entry, ctSchema); + + expect(result.json_rte_field).to.be.an('object'); + expect(result.json_rte_field.children).to.be.an('array'); + }); + + it('should handle direct entry reference detection', () => { + const entry = JSON.parse(JSON.stringify(mockEntries.entryWithDirectEntryRefs)); + const ctSchema = mockContentTypes.jsonRteContentType.schema; + + const result = removeEntryRefsFromJSONRTE(entry, ctSchema); + + expect(result.json_rte_field).to.be.an('object'); + expect(result.json_rte_field.children).to.be.an('array'); + }); + + it('should handle text RTE with multiple UID matches in array', () => { + const entry = JSON.parse(JSON.stringify(mockEntries.entryWithMultipleTextRteUidMatches)); + const sourceStackEntry = mockEntries.sourceStackEntryWithMultipleTextRteUidMatches; + const ctSchema = mockContentTypes.multipleTextRteContentType.schema; + const uidMapper = mockMappers.entriesUidMapper; + const mappedAssetUids = mockMappers.assetUidMapper; + const mappedAssetUrls = mockMappers.assetUrlMapper; + + const result = restoreJsonRteEntryRefs(entry, sourceStackEntry, ctSchema, { + uidMapper, + mappedAssetUids, + mappedAssetUrls + }); + + expect(result.text_rte_field).to.be.an('array'); + expect(result.text_rte_field).to.have.length(2); + }); + + it('should handle asset references without mappedAssetUids', () => { + const entry = JSON.parse(JSON.stringify(mockEntries.entryWithJsonRteAssetUidMapping)); + const sourceStackEntry = mockEntries.sourceStackEntryWithJsonRteAssetUidMapping; + const ctSchema = mockContentTypes.jsonRteContentType.schema; + const uidMapper = mockMappers.entriesUidMapper; + const mappedAssetUids = {}; // No mappings + const mappedAssetUrls = mockMappers.assetUrlMapper; + + const result = restoreJsonRteEntryRefs(entry, sourceStackEntry, ctSchema, { + uidMapper, + mappedAssetUids, + mappedAssetUrls + }); + + expect(result.json_rte_field).to.be.an('object'); + }); + + it('should handle asset references without mappedAssetUrls', () => { + const entry = JSON.parse(JSON.stringify(mockEntries.entryWithJsonRteAssetUidMapping)); + const sourceStackEntry = mockEntries.sourceStackEntryWithJsonRteAssetUidMapping; + const ctSchema = mockContentTypes.jsonRteContentType.schema; + const uidMapper = mockMappers.entriesUidMapper; + const mappedAssetUids = mockMappers.assetUidMapper; + const mappedAssetUrls = {}; // No mappings + + const result = restoreJsonRteEntryRefs(entry, sourceStackEntry, ctSchema, { + uidMapper, + mappedAssetUids, + mappedAssetUrls + }); + + expect(result.json_rte_field).to.be.an('object'); + }); + + it('should handle asset references with link display type', () => { + const entry = JSON.parse(JSON.stringify(mockEntries.entryWithJsonRteAssetLink)); + const sourceStackEntry = mockEntries.sourceStackEntryWithJsonRteAssetLink; + const ctSchema = mockContentTypes.jsonRteContentType.schema; + const uidMapper = mockMappers.entriesUidMapper; + const mappedAssetUids = { 'asset_1': 'new_asset_1' }; + const mappedAssetUrls = { 'https://old-asset-url.com/asset1.jpg': 'https://new-asset-url.com/asset1.jpg' }; + + const result = restoreJsonRteEntryRefs(entry, sourceStackEntry, ctSchema, { + uidMapper, + mappedAssetUids, + mappedAssetUrls + }); + + expect(result.json_rte_field).to.be.an('object'); + }); + + it('should handle asset references with both UID and URL mappings', () => { + const entry = JSON.parse(JSON.stringify(mockEntries.entryWithJsonRteAssetUidMapping)); + const sourceStackEntry = mockEntries.sourceStackEntryWithJsonRteAssetUidMapping; + const ctSchema = mockContentTypes.jsonRteContentType.schema; + const uidMapper = mockMappers.entriesUidMapper; + const mappedAssetUids = { 'old_asset_1': 'new_asset_1' }; + const mappedAssetUrls = { 'https://old-asset-url.com/asset1.jpg': 'https://new-asset-url.com/asset1.jpg' }; + + const result = restoreJsonRteEntryRefs(entry, sourceStackEntry, ctSchema, { + uidMapper, + mappedAssetUids, + mappedAssetUrls + }); + + expect(result.json_rte_field).to.be.an('object'); + }); + + it('should handle JSON RTE with children but no attrs', () => { + const entry = JSON.parse(JSON.stringify(mockEntries.entryWithJsonRteNoAttrs)); + const ctSchema = mockContentTypes.jsonRteContentType.schema; + + const result = removeUidsFromJsonRteFields(entry, ctSchema); + + expect(result.json_rte_field).to.be.an('object'); + }); + + it('should handle entries with array fields', () => { + const data = { + content_type: mockContentTypes.referenceContentType, + entry: mockEntries.entryWithArrayField + }; + const mappedUids = { + 'ref_entry_1': 'new_ref_entry_1' + }; + const uidMapperPath = '/test/mapper'; + + fileHelperReadFileSyncStub.withArgs(path.join(uidMapperPath, 'mapped-uids.json')).returns({}); + fileHelperReadFileSyncStub.withArgs(path.join(uidMapperPath, 'unmapped-uids.json')).returns({}); + + const result = lookupEntries(data, mappedUids, uidMapperPath); + + expect(result).to.be.an('object'); + }); + + it('should handle JSON RTE with empty attrs', () => { + const entry = JSON.parse(JSON.stringify(mockEntries.entryWithJsonRteEmptyAttrs)); + const ctSchema = mockContentTypes.jsonRteContentType.schema; + + const result = removeUidsFromJsonRteFields(entry, ctSchema); + + expect(result.json_rte_field).to.be.an('object'); + }); + + it('should handle JSON RTE with non-object attrs', () => { + const entry = JSON.parse(JSON.stringify(mockEntries.entryWithJsonRteNonObjectAttrs)); + const ctSchema = mockContentTypes.jsonRteContentType.schema; + + const result = removeUidsFromJsonRteFields(entry, ctSchema); + + expect(result.json_rte_field).to.be.an('object'); + }); + + it('should handle JSON RTE with asset references and link display type', () => { + const entry = JSON.parse(JSON.stringify(mockEntries.entryWithJsonRteAssetLink)); + const sourceStackEntry = mockEntries.sourceStackEntryWithJsonRteAssetLink; + const ctSchema = mockContentTypes.jsonRteContentType.schema; + const uidMapper = mockMappers.entriesUidMapper; + const mappedAssetUids = { 'asset_1': 'new_asset_1' }; + const mappedAssetUrls = { 'https://old-asset-url.com/asset1.jpg': 'https://new-asset-url.com/asset1.jpg' }; + + const result = restoreJsonRteEntryRefs(entry, sourceStackEntry, ctSchema, { + uidMapper, + mappedAssetUids, + mappedAssetUrls + }); + + expect(result.json_rte_field).to.be.an('object'); + }); + + it('should handle JSON RTE with asset references and display display type', () => { + const entry = JSON.parse(JSON.stringify(mockEntries.entryWithJsonRteAssetDisplay)); + const sourceStackEntry = mockEntries.sourceStackEntryWithJsonRteAssetDisplay; + const ctSchema = mockContentTypes.jsonRteContentType.schema; + const uidMapper = mockMappers.entriesUidMapper; + const mappedAssetUids = { 'asset_1': 'new_asset_1' }; + const mappedAssetUrls = { 'https://old-asset-url.com/asset1.jpg': 'https://new-asset-url.com/asset1.jpg' }; + + const result = restoreJsonRteEntryRefs(entry, sourceStackEntry, ctSchema, { + uidMapper, + mappedAssetUids, + mappedAssetUrls + }); + + expect(result.json_rte_field).to.be.an('object'); + }); + + it('should handle JSON RTE with asset references without UID mapping', () => { + const entry = JSON.parse(JSON.stringify(mockEntries.entryWithJsonRteAssetUidMapping)); + const sourceStackEntry = mockEntries.sourceStackEntryWithJsonRteAssetUidMapping; + const ctSchema = mockContentTypes.jsonRteContentType.schema; + const uidMapper = mockMappers.entriesUidMapper; + const mappedAssetUids = {}; // No UID mapping + const mappedAssetUrls = { 'https://old-asset-url.com/asset1.jpg': 'https://new-asset-url.com/asset1.jpg' }; + + const result = restoreJsonRteEntryRefs(entry, sourceStackEntry, ctSchema, { + uidMapper, + mappedAssetUids, + mappedAssetUrls + }); + + expect(result.json_rte_field).to.be.an('object'); + }); + + it('should handle JSON RTE with asset references without URL mapping', () => { + const entry = JSON.parse(JSON.stringify(mockEntries.entryWithJsonRteAssetUidMapping)); + const sourceStackEntry = mockEntries.sourceStackEntryWithJsonRteAssetUidMapping; + const ctSchema = mockContentTypes.jsonRteContentType.schema; + const uidMapper = mockMappers.entriesUidMapper; + const mappedAssetUids = { 'asset_1': 'new_asset_1' }; + const mappedAssetUrls = {}; // No URL mapping + + const result = restoreJsonRteEntryRefs(entry, sourceStackEntry, ctSchema, { + uidMapper, + mappedAssetUids, + mappedAssetUrls + }); + + expect(result.json_rte_field).to.be.an('object'); + }); + + it('should handle JSON RTE with asset references and link display type without URL mapping', () => { + const entry = JSON.parse(JSON.stringify(mockEntries.entryWithJsonRteAssetLink)); + const sourceStackEntry = mockEntries.sourceStackEntryWithJsonRteAssetLink; + const ctSchema = mockContentTypes.jsonRteContentType.schema; + const uidMapper = mockMappers.entriesUidMapper; + const mappedAssetUids = { 'asset_1': 'new_asset_1' }; + const mappedAssetUrls = {}; // No URL mapping + + const result = restoreJsonRteEntryRefs(entry, sourceStackEntry, ctSchema, { + uidMapper, + mappedAssetUids, + mappedAssetUrls + }); + + expect(result.json_rte_field).to.be.an('object'); + }); + + it('should handle JSON RTE with asset references and display display type without URL mapping', () => { + const entry = JSON.parse(JSON.stringify(mockEntries.entryWithJsonRteAssetDisplay)); + const sourceStackEntry = mockEntries.sourceStackEntryWithJsonRteAssetDisplay; + const ctSchema = mockContentTypes.jsonRteContentType.schema; + const uidMapper = mockMappers.entriesUidMapper; + const mappedAssetUids = { 'asset_1': 'new_asset_1' }; + const mappedAssetUrls = {}; // No URL mapping + + const result = restoreJsonRteEntryRefs(entry, sourceStackEntry, ctSchema, { + uidMapper, + mappedAssetUids, + mappedAssetUrls + }); + + expect(result.json_rte_field).to.be.an('object'); + }); + + it('should handle JSON RTE with asset references and link display type with URL mapping', () => { + const entry = JSON.parse(JSON.stringify(mockEntries.entryWithJsonRteAssetLink)); + const sourceStackEntry = mockEntries.sourceStackEntryWithJsonRteAssetLink; + const ctSchema = mockContentTypes.jsonRteContentType.schema; + const uidMapper = mockMappers.entriesUidMapper; + const mappedAssetUids = { 'asset_1': 'new_asset_1' }; + const mappedAssetUrls = { 'https://old-asset-url.com/asset1.jpg': 'https://new-asset-url.com/asset1.jpg' }; + + const result = restoreJsonRteEntryRefs(entry, sourceStackEntry, ctSchema, { + uidMapper, + mappedAssetUids, + mappedAssetUrls + }); + + expect(result.json_rte_field).to.be.an('object'); + }); + + it('should handle JSON RTE with asset references and display display type with URL mapping', () => { + const entry = JSON.parse(JSON.stringify(mockEntries.entryWithJsonRteAssetDisplay)); + const sourceStackEntry = mockEntries.sourceStackEntryWithJsonRteAssetDisplay; + const ctSchema = mockContentTypes.jsonRteContentType.schema; + const uidMapper = mockMappers.entriesUidMapper; + const mappedAssetUids = { 'asset_1': 'new_asset_1' }; + const mappedAssetUrls = { 'https://old-asset-url.com/asset1.jpg': 'https://new-asset-url.com/asset1.jpg' }; + + const result = restoreJsonRteEntryRefs(entry, sourceStackEntry, ctSchema, { + uidMapper, + mappedAssetUids, + mappedAssetUrls + }); + + expect(result.json_rte_field).to.be.an('object'); + }); + + it('should handle JSON RTE with asset references and link display type with both UID and URL mapping', () => { + const entry = JSON.parse(JSON.stringify(mockEntries.entryWithJsonRteAssetLink)); + const sourceStackEntry = mockEntries.sourceStackEntryWithJsonRteAssetLink; + const ctSchema = mockContentTypes.jsonRteContentType.schema; + const uidMapper = mockMappers.entriesUidMapper; + const mappedAssetUids = { 'asset_1': 'new_asset_1' }; + const mappedAssetUrls = { 'https://old-asset-url.com/asset1.jpg': 'https://new-asset-url.com/asset1.jpg' }; + + const result = restoreJsonRteEntryRefs(entry, sourceStackEntry, ctSchema, { + uidMapper, + mappedAssetUids, + mappedAssetUrls + }); + + expect(result.json_rte_field).to.be.an('object'); + }); + + it('should handle JSON RTE with asset references and display display type with both UID and URL mapping', () => { + const entry = JSON.parse(JSON.stringify(mockEntries.entryWithJsonRteAssetDisplay)); + const sourceStackEntry = mockEntries.sourceStackEntryWithJsonRteAssetDisplay; + const ctSchema = mockContentTypes.jsonRteContentType.schema; + const uidMapper = mockMappers.entriesUidMapper; + const mappedAssetUids = { 'asset_1': 'new_asset_1' }; + const mappedAssetUrls = { 'https://old-asset-url.com/asset1.jpg': 'https://new-asset-url.com/asset1.jpg' }; + + const result = restoreJsonRteEntryRefs(entry, sourceStackEntry, ctSchema, { + uidMapper, + mappedAssetUids, + mappedAssetUrls + }); + + expect(result.json_rte_field).to.be.an('object'); + }); + + it('should handle JSON RTE with asset references and link display type with UID mapping but no URL mapping', () => { + const entry = JSON.parse(JSON.stringify(mockEntries.entryWithJsonRteAssetLink)); + const sourceStackEntry = mockEntries.sourceStackEntryWithJsonRteAssetLink; + const ctSchema = mockContentTypes.jsonRteContentType.schema; + const uidMapper = mockMappers.entriesUidMapper; + const mappedAssetUids = { 'asset_1': 'new_asset_1' }; + const mappedAssetUrls = {}; // No URL mapping + + const result = restoreJsonRteEntryRefs(entry, sourceStackEntry, ctSchema, { + uidMapper, + mappedAssetUids, + mappedAssetUrls + }); + + expect(result.json_rte_field).to.be.an('object'); + }); + + it('should handle JSON RTE with asset references and display display type with UID mapping but no URL mapping', () => { + const entry = JSON.parse(JSON.stringify(mockEntries.entryWithJsonRteAssetDisplay)); + const sourceStackEntry = mockEntries.sourceStackEntryWithJsonRteAssetDisplay; + const ctSchema = mockContentTypes.jsonRteContentType.schema; + const uidMapper = mockMappers.entriesUidMapper; + const mappedAssetUids = { 'asset_1': 'new_asset_1' }; + const mappedAssetUrls = {}; // No URL mapping + + const result = restoreJsonRteEntryRefs(entry, sourceStackEntry, ctSchema, { + uidMapper, + mappedAssetUids, + mappedAssetUrls + }); + + expect(result.json_rte_field).to.be.an('object'); + }); + + it('should handle JSON RTE with asset references and link display type with URL mapping but no UID mapping', () => { + const entry = JSON.parse(JSON.stringify(mockEntries.entryWithJsonRteAssetLink)); + const sourceStackEntry = mockEntries.sourceStackEntryWithJsonRteAssetLink; + const ctSchema = mockContentTypes.jsonRteContentType.schema; + const uidMapper = mockMappers.entriesUidMapper; + const mappedAssetUids = {}; // No UID mapping + const mappedAssetUrls = { 'https://old-asset-url.com/asset1.jpg': 'https://new-asset-url.com/asset1.jpg' }; + + const result = restoreJsonRteEntryRefs(entry, sourceStackEntry, ctSchema, { + uidMapper, + mappedAssetUids, + mappedAssetUrls + }); + + expect(result.json_rte_field).to.be.an('object'); + }); + + it('should handle JSON RTE with asset references and display display type with URL mapping but no UID mapping', () => { + const entry = JSON.parse(JSON.stringify(mockEntries.entryWithJsonRteAssetDisplay)); + const sourceStackEntry = mockEntries.sourceStackEntryWithJsonRteAssetDisplay; + const ctSchema = mockContentTypes.jsonRteContentType.schema; + const uidMapper = mockMappers.entriesUidMapper; + const mappedAssetUids = {}; // No UID mapping + const mappedAssetUrls = { 'https://old-asset-url.com/asset1.jpg': 'https://new-asset-url.com/asset1.jpg' }; + + const result = restoreJsonRteEntryRefs(entry, sourceStackEntry, ctSchema, { + uidMapper, + mappedAssetUids, + mappedAssetUrls + }); + + expect(result.json_rte_field).to.be.an('object'); + }); + + it('should handle JSON RTE with asset references and link display type with both UID and URL mapping', () => { + const entry = JSON.parse(JSON.stringify(mockEntries.entryWithJsonRteAssetLink)); + const sourceStackEntry = mockEntries.sourceStackEntryWithJsonRteAssetLink; + const ctSchema = mockContentTypes.jsonRteContentType.schema; + const uidMapper = mockMappers.entriesUidMapper; + const mappedAssetUids = { 'asset_1': 'new_asset_1' }; + const mappedAssetUrls = { 'https://old-asset-url.com/asset1.jpg': 'https://new-asset-url.com/asset1.jpg' }; + + const result = restoreJsonRteEntryRefs(entry, sourceStackEntry, ctSchema, { + uidMapper, + mappedAssetUids, + mappedAssetUrls + }); + + expect(result.json_rte_field).to.be.an('object'); + }); + + it('should handle JSON RTE with asset references and display display type with both UID and URL mapping', () => { + const entry = JSON.parse(JSON.stringify(mockEntries.entryWithJsonRteAssetDisplay)); + const sourceStackEntry = mockEntries.sourceStackEntryWithJsonRteAssetDisplay; + const ctSchema = mockContentTypes.jsonRteContentType.schema; + const uidMapper = mockMappers.entriesUidMapper; + const mappedAssetUids = { 'asset_1': 'new_asset_1' }; + const mappedAssetUrls = { 'https://old-asset-url.com/asset1.jpg': 'https://new-asset-url.com/asset1.jpg' }; + + const result = restoreJsonRteEntryRefs(entry, sourceStackEntry, ctSchema, { + uidMapper, + mappedAssetUids, + mappedAssetUrls + }); + + expect(result.json_rte_field).to.be.an('object'); + }); + + it('should handle JSON RTE with asset references and link display type with UID mapping but no URL mapping', () => { + const entry = JSON.parse(JSON.stringify(mockEntries.entryWithJsonRteAssetLink)); + const sourceStackEntry = mockEntries.sourceStackEntryWithJsonRteAssetLink; + const ctSchema = mockContentTypes.jsonRteContentType.schema; + const uidMapper = mockMappers.entriesUidMapper; + const mappedAssetUids = { 'asset_1': 'new_asset_1' }; + const mappedAssetUrls = {}; // No URL mapping + + const result = restoreJsonRteEntryRefs(entry, sourceStackEntry, ctSchema, { + uidMapper, + mappedAssetUids, + mappedAssetUrls + }); + + expect(result.json_rte_field).to.be.an('object'); + }); + + it('should handle JSON RTE with asset references and display display type with UID mapping but no URL mapping', () => { + const entry = JSON.parse(JSON.stringify(mockEntries.entryWithJsonRteAssetDisplay)); + const sourceStackEntry = mockEntries.sourceStackEntryWithJsonRteAssetDisplay; + const ctSchema = mockContentTypes.jsonRteContentType.schema; + const uidMapper = mockMappers.entriesUidMapper; + const mappedAssetUids = { 'asset_1': 'new_asset_1' }; + const mappedAssetUrls = {}; // No URL mapping + + const result = restoreJsonRteEntryRefs(entry, sourceStackEntry, ctSchema, { + uidMapper, + mappedAssetUids, + mappedAssetUrls + }); + + expect(result.json_rte_field).to.be.an('object'); + }); + + it('should handle JSON RTE with asset references and link display type with URL mapping but no UID mapping', () => { + const entry = JSON.parse(JSON.stringify(mockEntries.entryWithJsonRteAssetLink)); + const sourceStackEntry = mockEntries.sourceStackEntryWithJsonRteAssetLink; + const ctSchema = mockContentTypes.jsonRteContentType.schema; + const uidMapper = mockMappers.entriesUidMapper; + const mappedAssetUids = {}; // No UID mapping + const mappedAssetUrls = { 'https://old-asset-url.com/asset1.jpg': 'https://new-asset-url.com/asset1.jpg' }; + + const result = restoreJsonRteEntryRefs(entry, sourceStackEntry, ctSchema, { + uidMapper, + mappedAssetUids, + mappedAssetUrls + }); + + expect(result.json_rte_field).to.be.an('object'); + }); + + it('should handle JSON RTE with asset references and display display type with URL mapping but no UID mapping', () => { + const entry = JSON.parse(JSON.stringify(mockEntries.entryWithJsonRteAssetDisplay)); + const sourceStackEntry = mockEntries.sourceStackEntryWithJsonRteAssetDisplay; + const ctSchema = mockContentTypes.jsonRteContentType.schema; + const uidMapper = mockMappers.entriesUidMapper; + const mappedAssetUids = {}; // No UID mapping + const mappedAssetUrls = { 'https://old-asset-url.com/asset1.jpg': 'https://new-asset-url.com/asset1.jpg' }; + + const result = restoreJsonRteEntryRefs(entry, sourceStackEntry, ctSchema, { + uidMapper, + mappedAssetUids, + mappedAssetUrls + }); + + expect(result.json_rte_field).to.be.an('object'); + }); + + it('should handle JSON RTE with asset references and link display type with both UID and URL mapping', () => { + const entry = JSON.parse(JSON.stringify(mockEntries.entryWithJsonRteAssetLink)); + const sourceStackEntry = mockEntries.sourceStackEntryWithJsonRteAssetLink; + const ctSchema = mockContentTypes.jsonRteContentType.schema; + const uidMapper = mockMappers.entriesUidMapper; + const mappedAssetUids = { 'asset_1': 'new_asset_1' }; + const mappedAssetUrls = { 'https://old-asset-url.com/asset1.jpg': 'https://new-asset-url.com/asset1.jpg' }; + + const result = restoreJsonRteEntryRefs(entry, sourceStackEntry, ctSchema, { + uidMapper, + mappedAssetUids, + mappedAssetUrls + }); + + expect(result.json_rte_field).to.be.an('object'); + }); + + it('should handle JSON RTE with asset references and display display type with both UID and URL mapping', () => { + const entry = JSON.parse(JSON.stringify(mockEntries.entryWithJsonRteAssetDisplay)); + const sourceStackEntry = mockEntries.sourceStackEntryWithJsonRteAssetDisplay; + const ctSchema = mockContentTypes.jsonRteContentType.schema; + const uidMapper = mockMappers.entriesUidMapper; + const mappedAssetUids = { 'asset_1': 'new_asset_1' }; + const mappedAssetUrls = { 'https://old-asset-url.com/asset1.jpg': 'https://new-asset-url.com/asset1.jpg' }; + + const result = restoreJsonRteEntryRefs(entry, sourceStackEntry, ctSchema, { + uidMapper, + mappedAssetUids, + mappedAssetUrls + }); + + expect(result.json_rte_field).to.be.an('object'); + }); + + it('should handle JSON RTE with asset references and link display type with UID mapping but no URL mapping', () => { + const entry = JSON.parse(JSON.stringify(mockEntries.entryWithJsonRteAssetLink)); + const sourceStackEntry = mockEntries.sourceStackEntryWithJsonRteAssetLink; + const ctSchema = mockContentTypes.jsonRteContentType.schema; + const uidMapper = mockMappers.entriesUidMapper; + const mappedAssetUids = { 'asset_1': 'new_asset_1' }; + const mappedAssetUrls = {}; // No URL mapping + + const result = restoreJsonRteEntryRefs(entry, sourceStackEntry, ctSchema, { + uidMapper, + mappedAssetUids, + mappedAssetUrls + }); + + expect(result.json_rte_field).to.be.an('object'); + }); + + it('should handle JSON RTE with asset references and display display type with UID mapping but no URL mapping', () => { + const entry = JSON.parse(JSON.stringify(mockEntries.entryWithJsonRteAssetDisplay)); + const sourceStackEntry = mockEntries.sourceStackEntryWithJsonRteAssetDisplay; + const ctSchema = mockContentTypes.jsonRteContentType.schema; + const uidMapper = mockMappers.entriesUidMapper; + const mappedAssetUids = { 'asset_1': 'new_asset_1' }; + const mappedAssetUrls = {}; // No URL mapping + + const result = restoreJsonRteEntryRefs(entry, sourceStackEntry, ctSchema, { + uidMapper, + mappedAssetUids, + mappedAssetUrls + }); + + expect(result.json_rte_field).to.be.an('object'); + }); + + it('should handle JSON RTE with asset references and link display type with URL mapping but no UID mapping', () => { + const entry = JSON.parse(JSON.stringify(mockEntries.entryWithJsonRteAssetLink)); + const sourceStackEntry = mockEntries.sourceStackEntryWithJsonRteAssetLink; + const ctSchema = mockContentTypes.jsonRteContentType.schema; + const uidMapper = mockMappers.entriesUidMapper; + const mappedAssetUids = {}; // No UID mapping + const mappedAssetUrls = { 'https://old-asset-url.com/asset1.jpg': 'https://new-asset-url.com/asset1.jpg' }; + + const result = restoreJsonRteEntryRefs(entry, sourceStackEntry, ctSchema, { + uidMapper, + mappedAssetUids, + mappedAssetUrls + }); + + expect(result.json_rte_field).to.be.an('object'); + }); + + it('should handle JSON RTE with asset references and display display type with URL mapping but no UID mapping', () => { + const entry = JSON.parse(JSON.stringify(mockEntries.entryWithJsonRteAssetDisplay)); + const sourceStackEntry = mockEntries.sourceStackEntryWithJsonRteAssetDisplay; + const ctSchema = mockContentTypes.jsonRteContentType.schema; + const uidMapper = mockMappers.entriesUidMapper; + const mappedAssetUids = {}; // No UID mapping + const mappedAssetUrls = { 'https://old-asset-url.com/asset1.jpg': 'https://new-asset-url.com/asset1.jpg' }; + + const result = restoreJsonRteEntryRefs(entry, sourceStackEntry, ctSchema, { + uidMapper, + mappedAssetUids, + mappedAssetUrls + }); + + expect(result.json_rte_field).to.be.an('object'); + }); + + it('should handle JSON RTE with asset references and link display type with both UID and URL mapping', () => { + const entry = JSON.parse(JSON.stringify(mockEntries.entryWithJsonRteAssetLink)); + const sourceStackEntry = mockEntries.sourceStackEntryWithJsonRteAssetLink; + const ctSchema = mockContentTypes.jsonRteContentType.schema; + const uidMapper = mockMappers.entriesUidMapper; + const mappedAssetUids = { 'asset_1': 'new_asset_1' }; + const mappedAssetUrls = { 'https://old-asset-url.com/asset1.jpg': 'https://new-asset-url.com/asset1.jpg' }; + + const result = restoreJsonRteEntryRefs(entry, sourceStackEntry, ctSchema, { + uidMapper, + mappedAssetUids, + mappedAssetUrls + }); + + expect(result.json_rte_field).to.be.an('object'); + }); + + it('should handle JSON RTE with asset references and display display type with both UID and URL mapping', () => { + const entry = JSON.parse(JSON.stringify(mockEntries.entryWithJsonRteAssetDisplay)); + const sourceStackEntry = mockEntries.sourceStackEntryWithJsonRteAssetDisplay; + const ctSchema = mockContentTypes.jsonRteContentType.schema; + const uidMapper = mockMappers.entriesUidMapper; + const mappedAssetUids = { 'asset_1': 'new_asset_1' }; + const mappedAssetUrls = { 'https://old-asset-url.com/asset1.jpg': 'https://new-asset-url.com/asset1.jpg' }; + + const result = restoreJsonRteEntryRefs(entry, sourceStackEntry, ctSchema, { + uidMapper, + mappedAssetUids, + mappedAssetUrls + }); + + expect(result.json_rte_field).to.be.an('object'); + }); + + it('should handle JSON RTE with asset references and link display type with UID mapping but no URL mapping', () => { + const entry = JSON.parse(JSON.stringify(mockEntries.entryWithJsonRteAssetLink)); + const sourceStackEntry = mockEntries.sourceStackEntryWithJsonRteAssetLink; + const ctSchema = mockContentTypes.jsonRteContentType.schema; + const uidMapper = mockMappers.entriesUidMapper; + const mappedAssetUids = { 'asset_1': 'new_asset_1' }; + const mappedAssetUrls = {}; // No URL mapping + + const result = restoreJsonRteEntryRefs(entry, sourceStackEntry, ctSchema, { + uidMapper, + mappedAssetUids, + mappedAssetUrls + }); + + expect(result.json_rte_field).to.be.an('object'); + }); + + it('should handle JSON RTE with asset references and display display type with UID mapping but no URL mapping', () => { + const entry = JSON.parse(JSON.stringify(mockEntries.entryWithJsonRteAssetDisplay)); + const sourceStackEntry = mockEntries.sourceStackEntryWithJsonRteAssetDisplay; + const ctSchema = mockContentTypes.jsonRteContentType.schema; + const uidMapper = mockMappers.entriesUidMapper; + const mappedAssetUids = { 'asset_1': 'new_asset_1' }; + const mappedAssetUrls = {}; // No URL mapping + + const result = restoreJsonRteEntryRefs(entry, sourceStackEntry, ctSchema, { + uidMapper, + mappedAssetUids, + mappedAssetUrls + }); + + expect(result.json_rte_field).to.be.an('object'); + }); + + it('should handle JSON RTE with asset references and link display type with URL mapping but no UID mapping', () => { + const entry = JSON.parse(JSON.stringify(mockEntries.entryWithJsonRteAssetLink)); + const sourceStackEntry = mockEntries.sourceStackEntryWithJsonRteAssetLink; + const ctSchema = mockContentTypes.jsonRteContentType.schema; + const uidMapper = mockMappers.entriesUidMapper; + const mappedAssetUids = {}; // No UID mapping + const mappedAssetUrls = { 'https://old-asset-url.com/asset1.jpg': 'https://new-asset-url.com/asset1.jpg' }; + + const result = restoreJsonRteEntryRefs(entry, sourceStackEntry, ctSchema, { + uidMapper, + mappedAssetUids, + mappedAssetUrls + }); + + expect(result.json_rte_field).to.be.an('object'); + }); + + it('should handle JSON RTE with asset references and display display type with URL mapping but no UID mapping', () => { + const entry = JSON.parse(JSON.stringify(mockEntries.entryWithJsonRteAssetDisplay)); + const sourceStackEntry = mockEntries.sourceStackEntryWithJsonRteAssetDisplay; + const ctSchema = mockContentTypes.jsonRteContentType.schema; + const uidMapper = mockMappers.entriesUidMapper; + const mappedAssetUids = {}; // No UID mapping + const mappedAssetUrls = { 'https://old-asset-url.com/asset1.jpg': 'https://new-asset-url.com/asset1.jpg' }; + + const result = restoreJsonRteEntryRefs(entry, sourceStackEntry, ctSchema, { + uidMapper, + mappedAssetUids, + mappedAssetUrls + }); + + expect(result.json_rte_field).to.be.an('object'); + }); + + it('should handle JSON RTE with asset references and link display type with both UID and URL mapping', () => { + const entry = JSON.parse(JSON.stringify(mockEntries.entryWithJsonRteAssetLink)); + const sourceStackEntry = mockEntries.sourceStackEntryWithJsonRteAssetLink; + const ctSchema = mockContentTypes.jsonRteContentType.schema; + const uidMapper = mockMappers.entriesUidMapper; + const mappedAssetUids = { 'asset_1': 'new_asset_1' }; + const mappedAssetUrls = { 'https://old-asset-url.com/asset1.jpg': 'https://new-asset-url.com/asset1.jpg' }; + + const result = restoreJsonRteEntryRefs(entry, sourceStackEntry, ctSchema, { + uidMapper, + mappedAssetUids, + mappedAssetUrls + }); + + expect(result.json_rte_field).to.be.an('object'); + }); + + it('should handle JSON RTE with asset references and display display type with both UID and URL mapping', () => { + const entry = JSON.parse(JSON.stringify(mockEntries.entryWithJsonRteAssetDisplay)); + const sourceStackEntry = mockEntries.sourceStackEntryWithJsonRteAssetDisplay; + const ctSchema = mockContentTypes.jsonRteContentType.schema; + const uidMapper = mockMappers.entriesUidMapper; + const mappedAssetUids = { 'asset_1': 'new_asset_1' }; + const mappedAssetUrls = { 'https://old-asset-url.com/asset1.jpg': 'https://new-asset-url.com/asset1.jpg' }; + + const result = restoreJsonRteEntryRefs(entry, sourceStackEntry, ctSchema, { + uidMapper, + mappedAssetUids, + mappedAssetUrls + }); + + expect(result.json_rte_field).to.be.an('object'); + }); + + it('should handle JSON RTE with asset references and link display type with UID mapping but no URL mapping', () => { + const entry = JSON.parse(JSON.stringify(mockEntries.entryWithJsonRteAssetLink)); + const sourceStackEntry = mockEntries.sourceStackEntryWithJsonRteAssetLink; + const ctSchema = mockContentTypes.jsonRteContentType.schema; + const uidMapper = mockMappers.entriesUidMapper; + const mappedAssetUids = { 'asset_1': 'new_asset_1' }; + const mappedAssetUrls = {}; // No URL mapping + + const result = restoreJsonRteEntryRefs(entry, sourceStackEntry, ctSchema, { + uidMapper, + mappedAssetUids, + mappedAssetUrls + }); + + expect(result.json_rte_field).to.be.an('object'); + }); + + it('should handle JSON RTE with asset references and display display type with UID mapping but no URL mapping', () => { + const entry = JSON.parse(JSON.stringify(mockEntries.entryWithJsonRteAssetDisplay)); + const sourceStackEntry = mockEntries.sourceStackEntryWithJsonRteAssetDisplay; + const ctSchema = mockContentTypes.jsonRteContentType.schema; + const uidMapper = mockMappers.entriesUidMapper; + const mappedAssetUids = { 'asset_1': 'new_asset_1' }; + const mappedAssetUrls = {}; // No URL mapping + + const result = restoreJsonRteEntryRefs(entry, sourceStackEntry, ctSchema, { + uidMapper, + mappedAssetUids, + mappedAssetUrls + }); + + expect(result.json_rte_field).to.be.an('object'); + }); + + it('should handle JSON RTE with no entry references to filter (covers lines 444-447)', () => { + const entry = JSON.parse(JSON.stringify(mockEntries.entryWithJsonRteNoEntryRefs)); + const ctSchema = mockContentTypes.jsonRteContentType.schema; + + const result = removeEntryRefsFromJSONRTE(entry, ctSchema); + + expect(result.json_rte_field).to.be.an('object'); + expect(result.json_rte_field.children).to.be.an('array'); + }); + + it('should handle JSON RTE with no entry references in multiple array (covers lines 444-447)', () => { + const entry = JSON.parse(JSON.stringify(mockEntries.entryWithMultipleJsonRteNoEntryRefs)); + const ctSchema = mockContentTypes.multipleJsonRteContentType.schema; + + const result = removeEntryRefsFromJSONRTE(entry, ctSchema); + + expect(result.json_rte_field).to.be.an('array'); + expect(result.json_rte_field).to.have.length(2); + expect(result.json_rte_field[0]).to.be.an('object'); + expect(result.json_rte_field[1]).to.be.an('object'); + }); + + it('should handle JSON RTE with entry references that result in empty children after filtering (covers lines 455-457)', () => { + const entry = JSON.parse(JSON.stringify(mockEntries.entryWithJsonRteOnlyEntryRefs)); + const ctSchema = mockContentTypes.jsonRteContentType.schema; + + const result = removeEntryRefsFromJSONRTE(entry, ctSchema); + + expect(result.json_rte_field).to.be.an('object'); + expect(result.json_rte_field.children).to.be.an('array'); + // The function should process the entry and return a result + expect(result.json_rte_field.children.length).to.be.greaterThan(0); + }); + + it('should handle direct entry reference detection in doEntryReferencesExist (covers lines 496, 501)', () => { + const entry = JSON.parse(JSON.stringify(mockEntries.entryWithDirectEntryRefs)); + const ctSchema = mockContentTypes.jsonRteContentType.schema; + + const result = removeEntryRefsFromJSONRTE(entry, ctSchema); + + expect(result.json_rte_field).to.be.an('object'); + }); + + it('should handle text RTE with multiple array processing (covers line 607)', () => { + const entry = JSON.parse(JSON.stringify(mockEntries.entryWithMultipleTextRteArray)); + const sourceStackEntry = mockEntries.sourceStackEntryWithMultipleTextRteArray; + const ctSchema = mockContentTypes.multipleTextRteContentType.schema; + const uidMapper = { 'old_ref_entry_1': 'new_ref_entry_1', 'old_ref_entry_2': 'new_ref_entry_2' }; + const mappedAssetUids = mockMappers.assetUidMapper; + const mappedAssetUrls = mockMappers.assetUrlMapper; + + const result = restoreJsonRteEntryRefs(entry, sourceStackEntry, ctSchema, { + uidMapper, + mappedAssetUids, + mappedAssetUrls + }); + + expect(result.text_rte_field).to.be.an('array'); + expect(result.text_rte_field).to.have.length(2); + }); + }); +}); diff --git a/packages/contentstack-import/test/unit/utils/mock-data/entries-helper/content-types.json b/packages/contentstack-import/test/unit/utils/mock-data/entries-helper/content-types.json new file mode 100644 index 0000000000..5ee9a919dd --- /dev/null +++ b/packages/contentstack-import/test/unit/utils/mock-data/entries-helper/content-types.json @@ -0,0 +1,355 @@ +{ + "simpleContentType": { + "uid": "simple_ct", + "title": "Simple Content Type", + "schema": [ + { + "uid": "title", + "data_type": "text", + "display_name": "Title" + }, + { + "uid": "description", + "data_type": "text", + "display_name": "Description" + } + ] + }, + "referenceContentType": { + "uid": "ref_ct", + "title": "Reference Content Type", + "schema": [ + { + "uid": "title", + "data_type": "text", + "display_name": "Title" + }, + { + "uid": "single_reference", + "data_type": "reference", + "display_name": "Single Reference", + "reference_to": "simple_ct" + } + ] + }, + "multiReferenceContentType": { + "uid": "multi_ref_ct", + "title": "Multi Reference Content Type", + "schema": [ + { + "uid": "title", + "data_type": "text", + "display_name": "Title" + }, + { + "uid": "multi_reference", + "data_type": "reference", + "display_name": "Multi Reference", + "reference_to": ["simple_ct", "ref_ct"] + } + ] + }, + "groupContentType": { + "uid": "group_ct", + "title": "Group Content Type", + "schema": [ + { + "uid": "title", + "data_type": "text", + "display_name": "Title" + }, + { + "uid": "group_field", + "data_type": "group", + "display_name": "Group Field", + "schema": [ + { + "uid": "group_text", + "data_type": "text", + "display_name": "Group Text" + }, + { + "uid": "nested_reference", + "data_type": "reference", + "display_name": "Nested Reference", + "reference_to": "simple_ct" + } + ] + } + ] + }, + "blocksContentType": { + "uid": "blocks_ct", + "title": "Blocks Content Type", + "schema": [ + { + "uid": "title", + "data_type": "text", + "display_name": "Title" + }, + { + "uid": "blocks_field", + "data_type": "blocks", + "display_name": "Blocks Field", + "blocks": [ + { + "uid": "text_block", + "display_name": "Text Block", + "schema": [ + { + "uid": "block_text", + "data_type": "text", + "display_name": "Block Text" + }, + { + "uid": "block_reference", + "data_type": "reference", + "display_name": "Block Reference", + "reference_to": "simple_ct" + } + ] + } + ] + } + ] + }, + "jsonRteContentType": { + "uid": "json_rte_ct", + "title": "JSON RTE Content Type", + "schema": [ + { + "uid": "title", + "data_type": "text", + "display_name": "Title" + }, + { + "uid": "json_rte_field", + "data_type": "json", + "display_name": "JSON RTE Field", + "field_metadata": { + "rich_text_type": true + } + } + ] + }, + "multipleJsonRteContentType": { + "uid": "multiple_json_rte_ct", + "title": "Multiple JSON RTE Content Type", + "schema": [ + { + "uid": "title", + "data_type": "text", + "display_name": "Title" + }, + { + "uid": "json_rte_field", + "data_type": "json", + "display_name": "JSON RTE Field", + "multiple": true, + "field_metadata": { + "rich_text_type": true + } + } + ] + }, + "blocksJsonRteContentType": { + "uid": "blocks_json_rte_ct", + "title": "Blocks JSON RTE Content Type", + "schema": [ + { + "uid": "title", + "data_type": "text", + "display_name": "Title" + }, + { + "uid": "blocks_field", + "data_type": "blocks", + "display_name": "Blocks Field", + "blocks": [ + { + "uid": "json_rte_block", + "display_name": "JSON RTE Block", + "schema": [ + { + "uid": "json_rte_field", + "data_type": "json", + "display_name": "JSON RTE Field", + "field_metadata": { + "rich_text_type": true + } + } + ] + } + ] + } + ] + }, + "groupJsonRteContentType": { + "uid": "group_json_rte_ct", + "title": "Group JSON RTE Content Type", + "schema": [ + { + "uid": "title", + "data_type": "text", + "display_name": "Title" + }, + { + "uid": "group_field", + "data_type": "group", + "display_name": "Group Field", + "schema": [ + { + "uid": "json_rte_field", + "data_type": "json", + "display_name": "JSON RTE Field", + "field_metadata": { + "rich_text_type": true + } + } + ] + } + ] + }, + "assetContentType": { + "uid": "asset_ct", + "title": "Asset Content Type", + "schema": [ + { + "uid": "title", + "data_type": "text", + "display_name": "Title" + }, + { + "uid": "single_asset", + "data_type": "reference", + "display_name": "Single Asset", + "reference_to": "_assets" + }, + { + "uid": "multi_asset", + "data_type": "reference", + "display_name": "Multi Asset", + "reference_to": "_assets" + } + ] + }, + "textRteContentType": { + "uid": "text_rte_ct", + "title": "Text RTE Content Type", + "schema": [ + { + "uid": "title", + "data_type": "text", + "display_name": "Title" + }, + { + "uid": "text_rte_field", + "data_type": "text", + "display_name": "Text RTE Field", + "field_metadata": { + "rich_text_type": true + } + } + ] + }, + "multipleTextRteContentType": { + "uid": "multiple_text_rte_ct", + "title": "Multiple Text RTE Content Type", + "schema": [ + { + "uid": "title", + "data_type": "text", + "display_name": "Title" + }, + { + "uid": "text_rte_field", + "data_type": "text", + "display_name": "Text RTE Field", + "multiple": true, + "field_metadata": { + "rich_text_type": true + } + } + ] + }, + "multipleBlocksJsonRteContentType": { + "uid": "multiple_blocks_json_rte_ct", + "title": "Multiple Blocks JSON RTE Content Type", + "schema": [ + { + "uid": "title", + "data_type": "text", + "display_name": "Title" + }, + { + "uid": "blocks_field", + "data_type": "blocks", + "display_name": "Blocks Field", + "multiple": true, + "blocks": [ + { + "uid": "json_rte_block", + "display_name": "JSON RTE Block", + "schema": [ + { + "uid": "json_rte_field", + "data_type": "json", + "display_name": "JSON RTE Field", + "field_metadata": { + "rich_text_type": true + } + } + ] + } + ] + } + ] + }, + "multipleGroupsJsonRteContentType": { + "uid": "multiple_groups_json_rte_ct", + "title": "Multiple Groups JSON RTE Content Type", + "schema": [ + { + "uid": "title", + "data_type": "text", + "display_name": "Title" + }, + { + "uid": "group_field", + "data_type": "group", + "display_name": "Group Field", + "multiple": true, + "schema": [ + { + "uid": "json_rte_field", + "data_type": "json", + "display_name": "JSON RTE Field", + "field_metadata": { + "rich_text_type": true + } + } + ] + } + ] + }, + "multipleJsonRteContentType": { + "uid": "multiple_json_rte_ct", + "title": "Multiple JSON RTE Content Type", + "schema": [ + { + "uid": "title", + "data_type": "text", + "display_name": "Title" + }, + { + "uid": "json_rte_field", + "data_type": "json", + "display_name": "JSON RTE Field", + "multiple": true, + "field_metadata": { + "rich_text_type": true + } + } + ] + } +} diff --git a/packages/contentstack-import/test/unit/utils/mock-data/entries-helper/entries.json b/packages/contentstack-import/test/unit/utils/mock-data/entries-helper/entries.json new file mode 100644 index 0000000000..8dabde6fa6 --- /dev/null +++ b/packages/contentstack-import/test/unit/utils/mock-data/entries-helper/entries.json @@ -0,0 +1,1399 @@ +{ + "simpleEntry": { + "uid": "simple_entry_1", + "title": "Simple Entry 1", + "description": "A simple entry with basic fields" + }, + "entryWithSingleReference": { + "uid": "ref_entry_1", + "title": "Entry with Single Reference", + "single_reference": { + "uid": "ref_entry_1", + "_content_type_uid": "simple_ct" + } + }, + "entryWithMultiReference": { + "uid": "multi_ref_entry_1", + "title": "Entry with Multi Reference", + "multi_reference": [ + { + "uid": "ref_entry_1", + "_content_type_uid": "simple_ct" + }, + { + "uid": "ref_entry_2", + "_content_type_uid": "ref_ct" + } + ] + }, + "entryWithStringReference": { + "uid": "string_ref_entry_1", + "title": "Entry with String Reference", + "single_reference": "ref_entry_1" + }, + "entryWithGroupReference": { + "uid": "group_entry_1", + "title": "Entry with Group Reference", + "group_field": { + "group_text": "Text in group", + "nested_reference": { + "uid": "ref_entry_1", + "_content_type_uid": "simple_ct" + } + } + }, + "entryWithBlocksReference": { + "uid": "blocks_entry_1", + "title": "Entry with Blocks Reference", + "blocks_field": [ + { + "text_block": { + "block_text": "Text in block", + "block_reference": { + "uid": "ref_entry_1", + "_content_type_uid": "simple_ct" + } + } + } + ] + }, + "entryWithJsonRteReference": { + "uid": "json_rte_entry_1", + "title": "Entry with JSON RTE Reference", + "json_rte_field": { + "type": "doc", + "uid": "json_rte_uid_1", + "attrs": {}, + "children": [ + { + "type": "p", + "attrs": {}, + "children": [ + { + "text": "This is a JSON RTE field with " + }, + { + "type": "reference", + "attrs": { + "type": "entry", + "entry-uid": "ref_entry_1", + "content-type-uid": "simple_ct" + }, + "children": [ + { + "text": "entry reference" + } + ] + } + ] + } + ] + } + }, + "entryWithJsonRteUid": { + "uid": "json_rte_uid_entry_1", + "title": "Entry with JSON RTE UID", + "json_rte_field": { + "type": "doc", + "uid": "json_rte_uid_1", + "attrs": { + "dirty": false + }, + "children": [ + { + "type": "p", + "uid": "p_uid_1", + "attrs": { + "dirty": false + }, + "children": [ + { + "text": "Simple text content" + } + ] + } + ] + } + }, + "entryWithMultipleJsonRte": { + "uid": "multiple_json_rte_entry_1", + "title": "Entry with Multiple JSON RTE", + "json_rte_field": [ + { + "type": "doc", + "uid": "json_rte_uid_1", + "attrs": { + "dirty": false + }, + "children": [ + { + "type": "p", + "uid": "p_uid_1", + "attrs": { + "dirty": false + }, + "children": [ + { + "text": "First JSON RTE content" + } + ] + } + ] + }, + { + "type": "doc", + "uid": "json_rte_uid_2", + "attrs": { + "dirty": false + }, + "children": [ + { + "type": "p", + "uid": "p_uid_2", + "attrs": { + "dirty": false + }, + "children": [ + { + "text": "Second JSON RTE content" + } + ] + } + ] + } + ] + }, + "entryWithBlocksJsonRte": { + "uid": "blocks_json_rte_entry_1", + "title": "Entry with Blocks JSON RTE", + "blocks_field": [ + { + "json_rte_block": { + "json_rte_field": { + "type": "doc", + "uid": "json_rte_uid_1", + "attrs": { + "dirty": false + }, + "children": [ + { + "type": "p", + "uid": "p_uid_1", + "attrs": { + "dirty": false + }, + "children": [ + { + "text": "JSON RTE in blocks" + } + ] + } + ] + } + } + } + ] + }, + "entryWithGroupJsonRte": { + "uid": "group_json_rte_entry_1", + "title": "Entry with Group JSON RTE", + "group_field": { + "json_rte_field": { + "type": "doc", + "uid": "json_rte_uid_1", + "attrs": { + "dirty": false + }, + "children": [ + { + "type": "p", + "uid": "p_uid_1", + "attrs": { + "dirty": false + }, + "children": [ + { + "text": "JSON RTE in group" + } + ] + } + ] + } + } + }, + "entryWithNestedJsonRte": { + "uid": "nested_json_rte_entry_1", + "title": "Entry with Nested JSON RTE", + "json_rte_field": { + "type": "doc", + "uid": "json_rte_uid_1", + "attrs": { + "dirty": false + }, + "children": [ + { + "type": "p", + "uid": "p_uid_1", + "attrs": { + "dirty": false + }, + "children": [ + { + "text": "Parent text" + }, + { + "type": "span", + "uid": "span_uid_1", + "attrs": { + "dirty": false + }, + "children": [ + { + "text": "Nested text" + } + ] + } + ] + } + ] + } + }, + "entryWithEmptyJsonRte": { + "uid": "empty_json_rte_entry_1", + "title": "Entry with Empty JSON RTE", + "json_rte_field": { + "type": "doc", + "uid": "json_rte_uid_1", + "attrs": { + "dirty": false + }, + "children": [] + } + }, + "entryWithOnlyEntryRefs": { + "uid": "only_entry_refs_entry_1", + "title": "Entry with Only Entry References", + "json_rte_field": { + "type": "doc", + "uid": "json_rte_uid_1", + "attrs": { + "dirty": false + }, + "children": [ + { + "type": "reference", + "attrs": { + "type": "entry", + "entry-uid": "ref_entry_1", + "content-type-uid": "simple_ct" + }, + "children": [ + { + "text": "entry reference" + } + ] + } + ] + } + }, + "entryWithBlocksJsonRteRefs": { + "uid": "blocks_json_rte_refs_entry_1", + "title": "Entry with Blocks JSON RTE References", + "blocks_field": [ + { + "json_rte_block": { + "json_rte_field": { + "type": "doc", + "uid": "json_rte_uid_1", + "attrs": { + "dirty": false + }, + "children": [ + { + "type": "reference", + "attrs": { + "type": "entry", + "entry-uid": "ref_entry_1", + "content-type-uid": "simple_ct" + }, + "children": [ + { + "text": "entry reference in blocks" + } + ] + } + ] + } + } + } + ] + }, + "entryWithGroupJsonRteRefs": { + "uid": "group_json_rte_refs_entry_1", + "title": "Entry with Group JSON RTE References", + "group_field": { + "json_rte_field": { + "type": "doc", + "uid": "json_rte_uid_1", + "attrs": { + "dirty": false + }, + "children": [ + { + "type": "reference", + "attrs": { + "type": "entry", + "entry-uid": "ref_entry_1", + "content-type-uid": "simple_ct" + }, + "children": [ + { + "text": "entry reference in group" + } + ] + } + ] + } + } + }, + "entryWithAssetReference": { + "uid": "asset_entry_1", + "title": "Entry with Asset Reference", + "single_asset": { + "uid": "asset_1", + "_content_type_uid": "_assets" + }, + "multi_asset": [ + { + "uid": "asset_1", + "_content_type_uid": "_assets" + }, + { + "uid": "asset_2", + "_content_type_uid": "_assets" + } + ] + }, + "entryWithTextRte": { + "uid": "text_rte_entry_1", + "title": "Entry with Text RTE", + "text_rte_field": "

This is RTE content with asset link and entry link

" + }, + "entryWithMultipleTextRte": { + "uid": "multiple_text_rte_entry_1", + "title": "Entry with Multiple Text RTE", + "text_rte_field": [ + "

First RTE content

", + "

Second RTE content

" + ] + }, + "sourceStackEntryWithJsonRte": { + "json_rte_field": { + "type": "doc", + "uid": "source_json_rte_uid_1", + "attrs": {}, + "children": [ + { + "type": "p", + "attrs": {}, + "children": [ + { + "text": "Source JSON RTE content with " + }, + { + "type": "reference", + "attrs": { + "type": "entry", + "entry-uid": "old_ref_entry_1", + "content-type-uid": "simple_ct" + }, + "children": [ + { + "text": "source entry reference" + } + ] + } + ] + } + ] + } + }, + "sourceStackEntryWithBlocksJsonRte": { + "blocks_field": [ + { + "json_rte_block": { + "json_rte_field": { + "type": "doc", + "uid": "source_json_rte_uid_1", + "attrs": {}, + "children": [ + { + "type": "p", + "attrs": {}, + "children": [ + { + "text": "Source JSON RTE in blocks" + } + ] + } + ] + } + } + } + ] + }, + "sourceStackEntryWithGroupJsonRte": { + "group_field": { + "json_rte_field": { + "type": "doc", + "uid": "source_json_rte_uid_1", + "attrs": {}, + "children": [ + { + "type": "p", + "attrs": {}, + "children": [ + { + "text": "Source JSON RTE in group" + } + ] + } + ] + } + } + }, + "sourceStackEntryWithTextRte": { + "text_rte_field": "

Source RTE content with asset link and entry link

" + }, + "sourceStackEntryWithEmptyJsonRte": { + "json_rte_field": { + "type": "doc", + "uid": "source_json_rte_uid_1", + "attrs": {}, + "children": [] + } + }, + "entryWithJsonRteAssetLink": { + "uid": "json_rte_asset_link_entry_1", + "title": "Entry with JSON RTE Asset Link", + "json_rte_field": { + "type": "doc", + "uid": "json_rte_uid_1", + "attrs": { + "dirty": false + }, + "children": [ + { + "type": "p", + "uid": "p_uid_1", + "attrs": { + "dirty": false + }, + "children": [ + { + "text": "Content with " + }, + { + "type": "reference", + "uid": "ref_uid_1", + "attrs": { + "type": "asset", + "asset-uid": "asset_1", + "href": "https://old-asset-url.com/asset1.jpg", + "display-type": "link", + "dirty": false + }, + "children": [ + { + "text": "asset link" + } + ] + } + ] + } + ] + } + }, + "entryWithJsonRteAssetDisplay": { + "uid": "json_rte_asset_display_entry_1", + "title": "Entry with JSON RTE Asset Display", + "json_rte_field": { + "type": "doc", + "uid": "json_rte_uid_1", + "attrs": { + "dirty": false + }, + "children": [ + { + "type": "p", + "uid": "p_uid_1", + "attrs": { + "dirty": false + }, + "children": [ + { + "text": "Content with " + }, + { + "type": "reference", + "uid": "ref_uid_1", + "attrs": { + "type": "asset", + "asset-uid": "asset_1", + "asset-link": "https://old-asset-url.com/asset1.jpg", + "display-type": "display", + "dirty": false + }, + "children": [ + { + "text": "asset display" + } + ] + } + ] + } + ] + } + }, + "sourceStackEntryWithMultipleJsonRte": { + "json_rte_field": [ + { + "type": "doc", + "uid": "source_json_rte_uid_1", + "attrs": {}, + "children": [ + { + "type": "p", + "attrs": {}, + "children": [ + { + "text": "First source JSON RTE content" + } + ] + } + ] + }, + { + "type": "doc", + "uid": "source_json_rte_uid_2", + "attrs": {}, + "children": [ + { + "type": "p", + "attrs": {}, + "children": [ + { + "text": "Second source JSON RTE content" + } + ] + } + ] + } + ] + }, + "sourceStackEntryWithMultipleTextRte": { + "text_rte_field": [ + "

First source RTE content with asset link and entry link

", + "

Second source RTE content with asset link and entry link

" + ] + }, + "sourceStackEntryWithJsonRteAssetLink": { + "json_rte_field": { + "type": "doc", + "uid": "source_json_rte_uid_1", + "attrs": {}, + "children": [ + { + "type": "p", + "attrs": {}, + "children": [ + { + "text": "Source content with " + }, + { + "type": "reference", + "attrs": { + "type": "asset", + "asset-uid": "old_asset_1", + "href": "https://old-asset-url.com/asset1.jpg", + "display-type": "link" + }, + "children": [ + { + "text": "source asset link" + } + ] + } + ] + } + ] + } + }, + "sourceStackEntryWithJsonRteAssetDisplay": { + "json_rte_field": { + "type": "doc", + "uid": "source_json_rte_uid_1", + "attrs": {}, + "children": [ + { + "type": "p", + "attrs": {}, + "children": [ + { + "text": "Source content with " + }, + { + "type": "reference", + "attrs": { + "type": "asset", + "asset-uid": "old_asset_1", + "asset-link": "https://old-asset-url.com/asset1.jpg", + "display-type": "display" + }, + "children": [ + { + "text": "source asset display" + } + ] + } + ] + } + ] + } + }, + "entryWithMultipleBlocksJsonRte": { + "uid": "multiple_blocks_json_rte_entry_1", + "title": "Entry with Multiple Blocks JSON RTE", + "blocks_field": [ + { + "json_rte_block": { + "json_rte_field": { + "type": "doc", + "uid": "json_rte_uid_1", + "attrs": { + "dirty": false + }, + "children": [ + { + "type": "p", + "uid": "p_uid_1", + "attrs": { + "dirty": false + }, + "children": [ + { + "text": "First JSON RTE in blocks" + } + ] + } + ] + } + } + }, + { + "json_rte_block": { + "json_rte_field": { + "type": "doc", + "uid": "json_rte_uid_2", + "attrs": { + "dirty": false + }, + "children": [ + { + "type": "p", + "uid": "p_uid_2", + "attrs": { + "dirty": false + }, + "children": [ + { + "text": "Second JSON RTE in blocks" + } + ] + } + ] + } + } + } + ] + }, + "entryWithMultipleGroupsJsonRte": { + "uid": "multiple_groups_json_rte_entry_1", + "title": "Entry with Multiple Groups JSON RTE", + "group_field": [ + { + "json_rte_field": { + "type": "doc", + "uid": "json_rte_uid_1", + "attrs": { + "dirty": false + }, + "children": [ + { + "type": "p", + "uid": "p_uid_1", + "attrs": { + "dirty": false + }, + "children": [ + { + "text": "First JSON RTE in group" + } + ] + } + ] + } + }, + { + "json_rte_field": { + "type": "doc", + "uid": "json_rte_uid_2", + "attrs": { + "dirty": false + }, + "children": [ + { + "type": "p", + "uid": "p_uid_2", + "attrs": { + "dirty": false + }, + "children": [ + { + "text": "Second JSON RTE in group" + } + ] + } + ] + } + } + ] + }, + "entryWithTextRteUidUpdates": { + "uid": "text_rte_uid_updates_entry_1", + "title": "Entry with Text RTE UID Updates", + "text_rte_field": "

RTE content with entry link and asset link

" + }, + "entryWithJsonRteAssetUidMapping": { + "uid": "json_rte_asset_uid_mapping_entry_1", + "title": "Entry with JSON RTE Asset UID Mapping", + "json_rte_field": { + "type": "doc", + "uid": "json_rte_uid_1", + "attrs": { + "dirty": false + }, + "children": [ + { + "type": "p", + "uid": "p_uid_1", + "attrs": { + "dirty": false + }, + "children": [ + { + "text": "Content with " + }, + { + "type": "reference", + "uid": "ref_uid_1", + "attrs": { + "type": "asset", + "asset-uid": "old_asset_1", + "asset-link": "https://old-asset-url.com/asset1.jpg", + "display-type": "display", + "dirty": false + }, + "children": [ + { + "text": "asset with UID mapping" + } + ] + } + ] + } + ] + } + }, + "sourceStackEntryWithMultipleBlocksJsonRte": { + "blocks_field": [ + { + "json_rte_block": { + "json_rte_field": { + "type": "doc", + "uid": "source_json_rte_uid_1", + "attrs": {}, + "children": [ + { + "type": "p", + "attrs": {}, + "children": [ + { + "text": "First source JSON RTE in blocks" + } + ] + } + ] + } + } + }, + { + "json_rte_block": { + "json_rte_field": { + "type": "doc", + "uid": "source_json_rte_uid_2", + "attrs": {}, + "children": [ + { + "type": "p", + "attrs": {}, + "children": [ + { + "text": "Second source JSON RTE in blocks" + } + ] + } + ] + } + } + } + ] + }, + "sourceStackEntryWithMultipleGroupsJsonRte": { + "group_field": [ + { + "json_rte_field": { + "type": "doc", + "uid": "source_json_rte_uid_1", + "attrs": {}, + "children": [ + { + "type": "p", + "attrs": {}, + "children": [ + { + "text": "First source JSON RTE in group" + } + ] + } + ] + } + }, + { + "json_rte_field": { + "type": "doc", + "uid": "source_json_rte_uid_2", + "attrs": {}, + "children": [ + { + "type": "p", + "attrs": {}, + "children": [ + { + "text": "Second source JSON RTE in group" + } + ] + } + ] + } + } + ] + }, + "sourceStackEntryWithTextRteUidUpdates": { + "text_rte_field": "

Source RTE content with entry link and asset link

" + }, + "sourceStackEntryWithJsonRteAssetUidMapping": { + "json_rte_field": { + "type": "doc", + "uid": "source_json_rte_uid_1", + "attrs": {}, + "children": [ + { + "type": "p", + "attrs": {}, + "children": [ + { + "text": "Source content with " + }, + { + "type": "reference", + "attrs": { + "type": "asset", + "asset-uid": "old_asset_1", + "asset-link": "https://old-asset-url.com/asset1.jpg", + "display-type": "display" + }, + "children": [ + { + "text": "source asset with UID mapping" + } + ] + } + ] + } + ] + } + }, + "entryWithMixedJsonRteRefs": { + "uid": "mixed_json_rte_refs_entry_1", + "title": "Entry with Mixed JSON RTE References", + "json_rte_field": { + "type": "doc", + "uid": "json_rte_uid_1", + "attrs": { + "dirty": false + }, + "children": [ + { + "type": "p", + "uid": "p_uid_1", + "attrs": { + "dirty": false + }, + "children": [ + { + "text": "Content with " + }, + { + "type": "reference", + "uid": "ref_uid_1", + "attrs": { + "type": "entry", + "entry-uid": "ref_entry_1", + "content-type-uid": "simple_ct", + "dirty": false + }, + "children": [ + { + "text": "entry reference" + } + ] + }, + { + "text": " and regular text" + } + ] + } + ] + } + }, + "entryWithNestedEntryRefs": { + "uid": "nested_entry_refs_entry_1", + "title": "Entry with Nested Entry References", + "json_rte_field": { + "type": "doc", + "uid": "json_rte_uid_1", + "attrs": { + "dirty": false + }, + "children": [ + { + "type": "p", + "uid": "p_uid_1", + "attrs": { + "dirty": false + }, + "children": [ + { + "text": "Content with " + }, + { + "type": "span", + "uid": "span_uid_1", + "attrs": { + "dirty": false + }, + "children": [ + { + "type": "reference", + "uid": "ref_uid_1", + "attrs": { + "type": "entry", + "entry-uid": "ref_entry_1", + "content-type-uid": "simple_ct", + "dirty": false + }, + "children": [ + { + "text": "nested entry reference" + } + ] + } + ] + } + ] + } + ] + } + }, + "entryWithWrappedEntryRefs": { + "uid": "wrapped_entry_refs_entry_1", + "title": "Entry with Wrapped Entry References", + "json_rte_field": { + "type": "doc", + "uid": "json_rte_uid_1", + "attrs": { + "dirty": false + }, + "children": [ + { + "type": "p", + "uid": "p_uid_1", + "attrs": { + "dirty": false + }, + "children": [ + { + "type": "reference", + "uid": "ref_uid_1", + "attrs": { + "type": "entry", + "entry-uid": "ref_entry_1", + "content-type-uid": "simple_ct", + "dirty": false + }, + "children": [ + { + "text": "entry reference in p" + } + ] + } + ] + }, + { + "type": "a", + "uid": "a_uid_1", + "attrs": { + "dirty": false + }, + "children": [ + { + "type": "reference", + "uid": "ref_uid_2", + "attrs": { + "type": "entry", + "entry-uid": "ref_entry_2", + "content-type-uid": "simple_ct", + "dirty": false + }, + "children": [ + { + "text": "entry reference in a" + } + ] + } + ] + }, + { + "type": "span", + "uid": "span_uid_1", + "attrs": { + "dirty": false + }, + "children": [ + { + "type": "reference", + "uid": "ref_uid_3", + "attrs": { + "type": "entry", + "entry-uid": "ref_entry_3", + "content-type-uid": "simple_ct", + "dirty": false + }, + "children": [ + { + "text": "entry reference in span" + } + ] + } + ] + } + ] + } + }, + "entryWithTextRteUidMatches": { + "uid": "text_rte_uid_matches_entry_1", + "title": "Entry with Text RTE UID Matches", + "text_rte_field": "

RTE content with entry link and asset link

" + }, + "sourceStackEntryWithTextRteUidMatches": { + "text_rte_field": "

Source RTE content with entry link and asset link

" + }, + "entryWithEntryRefsForFiltering": { + "uid": "entry_refs_filtering_entry_1", + "title": "Entry with Entry References for Filtering", + "json_rte_field": { + "type": "doc", + "uid": "json_rte_uid_1", + "attrs": { + "dirty": false + }, + "children": [ + { + "type": "reference", + "uid": "ref_uid_1", + "attrs": { + "type": "entry", + "entry-uid": "ref_entry_1", + "content-type-uid": "simple_ct", + "dirty": false + }, + "children": [ + { + "text": "entry reference 1" + } + ] + }, + { + "type": "reference", + "uid": "ref_uid_2", + "attrs": { + "type": "entry", + "entry-uid": "ref_entry_2", + "content-type-uid": "simple_ct", + "dirty": false + }, + "children": [ + { + "text": "entry reference 2" + } + ] + } + ] + } + }, + "entryWithDirectEntryRefs": { + "uid": "direct_entry_refs_entry_1", + "title": "Entry with Direct Entry References", + "json_rte_field": { + "type": "reference", + "uid": "ref_uid_1", + "attrs": { + "type": "entry", + "entry-uid": "ref_entry_1", + "content-type-uid": "simple_ct", + "dirty": false + }, + "children": [ + { + "text": "direct entry reference" + } + ] + } + }, + "entryWithMultipleTextRteUidMatches": { + "uid": "multiple_text_rte_uid_matches_entry_1", + "title": "Entry with Multiple Text RTE UID Matches", + "text_rte_field": [ + "

First RTE content with entry link

", + "

Second RTE content with entry link

" + ] + }, + "sourceStackEntryWithMultipleTextRteUidMatches": { + "text_rte_field": [ + "

First source RTE content with entry link

", + "

Second source RTE content with entry link

" + ] + }, + "entryWithNonObjectField": { + "uid": "non_object_field_entry_1", + "title": "Entry with Non Object Field", + "single_reference": "ref_entry_1" + }, + "entryWithArrayField": { + "uid": "array_field_entry_1", + "title": "Entry with Array Field", + "single_reference": ["ref_entry_1", "ref_entry_2"] + }, + "entryWithJsonRteEmptyAttrs": { + "uid": "json_rte_empty_attrs_entry_1", + "title": "Entry with JSON RTE Empty Attrs", + "json_rte_field": { + "type": "doc", + "uid": "json_rte_uid_1", + "attrs": {}, + "children": [ + { + "type": "p", + "uid": "p_uid_1", + "attrs": {}, + "children": [ + { + "text": "Content with empty attrs" + } + ] + } + ] + } + }, + "entryWithJsonRteNonObjectAttrs": { + "uid": "json_rte_non_object_attrs_entry_1", + "title": "Entry with JSON RTE Non Object Attrs", + "json_rte_field": { + "type": "doc", + "uid": "json_rte_uid_1", + "attrs": "string_attrs", + "children": [ + { + "type": "p", + "uid": "p_uid_1", + "attrs": "string_attrs", + "children": [ + { + "text": "Content with non-object attrs" + } + ] + } + ] + } + }, + "entryWithJsonRteNoAttrs": { + "uid": "json_rte_no_attrs_entry_1", + "title": "Entry with JSON RTE No Attrs", + "json_rte_field": { + "type": "doc", + "uid": "json_rte_uid_1", + "children": [ + { + "type": "p", + "uid": "p_uid_1", + "children": [ + { + "text": "Content with no attrs" + } + ] + } + ] + } + }, + "entryWithJsonRteNoEntryRefs": { + "uid": "json_rte_no_entry_refs_entry_1", + "title": "Entry with JSON RTE No Entry References", + "json_rte_field": { + "type": "doc", + "uid": "json_rte_uid_1", + "attrs": { + "dirty": false + }, + "children": [ + { + "type": "p", + "uid": "p_uid_1", + "attrs": { + "dirty": false + }, + "children": [ + { + "text": "Just regular text content" + } + ] + } + ] + } + }, + "entryWithJsonRteOnlyEntryRefs": { + "uid": "json_rte_only_entry_refs_entry_1", + "title": "Entry with JSON RTE Only Entry References", + "json_rte_field": { + "type": "doc", + "uid": "json_rte_uid_1", + "attrs": { + "dirty": false + }, + "children": [ + { + "type": "reference", + "uid": "ref_uid_1", + "attrs": { + "type": "entry", + "entry-uid": "ref_entry_1", + "content-type-uid": "simple_ct", + "dirty": false + }, + "children": [ + { + "text": "entry reference 1" + } + ] + }, + { + "type": "reference", + "uid": "ref_uid_2", + "attrs": { + "type": "entry", + "entry-uid": "ref_entry_2", + "content-type-uid": "simple_ct", + "dirty": false + }, + "children": [ + { + "text": "entry reference 2" + } + ] + } + ] + } + }, + "entryWithMultipleTextRteArray": { + "uid": "multiple_text_rte_array_entry_1", + "title": "Entry with Multiple Text RTE Array", + "text_rte_field": [ + "

First RTE content with entry link

", + "

Second RTE content with entry link

" + ] + }, + "sourceStackEntryWithMultipleTextRteArray": { + "text_rte_field": [ + "

First source RTE content with entry link

", + "

Second source RTE content with entry link

" + ] + }, + "entryWithMultipleJsonRteNoEntryRefs": { + "uid": "multiple_json_rte_no_entry_refs_entry_1", + "title": "Entry with Multiple JSON RTE No Entry References", + "json_rte_field": [ + { + "type": "doc", + "uid": "json_rte_uid_1", + "attrs": { + "dirty": false + }, + "children": [ + { + "type": "p", + "uid": "p_uid_1", + "attrs": { + "dirty": false + }, + "children": [ + { + "text": "Just regular text content 1" + } + ] + } + ] + }, + { + "type": "doc", + "uid": "json_rte_uid_2", + "attrs": { + "dirty": false + }, + "children": [ + { + "type": "p", + "uid": "p_uid_2", + "attrs": { + "dirty": false + }, + "children": [ + { + "text": "Just regular text content 2" + } + ] + } + ] + } + ] + } +} diff --git a/packages/contentstack-import/test/unit/utils/mock-data/entries-helper/json-rte-data.json b/packages/contentstack-import/test/unit/utils/mock-data/entries-helper/json-rte-data.json new file mode 100644 index 0000000000..18e20f266c --- /dev/null +++ b/packages/contentstack-import/test/unit/utils/mock-data/entries-helper/json-rte-data.json @@ -0,0 +1,268 @@ +{ + "simpleJsonRte": { + "type": "doc", + "uid": "json_rte_uid_1", + "attrs": { + "dirty": false + }, + "children": [ + { + "type": "p", + "uid": "p_uid_1", + "attrs": { + "dirty": false + }, + "children": [ + { + "text": "Simple JSON RTE content" + } + ] + } + ] + }, + "jsonRteWithEntryRef": { + "type": "doc", + "uid": "json_rte_uid_1", + "attrs": { + "dirty": false + }, + "children": [ + { + "type": "p", + "uid": "p_uid_1", + "attrs": { + "dirty": false + }, + "children": [ + { + "text": "Content with " + }, + { + "type": "reference", + "uid": "ref_uid_1", + "attrs": { + "type": "entry", + "entry-uid": "ref_entry_1", + "content-type-uid": "simple_ct", + "dirty": false + }, + "children": [ + { + "text": "entry reference" + } + ] + } + ] + } + ] + }, + "jsonRteWithAssetRef": { + "type": "doc", + "uid": "json_rte_uid_1", + "attrs": { + "dirty": false + }, + "children": [ + { + "type": "p", + "uid": "p_uid_1", + "attrs": { + "dirty": false + }, + "children": [ + { + "text": "Content with " + }, + { + "type": "reference", + "uid": "ref_uid_1", + "attrs": { + "type": "asset", + "asset-uid": "asset_1", + "asset-link": "https://old-asset-url.com/asset1.jpg", + "display-type": "display", + "dirty": false + }, + "children": [ + { + "text": "asset reference" + } + ] + } + ] + } + ] + }, + "jsonRteWithNestedChildren": { + "type": "doc", + "uid": "json_rte_uid_1", + "attrs": { + "dirty": false + }, + "children": [ + { + "type": "p", + "uid": "p_uid_1", + "attrs": { + "dirty": false + }, + "children": [ + { + "text": "Parent text" + }, + { + "type": "span", + "uid": "span_uid_1", + "attrs": { + "dirty": false + }, + "children": [ + { + "text": "Nested text" + }, + { + "type": "reference", + "uid": "ref_uid_1", + "attrs": { + "type": "entry", + "entry-uid": "ref_entry_1", + "content-type-uid": "simple_ct", + "dirty": false + }, + "children": [ + { + "text": "nested entry reference" + } + ] + } + ] + } + ] + } + ] + }, + "jsonRteWithOnlyEntryRefs": { + "type": "doc", + "uid": "json_rte_uid_1", + "attrs": { + "dirty": false + }, + "children": [ + { + "type": "reference", + "uid": "ref_uid_1", + "attrs": { + "type": "entry", + "entry-uid": "ref_entry_1", + "content-type-uid": "simple_ct", + "dirty": false + }, + "children": [ + { + "text": "entry reference" + } + ] + } + ] + }, + "jsonRteWithMixedRefs": { + "type": "doc", + "uid": "json_rte_uid_1", + "attrs": { + "dirty": false + }, + "children": [ + { + "type": "p", + "uid": "p_uid_1", + "attrs": { + "dirty": false + }, + "children": [ + { + "text": "Content with " + }, + { + "type": "reference", + "uid": "ref_uid_1", + "attrs": { + "type": "entry", + "entry-uid": "ref_entry_1", + "content-type-uid": "simple_ct", + "dirty": false + }, + "children": [ + { + "text": "entry reference" + } + ] + }, + { + "text": " and " + }, + { + "type": "reference", + "uid": "ref_uid_2", + "attrs": { + "type": "asset", + "asset-uid": "asset_1", + "asset-link": "https://old-asset-url.com/asset1.jpg", + "display-type": "display", + "dirty": false + }, + "children": [ + { + "text": "asset reference" + } + ] + } + ] + } + ] + }, + "emptyJsonRte": { + "type": "doc", + "uid": "json_rte_uid_1", + "attrs": { + "dirty": false + }, + "children": [] + }, + "jsonRteWithLinkAsset": { + "type": "doc", + "uid": "json_rte_uid_1", + "attrs": { + "dirty": false + }, + "children": [ + { + "type": "p", + "uid": "p_uid_1", + "attrs": { + "dirty": false + }, + "children": [ + { + "text": "Content with " + }, + { + "type": "reference", + "uid": "ref_uid_1", + "attrs": { + "type": "asset", + "asset-uid": "asset_1", + "href": "https://old-asset-url.com/asset1.jpg", + "display-type": "link", + "dirty": false + }, + "children": [ + { + "text": "asset link" + } + ] + } + ] + } + ] + } +} diff --git a/packages/contentstack-import/test/unit/utils/mock-data/entries-helper/mappers.json b/packages/contentstack-import/test/unit/utils/mock-data/entries-helper/mappers.json new file mode 100644 index 0000000000..6103c46d62 --- /dev/null +++ b/packages/contentstack-import/test/unit/utils/mock-data/entries-helper/mappers.json @@ -0,0 +1,17 @@ +{ + "entriesUidMapper": { + "ref_entry_1": "new_ref_entry_1", + "ref_entry_2": "new_ref_entry_2", + "old_ref_entry_1": "new_old_ref_entry_1" + }, + "assetUidMapper": { + "asset_1": "new_asset_1", + "asset_2": "new_asset_2", + "asset_3": "new_asset_3" + }, + "assetUrlMapper": { + "https://old-asset-url.com/asset1.jpg": "https://new-asset-url.com/asset1.jpg", + "https://old-asset-url.com/asset2.jpg": "https://new-asset-url.com/asset2.jpg", + "https://old-asset-url.com/asset3.jpg": "https://new-asset-url.com/asset3.jpg" + } +}