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

fix: pass org data when building ComponentSet with wildcard metadata #824

Merged
merged 6 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
fix: pass org data when building ComponentSet with wildcard metadata
  • Loading branch information
shetzel committed Dec 1, 2023
commit fc6f00f434bc2fc00ebc7172523d5976a1fc262d
14 changes: 14 additions & 0 deletions src/commands/project/retrieve/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,19 @@ const buildRetrieveAndDeleteTargets = async (
}
return result;
} else {
// check if we're retrieving metadata based on a pattern ...
let retrieveFromOrg: string | undefined;
if (flags.metadata) {
flags.metadata.some((mdEntry) => {
const mdName = mdEntry.split(':')[1];
if (mdName?.includes('*') && mdName?.length > 1 && !mdName?.includes('.*')) {
retrieveFromOrg = flags['target-org'].getUsername();
return true;
}
return false;
});
}

return {
componentSetFromNonDeletes: await ComponentSetBuilder.build({
sourceapiversion: (
Expand All @@ -399,6 +412,7 @@ const buildRetrieveAndDeleteTargets = async (
},
}
: {}),
org: retrieveFromOrg ? { username: retrieveFromOrg, exclude: [] } : undefined,
}),
};
}
Expand Down
17 changes: 17 additions & 0 deletions test/commands/retrieve/start.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,23 @@ describe('project retrieve start', () => {
ensureRetrieveArgs({ format: 'source' });
});

it('should pass along metadata and org for wildcard matching', async () => {
const metadata = ['ApexClass:MyC*'];
const result = await RetrieveMetadata.run(['--metadata', metadata[0], '--json']);
expect(result).to.deep.equal(expectedResults);
ensureCreateComponentSetArgs({
metadata: {
metadataEntries: metadata,
directoryPaths: [expectedDirectoryPath],
},
org: {
username: testOrg.username,
exclude: [],
},
});
ensureRetrieveArgs({ format: 'source' });
});

it('should pass along manifest', async () => {
const manifest = 'package.xml';
const result = await RetrieveMetadata.run(['--manifest', manifest, '--json']);
Expand Down
51 changes: 51 additions & 0 deletions test/nuts/deploy/metadata.nut.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright (c) 2023, salesforce.com, inc.
* All rights reserved.
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

import { fileURLToPath } from 'node:url';
import { expect } from 'chai';
import { SourceTestkit } from '@salesforce/source-testkit';
import { DeployResultJson } from '../../../src/utils/types.js';

describe('deploy metadata NUTs', () => {
let testkit: SourceTestkit;

before(async () => {
testkit = await SourceTestkit.create({
repository: 'https://github.com/trailheadapps/dreamhouse-lwc.git',
nut: fileURLToPath(import.meta.url),
});
await testkit.deploy({ args: '--source-dir force-app', exitCode: 0 });
});

after(async () => {
await testkit?.clean();
});

it('should deploy ApexClasses from wildcard match (single character)', async () => {
const response = await testkit.deploy({ args: '--metadata "ApexClass:P*"' });
expect(response?.status).to.equal(0);
const result = response?.result as unknown as DeployResultJson;
expect(result.success).to.be.true;
expect(result.files.length).to.equal(4);
result.files.forEach((f) => {
expect(f.type).to.equal('ApexClass');
expect(['PagedResult', 'PropertyController']).to.include(f.fullName);
});
});

it('should deploy ApexClasses from wildcard match (2 characters)', async () => {
const response = await testkit.deploy({ args: '--metadata "ApexClass:Pa*"' });
expect(response?.status).to.equal(0);
const result = response?.result as unknown as DeployResultJson;
expect(result.success).to.be.true;
expect(result.files.length).to.equal(2);
result.files.forEach((f) => {
expect(f.type).to.equal('ApexClass');
expect(f.fullName).to.equal('PagedResult');
});
});
});
43 changes: 43 additions & 0 deletions test/nuts/retrieve/metadata.nut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { fileURLToPath } from 'node:url';
import { execCmd } from '@salesforce/cli-plugins-testkit';
import { SourceTestkit } from '@salesforce/source-testkit';
import { expect } from 'chai';
import { RetrieveResultJson } from '../../../src/utils/types.js';

const ELECTRON = { id: '04t6A000002zgKSQAY', name: 'ElectronBranding' };

Expand Down Expand Up @@ -57,6 +58,48 @@ describe('retrieve metadata NUTs', () => {
await testkit.retrieve({ args: '--metadata ApexClass AuraDefinitionBundle --output-dir myOutput' });
await testkit.expect.filesToBeRetrieved(['myOutput/classes/*', 'myOutput/aura/**/*']);
});

it('should retrieve ApexClasses from wildcard match', async () => {
const response = await testkit.retrieve({ args: '--metadata "ApexClass:Test*"' });
expect(response?.status).to.equal(0);
const result = response?.result as unknown as RetrieveResultJson;
expect(result.success).to.be.true;
expect(result.files.length).to.equal(4);
result.files.forEach((f) => {
expect(f.type).to.equal('ApexClass');
expect(['TestSampleDataController', 'TestPropertyController']).to.include(f.fullName);
});
await testkit.expect.filesToBeRetrieved(['force-app/main/default/classes/Test*']);
});

it('should retrieve ApexClasses from wildcard match without already existing in the project', async () => {
const forceAppDir = path.join(testkit.projectDir, 'force-app');
const forceAppDirTmp = path.join(testkit.projectDir, 'force-app-tmp');

try {
fs.cpSync(forceAppDir, forceAppDirTmp, { recursive: true });
fs.rmSync(forceAppDir, { recursive: true, force: true });
expect(fs.existsSync(forceAppDir)).to.be.false;
const defaultDir = path.join(forceAppDir, 'main', 'default');
fs.mkdirSync(defaultDir, { recursive: true });

const response = await testkit.retrieve({ args: '--metadata "ApexClass:Test*"' });
expect(response?.status).to.equal(0);
const result = response?.result as unknown as RetrieveResultJson;
expect(result.success).to.be.true;
expect(result.files.length).to.equal(4);
result.files.forEach((f) => {
expect(f.type).to.equal('ApexClass');
expect(['TestSampleDataController', 'TestPropertyController']).to.include(f.fullName);
});
await testkit.expect.filesToBeRetrieved(['force-app/main/default/classes/Test*']);
} finally {
if (fs.existsSync(forceAppDirTmp)) {
fs.cpSync(forceAppDirTmp, forceAppDir, { recursive: true });
fs.rmSync(forceAppDirTmp, { recursive: true, force: true });
}
}
});
});

describe('--manifest flag', () => {
Expand Down
Loading