Skip to content

Commit 107e67c

Browse files
author
naman-contentstack
committed
Merge branch 'v2-beta-dev' into enhancement/DX-4443
2 parents 1408786 + 3b3556e commit 107e67c

File tree

8 files changed

+1877
-1638
lines changed

8 files changed

+1877
-1638
lines changed

.talismanrc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
fileignoreconfig:
22
- filename: pnpm-lock.yaml
3-
checksum: 2247bb2fd6b260dc960bb5b01939b85d34ff047e64bc1eb372fd046607fa7bd9
3+
checksum: 0d38bb12f29f0e69d78484a321bd17ca1ef0528f9e6294aac47fde45ab213a0b
44
- filename: package-lock.json
5-
checksum: 1c0d7a88e6e92119e09cc474645122f1ac6809b56c858280d66bf38a6a5939ae
5+
checksum: 3f5620c23bcc7df713fcf017382e8ccbf102d06387898ae1f328594f09924fbf
6+
- filename: packages/contentstack-audit/src/modules/entries.ts
7+
checksum: 8ad10d72522433bc5ce66079248aa2dabae1758ee63335024efd8526d76dd885
68
version: '1.0'

package-lock.json

Lines changed: 604 additions & 715 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/contentstack-audit/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@contentstack/cli-audit",
3-
"version": "2.0.0-beta.4",
3+
"version": "2.0.0-beta.5",
44
"description": "Contentstack audit plugin",
55
"author": "Contentstack CLI",
66
"homepage": "https://github.com/contentstack/cli",

packages/contentstack-audit/src/modules/entries.ts

Lines changed: 419 additions & 241 deletions
Large diffs are not rendered by default.

packages/contentstack-audit/test/unit/modules/entries.test.ts

Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,6 +1041,55 @@ describe('Entries module', () => {
10411041

10421042
expect(result).to.be.an('array'); // Should return array of missing references
10431043
});
1044+
1045+
fancy
1046+
.stdout({ print: process.env.PRINT === 'true' || false })
1047+
.it('should flag reference when ref entry has wrong content type (ct2 ref when reference_to is ct1)', () => {
1048+
const ctInstance = new Entries(constructorParam);
1049+
(ctInstance as any).currentUid = 'test-entry';
1050+
(ctInstance as any).entryMetaData = [{ uid: 'blt123', ctUid: 'ct2' }]; // Entry exists but is ct2
1051+
1052+
const referenceFieldSchema = { uid: 'ref', display_name: 'Ref', data_type: 'reference', reference_to: ['ct1'] };
1053+
const entryData = [{ uid: 'blt123', _content_type_uid: 'ct2' }];
1054+
const tree = [{ uid: 'test-entry', name: 'Test Entry' }];
1055+
1056+
const result = ctInstance.validateReferenceValues(tree, referenceFieldSchema as any, entryData);
1057+
1058+
expect(result).to.have.length(1);
1059+
expect(result[0].missingRefs).to.deep.include({ uid: 'blt123', _content_type_uid: 'ct2' });
1060+
});
1061+
1062+
fancy
1063+
.stdout({ print: process.env.PRINT === 'true' || false })
1064+
.it('should not flag reference when ref entry has correct content type (ct1 ref when reference_to is ct1)', () => {
1065+
const ctInstance = new Entries(constructorParam);
1066+
(ctInstance as any).currentUid = 'test-entry';
1067+
(ctInstance as any).entryMetaData = [{ uid: 'blt123', ctUid: 'ct1' }];
1068+
1069+
const referenceFieldSchema = { uid: 'ref', display_name: 'Ref', data_type: 'reference', reference_to: ['ct1'] };
1070+
const entryData = [{ uid: 'blt123', _content_type_uid: 'ct1' }];
1071+
const tree = [{ uid: 'test-entry', name: 'Test Entry' }];
1072+
1073+
const result = ctInstance.validateReferenceValues(tree, referenceFieldSchema as any, entryData);
1074+
1075+
expect(result).to.have.length(0);
1076+
});
1077+
1078+
fancy
1079+
.stdout({ print: process.env.PRINT === 'true' || false })
1080+
.it('should normalize reference_to string and allow matching ref (ct1 when reference_to is string ct1)', () => {
1081+
const ctInstance = new Entries(constructorParam);
1082+
(ctInstance as any).currentUid = 'test-entry';
1083+
(ctInstance as any).entryMetaData = [{ uid: 'blt456', ctUid: 'ct1' }];
1084+
1085+
const referenceFieldSchema = { uid: 'ref', display_name: 'Ref', data_type: 'reference', reference_to: 'ct1' };
1086+
const entryData = [{ uid: 'blt456', _content_type_uid: 'ct1' }];
1087+
const tree = [{ uid: 'test-entry', name: 'Test Entry' }];
1088+
1089+
const result = ctInstance.validateReferenceValues(tree, referenceFieldSchema as any, entryData);
1090+
1091+
expect(result).to.have.length(0);
1092+
});
10441093
});
10451094

