Skip to content

Commit

Permalink
test: add delete specific NUTs
Browse files Browse the repository at this point in the history
  • Loading branch information
WillieRuemmele committed Mar 22, 2024
1 parent 4142706 commit 66f055b
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 80 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"@salesforce/kit": "^3.0.15",
"@salesforce/plugin-info": "^3.0.28",
"@salesforce/sf-plugins-core": "^7.1.15",
"@salesforce/source-deploy-retrieve": "^10.5.3",
"@salesforce/source-deploy-retrieve": "^10.5.5",
"@salesforce/source-tracking": "^5.1.18",
"@salesforce/ts-types": "^2.0.9",
"chalk": "^5.3.0"
Expand Down
62 changes: 61 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,63 @@ 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');

const result = execCmd<DeployResultJson>(
'project:deploy:start --json --manifest destructiveChangesPre.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.filter((c) => c.fullName === 'a').some((c) => c.deleted === true)).to.be.true;
expect(successes.filter((c) => c.fullName === 'a').some((c) => c.deleted === false)).to.be.true;
});

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
112 changes: 34 additions & 78 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1865,41 +1865,7 @@
wordwrap "^1.0.0"
wrap-ansi "^7.0.0"

"@oclif/core@^3.11.0", "@oclif/core@^3.15.1", "@oclif/core@^3.18.1", "@oclif/core@^3.18.2", "@oclif/core@^3.19.1", "@oclif/core@^3.19.2", "@oclif/core@^3.20.0", "@oclif/core@^3.23.0":
version "3.23.0"
resolved "https://registry.yarnpkg.com/@oclif/core/-/core-3.23.0.tgz#d0ccc5f99c376e4bcfce04e8e94efae8417a53f8"
integrity sha512-giQ/8Ft8yXWg4IyPVtynPb7ihoQsa3A/1Q53UIJIhh+8k+EedE3lJ01yn6sq6Ha35IGqsG1WhkeHzlJIuldEaw==
dependencies:
"@types/cli-progress" "^3.11.5"
ansi-escapes "^4.3.2"
ansi-styles "^4.3.0"
cardinal "^2.1.1"
chalk "^4.1.2"
clean-stack "^3.0.1"
cli-progress "^3.12.0"
color "^4.2.3"
debug "^4.3.4"
ejs "^3.1.9"
get-package-type "^0.1.0"
globby "^11.1.0"
hyperlinker "^1.0.0"
indent-string "^4.0.0"
is-wsl "^2.2.0"
js-yaml "^3.14.1"
minimatch "^9.0.3"
natural-orderby "^2.0.3"
object-treeify "^1.1.33"
password-prompt "^1.1.3"
slice-ansi "^4.0.0"
string-width "^4.2.3"
strip-ansi "^6.0.1"
supports-color "^8.1.1"
supports-hyperlinks "^2.2.0"
widest-line "^3.1.0"
wordwrap "^1.0.0"
wrap-ansi "^7.0.0"

"@oclif/core@^3.25.2":
"@oclif/core@^3.11.0", "@oclif/core@^3.15.1", "@oclif/core@^3.18.1", "@oclif/core@^3.18.2", "@oclif/core@^3.19.1", "@oclif/core@^3.19.2", "@oclif/core@^3.20.0", "@oclif/core@^3.23.0", "@oclif/core@^3.25.2":
version "3.25.3"
resolved "https://registry.yarnpkg.com/@oclif/core/-/core-3.25.3.tgz#dac0e604c33267f879d3233cd4d0730146db4793"
integrity sha512-2TLZmqnDZos9h73KbrdKqvUQEXIPpUfEzgIfqdQRZwszfk1RtiHAb/7ihtnJICnRRVXlD4XLDmUlY4cFJ0ka4g==
Expand Down Expand Up @@ -2280,29 +2246,10 @@
"@salesforce/ts-types" "^2.0.9"
chalk "^5.3.0"

"@salesforce/source-deploy-retrieve@^10.0.0", "@salesforce/source-deploy-retrieve@^10.5.1":
version "10.5.1"
resolved "https://registry.yarnpkg.com/@salesforce/source-deploy-retrieve/-/source-deploy-retrieve-10.5.1.tgz#4afa68b715d269764f995a79b224b4f848f670ff"
integrity sha512-4xeVhKzi0wpzlwKj06hAL3EjJaRuMyx7xZsTr8T0/GFaEfsML14aUV3imMd0V3DcZRJ2oo+a9UrUYy5KnP76Kw==
dependencies:
"@salesforce/core" "^6.7.0"
"@salesforce/kit" "^3.0.15"
"@salesforce/ts-types" "^2.0.9"
fast-levenshtein "^3.0.0"
fast-xml-parser "^4.3.5"
got "^11.8.6"
graceful-fs "^4.2.11"
ignore "^5.3.1"
jszip "^3.10.1"
mime "2.6.0"
minimatch "^5.1.6"
proxy-agent "^6.4.0"
ts-retry-promise "^0.7.1"

