Skip to content
Open
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
18 changes: 18 additions & 0 deletions src/formatters/deployResultFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { join } from 'node:path';
import { Ux } from '@salesforce/sf-plugins-core';
import {
ComponentStatus,
DeployNotification,
DeployResult,
FileResponse,
FileResponseFailure,
Expand Down Expand Up @@ -154,6 +155,7 @@ export class DeployResultFormatter extends TestResultsFormatter implements Forma
this.displayTestResults();
this.maybeCreateRequestedReports();
this.displayReplacements();
this.displayNotifications();
}

public determineVerbosity(): Verbosity {
Expand Down Expand Up @@ -297,6 +299,22 @@ export class DeployResultFormatter extends TestResultsFormatter implements Forma
}
}

private displayNotifications(): void {
const notifications: DeployNotification[] = ensureArray(this.result.response.notifications);
if (!notifications.length) return;

ux.log();
ux.table({
data: notifications,
columns: [
{ key: 'messageCode', name: 'Code' },
{ key: 'messageText', name: 'Message' },
],
title: tableHeader('Notifications'),
overflow: 'wrap',
});
}

private displaySuccesses(): void {
const successes = this.relativeFiles.filter(isSdrSuccess);

Expand Down
90 changes: 90 additions & 0 deletions test/utils/output.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,96 @@ describe('deployResultFormatter', () => {
});
});

describe('displayNotifications', () => {
let tableStub: sinon.SinonStub;

beforeEach(() => {
tableStub = sandbox.stub(Ux.prototype, 'table');
});

it('displays notifications table when notifications array is present', () => {
const deployResult = getDeployResult('successSync', {
notifications: [
{
messageCode: 'ApexApiVersionRetirement',
messageText: 'This deployment contains 2 Apex classes with warnings.',
},
{
messageCode: 'ApexApiVersionRetirement',
messageText: 'This deployment contains 1 Apex triggers with warnings.',
},
],
});
const formatter = new DeployResultFormatter(deployResult, { verbose: true });
formatter.display();

const notificationsTableCall = tableStub.getCalls().find((call) => {
const callArg = call.args[0] as { title?: string };
return callArg?.title?.includes('Notifications');
});

expect(notificationsTableCall).to.exist;
if (notificationsTableCall) {
const tableArg = notificationsTableCall.args[0] as {
data: Array<{ messageCode: string; messageText: string }>;
};
expect(tableArg.data).to.have.lengthOf(2);
expect(tableArg.data[0].messageCode).to.equal('ApexApiVersionRetirement');
}
});

it('displays notifications table when a single notification object is present', () => {
const deployResult = getDeployResult('successSync', {
notifications: {
messageCode: 'ApexApiVersionRetirement',
messageText: 'This deployment contains 1 Apex triggers with warnings.',
},
});
const formatter = new DeployResultFormatter(deployResult, { verbose: true });
formatter.display();

const notificationsTableCall = tableStub.getCalls().find((call) => {
const callArg = call.args[0] as { title?: string };
return callArg?.title?.includes('Notifications');
});

expect(notificationsTableCall).to.exist;
if (notificationsTableCall) {
const tableArg = notificationsTableCall.args[0] as {
data: Array<{ messageCode: string; messageText: string }>;
};
expect(tableArg.data).to.have.lengthOf(1);
expect(tableArg.data[0].messageCode).to.equal('ApexApiVersionRetirement');
}
});

it('does not display notifications table when notifications are absent', () => {
const deployResult = getDeployResult('successSync');
const formatter = new DeployResultFormatter(deployResult, { verbose: true });
formatter.display();

const notificationsTableCall = tableStub.getCalls().find((call) => {
const callArg = call.args[0] as { title?: string };
return callArg?.title?.includes('Notifications');
});

expect(notificationsTableCall).to.not.exist;
});

it('includes notifications in JSON output', async () => {
const notifications = [
{
messageCode: 'ApexApiVersionRetirement',
messageText: 'This deployment contains 2 Apex classes with warnings.',
},
];
const deployResult = getDeployResult('successSync', { notifications });
const formatter = new DeployResultFormatter(deployResult, {});
const json = await formatter.getJson();
expect(json).to.have.property('notifications').deep.equal(notifications);
});
});

describe('coverage functions', () => {
describe('getCoverageFormattersOptions', () => {
it('clover, json', () => {
Expand Down
Loading