10461095
describe('validateModularBlocksField method', () => {
@@ -1365,5 +1414,130 @@ describe('Entries module', () => {
13651414

13661415
// Should not throw - method is void
13671416
});
1417+
1418+
fancy
1419+
.stdout({ print: process.env.PRINT === 'true' || false })
1420+
.it('should flag JSON RTE embed when ref has wrong content type (ct2 when reference_to is ct1,sys_assets)', () => {
1421+
const ctInstance = new Entries(constructorParam);
1422+
(ctInstance as any).currentUid = 'test-entry';
1423+
(ctInstance as any).missingRefs = { 'test-entry': [] };
1424+
(ctInstance as any).entryMetaData = [{ uid: 'blt123', ctUid: 'ct2' }];
1425+
1426+
const schema = {
1427+
uid: 'json_rte',
1428+
display_name: 'JSON RTE',
1429+
data_type: 'richtext',
1430+
reference_to: ['ct1', 'sys_assets'],
1431+
};
1432+
const child = {
1433+
type: 'embed',
1434+
uid: 'child-uid',
1435+
attrs: { 'entry-uid': 'blt123', 'content-type-uid': 'ct2' },
1436+
children: [],
1437+
};
1438+
const tree: Record<string, unknown>[] = [];
1439+
1440+
(ctInstance as any).jsonRefCheck(tree, schema, child);
1441+
1442+
expect((ctInstance as any).missingRefs['test-entry']).to.have.length(1);
1443+
expect((ctInstance as any).missingRefs['test-entry'][0].missingRefs).to.deep.include({
1444+
uid: 'blt123',
1445+
'content-type-uid': 'ct2',
1446+
});
1447+
});
1448+
});
1449+
1450+
describe('fixMissingReferences method', () => {
1451+
fancy
1452+
.stdout({ print: process.env.PRINT === 'true' || false })
1453+
.it('should filter out ref when ref has wrong content type (ct2 when reference_to is ct1)', () => {
1454+
const ctInstance = new Entries({ ...constructorParam, fix: true });
1455+
(ctInstance as any).currentUid = 'test-entry';
1456+
(ctInstance as any).missingRefs = { 'test-entry': [] };
1457+
(ctInstance as any).entryMetaData = [{ uid: 'blt123', ctUid: 'ct2' }];
1458+
1459+
const field = {
1460+
uid: 'ref_field',
1461+
display_name: 'Ref',
1462+
data_type: 'reference',
1463+
reference_to: ['ct1'],
1464+
};
1465+
const entry = [{ uid: 'blt123', _content_type_uid: 'ct2' }];
1466+
const tree = [{ uid: 'test-entry', name: 'Test Entry' }];
1467+
1468+
const result = ctInstance.fixMissingReferences(tree, field as any, entry);
1469+
1470+
expect(result).to.have.length(0);
1471+
expect((ctInstance as any).missingRefs['test-entry']).to.have.length(1);
1472+
expect((ctInstance as any).missingRefs['test-entry'][0].missingRefs).to.deep.include({
1473+
uid: 'blt123',
1474+
_content_type_uid: 'ct2',
1475+
});
1476+
});
1477+
});
1478+
1479+
describe('jsonRefCheck in fix mode', () => {
1480+
fancy
1481+
.stdout({ print: process.env.PRINT === 'true' || false })
1482+
.it('should return null when ref has wrong content type (fix mode)', () => {
1483+
const ctInstance = new Entries({ ...constructorParam, fix: true });
1484+
(ctInstance as any).currentUid = 'test-entry';
1485+
(ctInstance as any).missingRefs = { 'test-entry': [] };
1486+
(ctInstance as any).entryMetaData = [{ uid: 'blt123', ctUid: 'ct2' }];
1487+
1488+
const schema = {
1489+
uid: 'json_rte',
1490+
display_name: 'JSON RTE',
1491+
data_type: 'richtext',
1492+
reference_to: ['ct1'],
1493+
};
1494+
const child = {
1495+
type: 'embed',
1496+
uid: 'child-uid',
1497+
attrs: { 'entry-uid': 'blt123', 'content-type-uid': 'ct2' },
1498+
children: [],
1499+
};
1500+
const tree: Record<string, unknown>[] = [];
1501+
1502+
const result = (ctInstance as any).jsonRefCheck(tree, schema, child);
1503+
1504+
expect(result).to.be.null;
1505+
});
1506+
});
1507+
1508+
describe('isRefContentTypeAllowed helper', () => {
1509+
const callHelper = (refCtUid: string | undefined, referenceTo: string | string[] | undefined) => {
1510+
const ctInstance = new Entries(constructorParam);
1511+
return (ctInstance as any).isRefContentTypeAllowed(refCtUid, referenceTo);
1512+
};
1513+
1514+
fancy.stdout({ print: process.env.PRINT === 'true' || false }).it('returns true when refCtUid is in reference_to', () => {
1515+
expect(callHelper('ct1', ['ct1', 'ct2'])).to.be.true;
1516+
});
1517+
1518+
fancy.stdout({ print: process.env.PRINT === 'true' || false }).it('returns false when refCtUid is not in reference_to', () => {
1519+
expect(callHelper('ct2', ['ct1'])).to.be.false;
1520+
});
1521+
1522+
fancy.stdout({ print: process.env.PRINT === 'true' || false }).it('returns true when reference_to is undefined', () => {
1523+
expect(callHelper('ct1', undefined)).to.be.true;
1524+
});
1525+
1526+
fancy.stdout({ print: process.env.PRINT === 'true' || false }).it('normalizes reference_to string and allows matching refCtUid', () => {
1527+
expect(callHelper('ct1', 'ct1')).to.be.true;
1528+
expect(callHelper('ct2', 'ct1')).to.be.false;
1529+
});
1530+
1531+
fancy.stdout({ print: process.env.PRINT === 'true' || false }).it('returns false when reference_to is empty array', () => {
1532+
expect(callHelper('ct1', [])).to.be.false;
1533+
});
1534+
1535+
fancy.stdout({ print: process.env.PRINT === 'true' || false }).it('returns true when refCtUid is undefined', () => {
1536+
expect(callHelper(undefined, ['ct1'])).to.be.true;
1537+
});
1538+
1539+
fancy.stdout({ print: process.env.PRINT === 'true' || false }).it('returns true when refCtUid is in skipRefs', () => {
1540+
expect(callHelper('sys_assets', ['ct1'])).to.be.true;
1541+
});
13681542
});
13691543
});

