Skip to content

Commit cd9357a

Browse files
authored
Merge pull request #823 from salesforcecli/sh/show-deploy-errors-fix
test: adds a unit test for deploy errors
2 parents 9673a8c + 6adc94e commit cd9357a

File tree

1 file changed

+70
-2
lines changed

1 file changed

+70
-2
lines changed

test/utils/output.test.ts

Lines changed: 70 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import * as path from 'node:path';
88
import { assert, expect, config } from 'chai';
99
import sinon from 'sinon';
10-
import { DeployResult } from '@salesforce/source-deploy-retrieve';
10+
import { DeployMessage, DeployResult, FileResponse } from '@salesforce/source-deploy-retrieve';
1111
import { ux } from '@oclif/core';
1212
import { getCoverageFormattersOptions } from '../../src/utils/coverage.js';
1313
import { DeployResultFormatter } from '../../src/formatters/deployResultFormatter.js';
@@ -24,7 +24,11 @@ describe('deployResultFormatter', () => {
2424

2525
describe('displayFailures', () => {
2626
const deployResultFailure = getDeployResult('failed');
27-
const tableStub = sandbox.stub(ux, 'table');
27+
let tableStub: sinon.SinonStub;
28+
29+
beforeEach(() => {
30+
tableStub = sandbox.stub(ux, 'table');
31+
});
2832

2933
it('prints file responses, and messages from server', () => {
3034
const formatter = new DeployResultFormatter(deployResultFailure, { verbose: true });
@@ -39,6 +43,70 @@ describe('deployResultFormatter', () => {
3943
},
4044
]);
4145
});
46+
47+
it('displays errors from the server not in file responses', () => {
48+
const deployFailure = getDeployResult('failed');
49+
const error1 = {
50+
changed: false,
51+
componentType: 'ApexClass',
52+
created: false,
53+
createdDate: '2021-04-27T22:18:07.000Z',
54+
deleted: false,
55+
fileName: 'classes/ProductController.cls',
56+
fullName: 'ProductController',
57+
success: false,
58+
problemType: 'Error',
59+
problem: 'This component has some problems',
60+
lineNumber: '27',
61+
columnNumber: '18',
62+
} as DeployMessage;
63+
64+
// add package.xml error, which is different from a FileResponse error
65+
const error2 = {
66+
changed: false,
67+
componentType: '',
68+
created: false,
69+
createdDate: '2023-11-17T21:18:36.000Z',
70+
deleted: false,
71+
fileName: 'package.xml',
72+
fullName: 'Create_property',
73+
problem:
74+
"An object 'Create_property' of type Flow was named in package.xml, but was not found in zipped directory",
75+
problemType: 'Error',
76+
success: false,
77+
} as DeployMessage;
78+
79+
deployFailure.response.details.componentFailures = [error1, error2];
80+
sandbox.stub(deployFailure, 'getFileResponses').returns([
81+
{
82+
fullName: error1.fullName,
83+
filePath: error1.fileName,
84+
type: error1.componentType,
85+
state: 'Failed',
86+
lineNumber: error1.lineNumber,
87+
columnNumber: error1.columnNumber,
88+
error: error1.problem,
89+
problemType: error1.problemType,
90+
},
91+
] as FileResponse[]);
92+
const formatter = new DeployResultFormatter(deployFailure, { verbose: true });
93+
formatter.display();
94+
expect(tableStub.callCount).to.equal(1);
95+
expect(tableStub.firstCall.args[0]).to.deep.equal([
96+
{
97+
error: error2.problem,
98+
fullName: error2.fullName,
99+
loc: '',
100+
problemType: error2.problemType,
101+
},
102+
{
103+
error: 'This component has some problems',
104+
fullName: 'ProductController',
105+
loc: '27:18',
106+
problemType: 'Error',
107+
},
108+
]);
109+
});
42110
});
43111

44112
describe('coverage functions', () => {

0 commit comments

Comments
 (0)