Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add delete specific NUTs #947

Merged
merged 5 commits into from
Mar 22, 2024
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
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,4 @@ sf plugins

<!-- commands -->

# Command Topics

- [`sf project`](docs/project.md)

<!-- commandsstop -->
63 changes: 62 additions & 1 deletion test/nuts/destructive/destructiveChanges.nut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@
*/

import * as path from 'node:path';
import { writeFileSync } from 'node:fs';
import { fileURLToPath } from 'node:url';
import { expect } from 'chai';
import { assert, expect } from 'chai';
import { execCmd } from '@salesforce/cli-plugins-testkit';
import { SourceTestkit } from '@salesforce/source-testkit';
import { AuthInfo, Connection } from '@salesforce/core';
import { DeployMessage } from '@salesforce/source-deploy-retrieve';
import { DeployResultJson } from '../../../src/utils/types.js';

const isNameObsolete = async (username: string, memberType: string, memberName: string): Promise<boolean> => {
const connection = await Connection.create({
Expand Down Expand Up @@ -99,6 +102,64 @@ describe('project deploy start --destructive NUTs', () => {
expect(deleted).to.be.true;
});

it('should delete and deploy the same component', async () => {
const { apexName } = createApexClass();
let deleted = await isNameObsolete(testkit.username, 'ApexClass', apexName);

expect(deleted).to.be.false;
createManifest(`ApexClass:${apexName}`, 'pre');
createManifest(`ApexClass:${apexName}`, 'package');

const result = execCmd<DeployResultJson>(
'project:deploy:start --json --manifest package.xml --pre-destructive-changes destructiveChangesPre.xml',
{
ensureExitCode: 0,
}
);

deleted = await isNameObsolete(testkit.username, 'ApexClass', apexName);
expect(deleted).to.be.false;

const successes = result?.jsonOutput?.result.details?.componentSuccesses as DeployMessage[];
assert(successes);
// 1 package, 2 of the same apex classes
expect(successes.length).to.equal(3);
expect(successes[0].deleted).to.be.true;
expect(successes[2].deleted).to.be.false;
});

it('should delete and get file information with an empty deploy package', async () => {
const { apexName } = createApexClass();
let deleted = await isNameObsolete(testkit.username, 'ApexClass', apexName);

expect(deleted).to.be.false;
createManifest(`ApexClass:${apexName}`, 'pre');

writeFileSync(
path.join(testkit.projectDir, 'package.xml'),
'<?xml version="1.0" encoding="UTF-8"?>\n' +
'<Package xmlns="http://soap.sforce.com/2006/04/metadata">\n' +
' <version>59.0</version>\n' +
'</Package>'
);

const result = execCmd<DeployResultJson>(
'project:deploy:start --json --manifest package.xml --pre-destructive-changes destructiveChangesPre.xml',
{
ensureExitCode: 0,
}
);

deleted = await isNameObsolete(testkit.username, 'ApexClass', apexName);
expect(deleted).to.be.true;

const files = result?.jsonOutput?.result.files;
assert(files);
// 1 .cls, 1 .cls-meta.xml
expect(files.length).to.equal(2);
expect(files.filter((c) => c.fullName === 'a').every((c) => c.filePath !== undefined)).to.be.true;
});

it('should delete an ApexClass and then deploy a class with --purge-on-delete', async () => {
const { apexName } = createApexClass();
let deleted = await isNameObsolete(testkit.username, 'ApexClass', apexName);
Expand Down
1 change: 0 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10193,7 +10193,6 @@ [email protected]:
integrity sha512-ILEIE97kDZvF9Wb9f6h5aXK4swSlKGUcOEGiIYb2OOu/IrDU9iwj0fD//SsA6E5ibwJxpEvhullJY4Sl4GcpAw==

"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0:
name wrap-ansi-cjs
version "7.0.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
Expand Down
Loading