Skip to content

Commit 02b647a

Browse files
committed
fix: add test for deleted source table
1 parent 28aa4c0 commit 02b647a

2 files changed

Lines changed: 84 additions & 2 deletions

File tree

src/utils/deploy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ export async function buildPreDestructiveFileResponses(
287287
);
288288

289289
if (preDestructiveComponents.length === 0) {
290-
return [];
290+
return [] as FileResponseSuccess[];
291291
}
292292

293293
// Build metadata entries for ComponentSetBuilder

test/utils/output.test.ts

Lines changed: 83 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,13 @@ import path from 'node:path';
1717
import { stripVTControlCharacters } from 'node:util';
1818
import { assert, expect, config } from 'chai';
1919
import sinon from 'sinon';
20-
import { DeployMessage, DeployResult, Failures, FileResponse } from '@salesforce/source-deploy-retrieve';
20+
import {
21+
DeployMessage,
22+
DeployResult,
23+
Failures,
24+
FileResponse,
25+
ComponentStatus,
26+
} from '@salesforce/source-deploy-retrieve';
2127
import { Ux } from '@salesforce/sf-plugins-core';
2228
import { getCoverageFormattersOptions } from '../../src/utils/coverage.js';
2329
import { getZipFileSize } from '../../src/utils/output.js';
@@ -172,6 +178,82 @@ describe('deployResultFormatter', () => {
172178
});
173179
});
174180

181+
describe('displayDeletes', () => {
182+
let tableStub: sinon.SinonStub;
183+
184+
beforeEach(() => {
185+
tableStub = sandbox.stub(Ux.prototype, 'table');
186+
});
187+
188+
it('should display pre-destructive delete files in Deleted Source table', () => {
189+
const deployResult = getDeployResult('successSync');
190+
191+
// Create pre-destructive file responses with proper typing
192+
const preDestructiveFiles: FileResponse[] = [
193+
{
194+
fullName: 'CustomObject__c',
195+
type: 'CustomObject',
196+
state: ComponentStatus.Deleted,
197+
filePath: 'force-app/main/default/objects/CustomObject__c/CustomObject__c.object-meta.xml',
198+
},
199+
{
200+
fullName: 'CustomField__c.TestField__c',
201+
type: 'CustomField',
202+
state: ComponentStatus.Deleted,
203+
filePath: 'force-app/main/default/objects/CustomObject__c/fields/TestField__c.field-meta.xml',
204+
},
205+
];
206+
207+
// Pass pre-destructive files as extraDeletes to formatter
208+
// eslint-disable-next-line @typescript-eslint/no-explicit-any,@typescript-eslint/no-unsafe-argument
209+
const formatter = new DeployResultFormatter(deployResult, { verbose: true }, preDestructiveFiles as any);
210+
formatter.display();
211+
212+
// The formatter should call table() to display the Deleted Source
213+
const deletesTableCall = tableStub.getCalls().find((call) => {
214+
const callArg = call.args[0] as { title?: string };
215+
return callArg?.title && callArg.title.includes('Deleted Source');
216+
});
217+
218+
expect(deletesTableCall).to.exist;
219+
if (deletesTableCall) {
220+
const tableArg = deletesTableCall.args[0] as {
221+
data: Array<{ fullName: string; type: string; filePath: string; state: string }>;
222+
};
223+
expect(tableArg.data).to.deep.equal([
224+
{
225+
fullName: 'CustomObject__c',
226+
type: 'CustomObject',
227+
state: 'Deleted',
228+
filePath: 'force-app/main/default/objects/CustomObject__c/CustomObject__c.object-meta.xml',
229+
},
230+
{
231+
fullName: 'CustomField__c.TestField__c',
232+
type: 'CustomField',
233+
state: 'Deleted',
234+
filePath: 'force-app/main/default/objects/CustomObject__c/fields/TestField__c.field-meta.xml',
235+
},
236+
]);
237+
}
238+
});
239+
240+
it('should not display Deleted Source table when there are no deletes', () => {
241+
const deployResult = getDeployResult('successSync');
242+
243+
// Pass empty pre-destructive files
244+
const formatter = new DeployResultFormatter(deployResult, { verbose: true }, []);
245+
formatter.display();
246+
247+
// Verify no Deleted Source table is displayed
248+
const deletesTableCall = tableStub.getCalls().find((call) => {
249+
const callArg = call.args[0] as { title?: string };
250+
return callArg?.title && callArg.title.includes('Deleted Source');
251+
});
252+
253+
expect(deletesTableCall).to.not.exist;
254+
});
255+
});
256+
175257
describe('coverage functions', () => {
176258
describe('getCoverageFormattersOptions', () => {
177259
it('clover, json', () => {

0 commit comments

Comments
 (0)