Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .talismanrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ fileignoreconfig:
- filename: packages/contentstack-import/src/import/modules/environments.ts
checksum: f61c635eaec8026e0cfa80a5ab8272f7946531f6d89505dc0d247b4c7ab0eab7
- filename: pnpm-lock.yaml
checksum: c3020538089092e55f086c39cc4c027ef3d48f6c786a217db9c5e49f55ab8380
checksum: 33b0a88264d099a2594bf8f18b8b025b0e15443dce340cd2ab5021ccc9aa84b0
- filename: package-lock.json
checksum: 099edd9ec7ed92eb61ce916511ac87e2fc1ff985efe64a25749ac88ba0d3fa7d
checksum: 38142d4c1159342957985368de6d5caf77ab3198a926fe55cdfd95c7c7343100
- filename: packages/contentstack-bootstrap/src/bootstrap/utils.ts
checksum: 5ab20e057fa9c4c300f7a882d30e1c68bbc91ed19de520488107e8c37239682a
- filename: packages/contentstack-migration/README.md
Expand All @@ -14,4 +14,6 @@ fileignoreconfig:
checksum: f4f44b6031d2936ec2da98b39bb5f5c1bd0f3be34dbe498c75e64a35b7d25a33
- filename: packages/contentstack/README.md
checksum: 3a0fab964797476a71d2149ce261d265f410bd756eb9cde9400be9e5250fdc35
- filename: packages/contentstack-audit/src/modules/entries.ts
checksum: 8ad10d72522433bc5ce66079248aa2dabae1758ee63335024efd8526d76dd885
version: '1.0'
945 changes: 575 additions & 370 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/contentstack-audit/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@contentstack/cli-audit",
"version": "2.0.0-beta.4",
"version": "2.0.0-beta.5",
"description": "Contentstack audit plugin",
"author": "Contentstack CLI",
"homepage": "https://github.com/contentstack/cli",
Expand Down
660 changes: 419 additions & 241 deletions packages/contentstack-audit/src/modules/entries.ts

Large diffs are not rendered by default.

174 changes: 174 additions & 0 deletions packages/contentstack-audit/test/unit/modules/entries.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1041,6 +1041,55 @@ describe('Entries module', () => {

expect(result).to.be.an('array'); // Should return array of missing references
});

fancy
.stdout({ print: process.env.PRINT === 'true' || false })
.it('should flag reference when ref entry has wrong content type (ct2 ref when reference_to is ct1)', () => {
const ctInstance = new Entries(constructorParam);
(ctInstance as any).currentUid = 'test-entry';
(ctInstance as any).entryMetaData = [{ uid: 'blt123', ctUid: 'ct2' }]; // Entry exists but is ct2

const referenceFieldSchema = { uid: 'ref', display_name: 'Ref', data_type: 'reference', reference_to: ['ct1'] };
const entryData = [{ uid: 'blt123', _content_type_uid: 'ct2' }];
const tree = [{ uid: 'test-entry', name: 'Test Entry' }];

const result = ctInstance.validateReferenceValues(tree, referenceFieldSchema as any, entryData);

expect(result).to.have.length(1);
expect(result[0].missingRefs).to.deep.include({ uid: 'blt123', _content_type_uid: 'ct2' });
});

fancy
.stdout({ print: process.env.PRINT === 'true' || false })
.it('should not flag reference when ref entry has correct content type (ct1 ref when reference_to is ct1)', () => {
const ctInstance = new Entries(constructorParam);
(ctInstance as any).currentUid = 'test-entry';
(ctInstance as any).entryMetaData = [{ uid: 'blt123', ctUid: 'ct1' }];

const referenceFieldSchema = { uid: 'ref', display_name: 'Ref', data_type: 'reference', reference_to: ['ct1'] };
const entryData = [{ uid: 'blt123', _content_type_uid: 'ct1' }];
const tree = [{ uid: 'test-entry', name: 'Test Entry' }];

const result = ctInstance.validateReferenceValues(tree, referenceFieldSchema as any, entryData);

expect(result).to.have.length(0);
});

fancy
.stdout({ print: process.env.PRINT === 'true' || false })
.it('should normalize reference_to string and allow matching ref (ct1 when reference_to is string ct1)', () => {
const ctInstance = new Entries(constructorParam);
(ctInstance as any).currentUid = 'test-entry';
(ctInstance as any).entryMetaData = [{ uid: 'blt456', ctUid: 'ct1' }];

const referenceFieldSchema = { uid: 'ref', display_name: 'Ref', data_type: 'reference', reference_to: 'ct1' };
const entryData = [{ uid: 'blt456', _content_type_uid: 'ct1' }];
const tree = [{ uid: 'test-entry', name: 'Test Entry' }];

const result = ctInstance.validateReferenceValues(tree, referenceFieldSchema as any, entryData);

expect(result).to.have.length(0);
});
});

describe('validateModularBlocksField method', () => {
Expand Down Expand Up @@ -1365,5 +1414,130 @@ describe('Entries module', () => {

// Should not throw - method is void
});

fancy
.stdout({ print: process.env.PRINT === 'true' || false })
.it('should flag JSON RTE embed when ref has wrong content type (ct2 when reference_to is ct1,sys_assets)', () => {
const ctInstance = new Entries(constructorParam);
(ctInstance as any).currentUid = 'test-entry';
(ctInstance as any).missingRefs = { 'test-entry': [] };
(ctInstance as any).entryMetaData = [{ uid: 'blt123', ctUid: 'ct2' }];

const schema = {
uid: 'json_rte',
display_name: 'JSON RTE',
data_type: 'richtext',
reference_to: ['ct1', 'sys_assets'],
};
const child = {
type: 'embed',
uid: 'child-uid',
attrs: { 'entry-uid': 'blt123', 'content-type-uid': 'ct2' },
children: [],
};
const tree: Record<string, unknown>[] = [];

(ctInstance as any).jsonRefCheck(tree, schema, child);

expect((ctInstance as any).missingRefs['test-entry']).to.have.length(1);
expect((ctInstance as any).missingRefs['test-entry'][0].missingRefs).to.deep.include({
uid: 'blt123',
'content-type-uid': 'ct2',
});
});
});

