Skip to content

Commit 51c82cf

Browse files
author
naman-contentstack
committed
updated test cases
1 parent 8678c6e commit 51c82cf

File tree

1 file changed

+25
-15
lines changed

1 file changed

+25
-15
lines changed

packages/contentstack-branches/test/unit/utils/csv-utility.test.ts

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import { describe, it, beforeEach, afterEach } from 'mocha';
22
import { expect } from 'chai';
33
import { stub } from 'sinon';
4-
import { writeFileSync, existsSync, mkdirSync } from 'fs';
54
import { join } from 'path';
65
import { cliux } from '@contentstack/cli-utilities';
76
import * as csvUtility from '../../../src/utils/csv-utility';
8-
import { BranchDiffVerboseRes, CSVRow } from '../../../src/interfaces';
7+
import { BranchDiffVerboseRes } from '../../../src/interfaces';
98

109
describe('CSV Utility Testcases', () => {
1110
let writeFileSyncStub, existsSyncStub, mkdirSyncStub, cliuxPrintStub;
@@ -42,7 +41,15 @@ describe('CSV Utility Testcases', () => {
4241
path: 'title',
4342
displayName: 'Title',
4443
uid: 'title',
45-
field: 'text'
44+
field: 'text',
45+
propertyChanges: [
46+
{
47+
property: 'default_value',
48+
changeType: 'modified',
49+
oldValue: 'Old Title',
50+
newValue: 'New Title'
51+
}
52+
]
4653
}
4754
],
4855
added: [
@@ -85,37 +92,42 @@ describe('CSV Utility Testcases', () => {
8592
const result = csvUtility.generateCSVDataFromVerbose(mockVerboseRes);
8693

8794
expect(result).to.be.an('array');
88-
expect(result.length).to.equal(5); // 1 modified + 1 added + 1 deleted + 1 added CT + 1 deleted CT
95+
expect(result.length).to.equal(5); // 1 modified property change + 1 added + 1 deleted + 1 added CT + 1 deleted CT
8996

9097
// Check modified field
9198
const modifiedRow = result.find(row => row.fieldName === 'Title');
9299
expect(modifiedRow).to.exist;
93100
expect(modifiedRow?.operation).to.equal('modified');
94-
expect(modifiedRow?.modifiedValue).to.equal('text field \'Title\' has been modified');
101+
expect(modifiedRow?.sourceBranchValue).to.equal('New Title');
102+
expect(modifiedRow?.targetBranchValue).to.equal('Old Title');
95103

96104
// Check added field
97105
const addedRow = result.find(row => row.fieldName === 'New Field');
98106
expect(addedRow).to.exist;
99107
expect(addedRow?.operation).to.equal('added');
100-
expect(addedRow?.modifiedValue).to.equal('New text field \'New Field\' added to content type');
108+
expect(addedRow?.sourceBranchValue).to.equal('N/A');
109+
expect(addedRow?.targetBranchValue).to.equal('new_field');
101110

102111
// Check deleted field
103112
const deletedRow = result.find(row => row.fieldName === 'Old Field');
104113
expect(deletedRow).to.exist;
105114
expect(deletedRow?.operation).to.equal('deleted');
106-
expect(deletedRow?.modifiedValue).to.equal('text field \'Old Field\' removed from content type');
115+
expect(deletedRow?.sourceBranchValue).to.equal('old_field');
116+
expect(deletedRow?.targetBranchValue).to.equal('N/A');
107117

108118
// Check added content type
109119
const addedCTRow = result.find(row => row.contentTypeName === 'New Content Type');
110120
expect(addedCTRow).to.exist;
111121
expect(addedCTRow?.operation).to.equal('added');
112-
expect(addedCTRow?.modifiedValue).to.equal('Content type \'New Content Type\' added to stack');
122+
expect(addedCTRow?.sourceBranchValue).to.equal('N/A');
123+
expect(addedCTRow?.targetBranchValue).to.equal('N/A');
113124

114125
// Check deleted content type
115126
const deletedCTRow = result.find(row => row.contentTypeName === 'Deleted Content Type');
116127
expect(deletedCTRow).to.exist;
117128
expect(deletedCTRow?.operation).to.equal('deleted');
118-
expect(deletedCTRow?.modifiedValue).to.equal('Content type \'Deleted Content Type\' removed from stack');
129+
expect(deletedCTRow?.sourceBranchValue).to.equal('N/A');
130+
expect(deletedCTRow?.targetBranchValue).to.equal('N/A');
119131
});
120132

121133
it('should handle empty verbose results gracefully', () => {
@@ -143,9 +155,8 @@ describe('CSV Utility Testcases', () => {
143155
srNo: 1,
144156
contentTypeName: 'Test CT',
145157
fieldName: 'Test Field',
146-
fieldPath: 'Test CT → Test Field',
158+
fieldPath: 'N/A',
147159
operation: 'modified',
148-
modifiedValue: 'Field modified',
149160
sourceBranchValue: 'new_value',
150161
targetBranchValue: 'old_value'
151162
}
@@ -167,8 +178,8 @@ describe('CSV Utility Testcases', () => {
167178
expect(filePath).to.equal(join(customPath, 'content-types-diff.csv'));
168179

169180
// Verify CSV content
170-
expect(content).to.include('Sr No,Content Type Name,Field Name,Field Path,Operation,Modified Value,Source Branch Value,Target Branch Value');
171-
expect(content).to.include('1,"Test CT","Test Field","Test CT → Test Field","modified","Field modified","new_value","old_value"');
181+
expect(content).to.include('Sr No,Content Type Name,Field Name,Field Path,Operation,Source Branch Value,Target Branch Value');
182+
expect(content).to.include('1,"Test CT","Test Field","N/A","modified","new_value","old_value"');
172183

173184
// Verify success message
174185
expect(cliuxPrintStub.calledWith(`CSV report generated at: ${join(customPath, 'content-types-diff.csv')}`, { color: 'green' })).to.be.true;
@@ -184,9 +195,8 @@ describe('CSV Utility Testcases', () => {
184195
srNo: 1,
185196
contentTypeName: 'Test CT',
186197
fieldName: 'Test Field',
187-
fieldPath: 'Test CT → Test Field',
198+
fieldPath: 'N/A',
188199
operation: 'added',
189-
modifiedValue: 'New field added',
190200
sourceBranchValue: 'N/A',
191201
targetBranchValue: ''
192202
}

0 commit comments

Comments
 (0)