"@salesforce/source-deploy-retrieve@^10.5.3":
version "10.5.3"
resolved "https://registry.yarnpkg.com/@salesforce/source-deploy-retrieve/-/source-deploy-retrieve-10.5.3.tgz#c994a5522ce187bfc59bbdb76edfb550453a8025"
integrity sha512-gw28Co2twQ6GSIF94DdWxx6htBLWKIsMhaKlydfymoAp3kZrFmALRPh8Dj8RDQWV8wrSmzWqDFX9iGoldHZDbg==
"@salesforce/source-deploy-retrieve@^10.0.0", "@salesforce/source-deploy-retrieve@^10.5.1", "@salesforce/source-deploy-retrieve@^10.5.3", "@salesforce/source-deploy-retrieve@^10.5.5":
version "10.5.5"
resolved "https://registry.yarnpkg.com/@salesforce/source-deploy-retrieve/-/source-deploy-retrieve-10.5.5.tgz#c2680de777e4b392a5f02631ca1cd385cad72c93"
integrity sha512-o+c/qD9QojXIPMOuteUSdrbx/GI9HS0jFv49NcVrZX1Rzm/ZUk5JHkLzJtiUVQOEnBg4VVnFh2rBarPh0x6dWg==
dependencies:
"@salesforce/core" "^6.7.0"
"@salesforce/kit" "^3.0.15"
Expand Down Expand Up @@ -2334,22 +2281,7 @@
shelljs "^0.8.4"
sinon "^10.0.0"

"@salesforce/source-tracking@^5.0.0":
version "5.1.14"
resolved "https://registry.yarnpkg.com/@salesforce/source-tracking/-/source-tracking-5.1.14.tgz#ae2c02d687099e68508e327545f3b123a71dced2"
integrity sha512-wrxFM5Wz4GekH4R+eAd+h780K4qNIU7/77Frua5HDHvORcj07zGR8prJ2zG2/bbYwaclojexH9zHi0RHe2LMoA==
dependencies:
"@oclif/core" "^3.23.0"
"@salesforce/core" "^6.7.0"
"@salesforce/kit" "^3.0.15"
"@salesforce/source-deploy-retrieve" "^10.5.1"
"@salesforce/ts-types" "^2.0.9"
fast-xml-parser "^4.2.5"
graceful-fs "^4.2.11"
isomorphic-git "1.23.0"
ts-retry-promise "^0.8.0"

"@salesforce/source-tracking@^5.1.18":
"@salesforce/source-tracking@^5.0.0", "@salesforce/source-tracking@^5.1.18":
version "5.1.18"
resolved "https://registry.yarnpkg.com/@salesforce/source-tracking/-/source-tracking-5.1.18.tgz#aea622c04ac199b2288b3a94c6b8e8f207c438f7"
integrity sha512-V8itdxwfP72Kq26psNdxi3JI3tQRdxzViKUQM5w33B6vahWJS3P3nBOzIFJGu+J9/SMDUHRpPYTwUL84yXdoyA==
Expand Down Expand Up @@ -9458,7 +9390,16 @@ ssri@^9.0.0:
dependencies:
minipass "^3.1.1"

"string-width-cjs@npm:string-width@^4.2.0", "string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.0.0, string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
"string-width-cjs@npm:string-width@^4.2.0":
version "4.2.3"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
dependencies:
emoji-regex "^8.0.0"
is-fullwidth-code-point "^3.0.0"
strip-ansi "^6.0.1"

"string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.0.0, string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
version "4.2.3"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
Expand Down Expand Up @@ -9517,7 +9458,14 @@ string_decoder@~1.1.1:
dependencies:
safe-buffer "~5.1.0"

"strip-ansi-cjs@npm:strip-ansi@^6.0.1", [email protected], strip-ansi@^6.0.0, strip-ansi@^6.0.1:
"strip-ansi-cjs@npm:strip-ansi@^6.0.1":
version "6.0.1"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
dependencies:
ansi-regex "^5.0.1"

[email protected], strip-ansi@^6.0.0, strip-ansi@^6.0.1:
version "6.0.1"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
Expand Down Expand Up @@ -10247,8 +10195,7 @@ [email protected]:
resolved "https://registry.yarnpkg.com/workerpool/-/workerpool-6.2.1.tgz#46fc150c17d826b86a008e5a4508656777e9c343"
integrity sha512-ILEIE97kDZvF9Wb9f6h5aXK4swSlKGUcOEGiIYb2OOu/IrDU9iwj0fD//SsA6E5ibwJxpEvhullJY4Sl4GcpAw==

"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0:
name wrap-ansi-cjs
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0":
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 All @@ -10266,6 +10213,15 @@ wrap-ansi@^6.2.0:
string-width "^4.1.0"
strip-ansi "^6.0.0"

wrap-ansi@^7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
dependencies:
ansi-styles "^4.0.0"
string-width "^4.1.0"
strip-ansi "^6.0.0"

wrap-ansi@^8.1.0:
version "8.1.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-8.1.0.tgz#56dc22368ee570face1b49819975d9b9a5ead214"
Expand Down

0 comments on commit 66f055b

Please sign in to comment.