describe('fixMissingReferences method', () => {
fancy
.stdout({ print: process.env.PRINT === 'true' || false })
.it('should filter out ref when ref has wrong content type (ct2 when reference_to is ct1)', () => {
const ctInstance = new Entries({ ...constructorParam, fix: true });
(ctInstance as any).currentUid = 'test-entry';
(ctInstance as any).missingRefs = { 'test-entry': [] };
(ctInstance as any).entryMetaData = [{ uid: 'blt123', ctUid: 'ct2' }];

const field = {
uid: 'ref_field',
display_name: 'Ref',
data_type: 'reference',
reference_to: ['ct1'],
};
const entry = [{ uid: 'blt123', _content_type_uid: 'ct2' }];
const tree = [{ uid: 'test-entry', name: 'Test Entry' }];

const result = ctInstance.fixMissingReferences(tree, field as any, entry);

expect(result).to.have.length(0);
expect((ctInstance as any).missingRefs['test-entry']).to.have.length(1);
expect((ctInstance as any).missingRefs['test-entry'][0].missingRefs).to.deep.include({
uid: 'blt123',
_content_type_uid: 'ct2',
});
});
});

describe('jsonRefCheck in fix mode', () => {
fancy
.stdout({ print: process.env.PRINT === 'true' || false })
.it('should return null when ref has wrong content type (fix mode)', () => {
const ctInstance = new Entries({ ...constructorParam, fix: true });
(ctInstance as any).currentUid = 'test-entry';
(ctInstance as any).missingRefs = { 'test-entry': [] };
(ctInstance as any).entryMetaData = [{ uid: 'blt123', ctUid: 'ct2' }];

const schema = {
uid: 'json_rte',
display_name: 'JSON RTE',
data_type: 'richtext',
reference_to: ['ct1'],
};
const child = {
type: 'embed',
uid: 'child-uid',
attrs: { 'entry-uid': 'blt123', 'content-type-uid': 'ct2' },
children: [],
};
const tree: Record<string, unknown>[] = [];

const result = (ctInstance as any).jsonRefCheck(tree, schema, child);

expect(result).to.be.null;
});
});

describe('isRefContentTypeAllowed helper', () => {
const callHelper = (refCtUid: string | undefined, referenceTo: string | string[] | undefined) => {
const ctInstance = new Entries(constructorParam);
return (ctInstance as any).isRefContentTypeAllowed(refCtUid, referenceTo);
};

fancy.stdout({ print: process.env.PRINT === 'true' || false }).it('returns true when refCtUid is in reference_to', () => {
expect(callHelper('ct1', ['ct1', 'ct2'])).to.be.true;
});

fancy.stdout({ print: process.env.PRINT === 'true' || false }).it('returns false when refCtUid is not in reference_to', () => {
expect(callHelper('ct2', ['ct1'])).to.be.false;
});

fancy.stdout({ print: process.env.PRINT === 'true' || false }).it('returns true when reference_to is undefined', () => {
expect(callHelper('ct1', undefined)).to.be.true;
});

fancy.stdout({ print: process.env.PRINT === 'true' || false }).it('normalizes reference_to string and allows matching refCtUid', () => {
expect(callHelper('ct1', 'ct1')).to.be.true;
expect(callHelper('ct2', 'ct1')).to.be.false;
});

fancy.stdout({ print: process.env.PRINT === 'true' || false }).it('returns false when reference_to is empty array', () => {
expect(callHelper('ct1', [])).to.be.false;
});

fancy.stdout({ print: process.env.PRINT === 'true' || false }).it('returns true when refCtUid is undefined', () => {
expect(callHelper(undefined, ['ct1'])).to.be.true;
});

fancy.stdout({ print: process.env.PRINT === 'true' || false }).it('returns true when refCtUid is in skipRefs', () => {
expect(callHelper('sys_assets', ['ct1'])).to.be.true;
});
});
});
2 changes: 1 addition & 1 deletion packages/contentstack-import/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"author": "Contentstack",
"bugs": "https://github.com/contentstack/cli/issues",
"dependencies": {
"@contentstack/cli-audit": "~2.0.0-beta.4",
"@contentstack/cli-audit": "~2.0.0-beta.5",
"@contentstack/cli-command": "~2.0.0-beta",
"@contentstack/cli-utilities": "~2.0.0-beta",
"@contentstack/cli-variants": "~2.0.0-beta.5",
Expand Down
4 changes: 2 additions & 2 deletions packages/contentstack/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@contentstack/cli",
"description": "Command-line tool (CLI) to interact with Contentstack",
"version": "2.0.0-beta.12",
"version": "2.0.0-beta.13",
"author": "Contentstack",
"bin": {
"csdx": "./bin/run.js"
Expand All @@ -22,7 +22,7 @@
"prepack": "pnpm compile && oclif manifest && oclif readme"
},
"dependencies": {
"@contentstack/cli-audit": "~2.0.0-beta.4",
"@contentstack/cli-audit": "~2.0.0-beta.5",
"@contentstack/cli-cm-export": "~2.0.0-beta.9",
"@contentstack/cli-cm-import": "~2.0.0-beta.9",
"@contentstack/cli-auth": "~2.0.0-beta.5",
Expand Down
Loading
Loading