packages/contentstack-import/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"author": "Contentstack",
66
"bugs": "https://github.com/contentstack/cli/issues",
77
"dependencies": {
8-
"@contentstack/cli-audit": "~2.0.0-beta.4",
8+
"@contentstack/cli-audit": "~2.0.0-beta.5",
99
"@contentstack/cli-command": "~2.0.0-beta",
1010
"@contentstack/cli-utilities": "~2.0.0-beta",
1111
"@contentstack/cli-variants": "~2.0.0-beta.5",

packages/contentstack/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@contentstack/cli",
33
"description": "Command-line tool (CLI) to interact with Contentstack",
4-
"version": "2.0.0-beta.12",
4+
"version": "2.0.0-beta.13",
55
"author": "Contentstack",
66
"bin": {
77
"csdx": "./bin/run.js"
@@ -22,7 +22,7 @@
2222
"prepack": "pnpm compile && oclif manifest && oclif readme"
2323
},
2424
"dependencies": {
25-
"@contentstack/cli-audit": "~2.0.0-beta.4",
25+
"@contentstack/cli-audit": "~2.0.0-beta.5",
2626
"@contentstack/cli-cm-export": "~2.0.0-beta.9",
2727
"@contentstack/cli-cm-import": "~2.0.0-beta.9",
2828
"@contentstack/cli-auth": "~2.0.0-beta.5",

0 commit comments

Comments
 (0)