-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: prevent empty parent xml overwrites (#1308)
* test: snapshot for single field retrieve * test: get folder, tmpDir set up * test: getting paths fixed up * test: testDir cleanup * tests: snapshotTests (broken) * fix: don't blank parent objects that have properties * test: bump deps for xNuts * test: ignore scripts in install
- Loading branch information
Showing
13 changed files
with
313 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
...ify-force-app.expected/force-app/main/default/objects/Broker__c/Broker__c.object-meta.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<CustomObject xmlns="http://soap.sforce.com/2006/04/metadata"> | ||
<actionOverrides> | ||
<actionName>Accept</actionName> | ||
<type>Default</type> | ||
</actionOverrides> | ||
<actionOverrides> | ||
<actionName>CancelEdit</actionName> | ||
<type>Default</type> | ||
</actionOverrides> | ||
<actionOverrides> | ||
<actionName>Clone</actionName> | ||
<type>Default</type> | ||
</actionOverrides> | ||
<actionOverrides> | ||
<actionName>Delete</actionName> | ||
<type>Default</type> | ||
</actionOverrides> | ||
<actionOverrides> | ||
<actionName>Edit</actionName> | ||
<type>Default</type> | ||
</actionOverrides> | ||
<actionOverrides> | ||
<actionName>List</actionName> | ||
<type>Default</type> | ||
</actionOverrides> | ||
<actionOverrides> | ||
<actionName>New</actionName> | ||
<type>Default</type> | ||
</actionOverrides> | ||
<actionOverrides> | ||
<actionName>SaveEdit</actionName> | ||
<type>Default</type> | ||
</actionOverrides> | ||
<actionOverrides> | ||
<actionName>Tab</actionName> | ||
<type>Default</type> | ||
</actionOverrides> | ||
<actionOverrides> | ||
<actionName>View</actionName> | ||
<type>Default</type> | ||
</actionOverrides> | ||
<allowInChatterGroups>false</allowInChatterGroups> | ||
<compactLayoutAssignment>Broker_Compact</compactLayoutAssignment> | ||
<deploymentStatus>Deployed</deploymentStatus> | ||
<enableActivities>false</enableActivities> | ||
<enableBulkApi>true</enableBulkApi> | ||
<enableFeeds>false</enableFeeds> | ||
<enableHistory>false</enableHistory> | ||
<enableReports>true</enableReports> | ||
<enableSearch>true</enableSearch> | ||
<enableSharing>true</enableSharing> | ||
<enableStreamingApi>true</enableStreamingApi> | ||
<label>Broker</label> | ||
<nameField> | ||
<label>Broker Name</label> | ||
<type>Text</type> | ||
</nameField> | ||
<pluralLabel>Brokers</pluralLabel> | ||
<searchLayouts></searchLayouts> | ||
<sharingModel>ReadWrite</sharingModel> | ||
<visibility>Public</visibility> | ||
</CustomObject> |
12 changes: 12 additions & 0 deletions
12
...-app.expected/force-app/main/default/objects/Broker__c/fields/Broker_Id__c.field-meta.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<CustomField xmlns="http://soap.sforce.com/2006/04/metadata"> | ||
<fullName>Broker_Id__c</fullName> | ||
<externalId>true</externalId> | ||
<label>Broker Id</label> | ||
<precision>18</precision> | ||
<required>false</required> | ||
<scale>0</scale> | ||
<trackTrending>false</trackTrending> | ||
<type>Number</type> | ||
<unique>false</unique> | ||
</CustomField> |
10 changes: 10 additions & 0 deletions
10
...orce-app.expected/force-app/main/default/objects/Broker__c/fields/Email__c.field-meta.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<CustomField xmlns="http://soap.sforce.com/2006/04/metadata"> | ||
<fullName>Email__c</fullName> | ||
<externalId>false</externalId> | ||
<label>Email</label> | ||
<required>false</required> | ||
<trackTrending>false</trackTrending> | ||
<type>Email</type> | ||
<unique>false</unique> | ||
</CustomField> |
63 changes: 63 additions & 0 deletions
63
...gleCustomFieldRetrieve/force-app/main/default/objects/Broker__c/Broker__c.object-meta.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<CustomObject xmlns="http://soap.sforce.com/2006/04/metadata"> | ||
<actionOverrides> | ||
<actionName>Accept</actionName> | ||
<type>Default</type> | ||
</actionOverrides> | ||
<actionOverrides> | ||
<actionName>CancelEdit</actionName> | ||
<type>Default</type> | ||
</actionOverrides> | ||
<actionOverrides> | ||
<actionName>Clone</actionName> | ||
<type>Default</type> | ||
</actionOverrides> | ||
<actionOverrides> | ||
<actionName>Delete</actionName> | ||
<type>Default</type> | ||
</actionOverrides> | ||
<actionOverrides> | ||
<actionName>Edit</actionName> | ||
<type>Default</type> | ||
</actionOverrides> | ||
<actionOverrides> | ||
<actionName>List</actionName> | ||
<type>Default</type> | ||
</actionOverrides> | ||
<actionOverrides> | ||
<actionName>New</actionName> | ||
<type>Default</type> | ||
</actionOverrides> | ||
<actionOverrides> | ||
<actionName>SaveEdit</actionName> | ||
<type>Default</type> | ||
</actionOverrides> | ||
<actionOverrides> | ||
<actionName>Tab</actionName> | ||
<type>Default</type> | ||
</actionOverrides> | ||
<actionOverrides> | ||
<actionName>View</actionName> | ||
<type>Default</type> | ||
</actionOverrides> | ||
<allowInChatterGroups>false</allowInChatterGroups> | ||
<compactLayoutAssignment>Broker_Compact</compactLayoutAssignment> | ||
<deploymentStatus>Deployed</deploymentStatus> | ||
<enableActivities>false</enableActivities> | ||
<enableBulkApi>true</enableBulkApi> | ||
<enableFeeds>false</enableFeeds> | ||
<enableHistory>false</enableHistory> | ||
<enableReports>true</enableReports> | ||
<enableSearch>true</enableSearch> | ||
<enableSharing>true</enableSharing> | ||
<enableStreamingApi>true</enableStreamingApi> | ||
<label>Broker</label> | ||
<nameField> | ||
<label>Broker Name</label> | ||
<type>Text</type> | ||
</nameField> | ||
<pluralLabel>Brokers</pluralLabel> | ||
<searchLayouts></searchLayouts> | ||
<sharingModel>ReadWrite</sharingModel> | ||
<visibility>Public</visibility> | ||
</CustomObject> |
12 changes: 12 additions & 0 deletions
12
...FieldRetrieve/force-app/main/default/objects/Broker__c/fields/Broker_Id__c.field-meta.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<CustomField xmlns="http://soap.sforce.com/2006/04/metadata"> | ||
<fullName>Broker_Id__c</fullName> | ||
<externalId>true</externalId> | ||
<label>Broker Id</label> | ||
<precision>18</precision> | ||
<required>false</required> | ||
<scale>0</scale> | ||
<trackTrending>false</trackTrending> | ||
<type>Number</type> | ||
<unique>false</unique> | ||
</CustomField> |
12 changes: 12 additions & 0 deletions
12
test/snapshot/sampleProjects/singleCustomFieldRetrieve/mdapiOutput/objects/Broker__c.object
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<CustomObject xmlns="http://soap.sforce.com/2006/04/metadata"> | ||
<fields> | ||
<fullName>Email__c</fullName> | ||
<externalId>false</externalId> | ||
<label>Email</label> | ||
<required>false</required> | ||
<trackTrending>false</trackTrending> | ||
<type>Email</type> | ||
<unique>false</unique> | ||
</fields> | ||
</CustomObject> |
8 changes: 8 additions & 0 deletions
8
test/snapshot/sampleProjects/singleCustomFieldRetrieve/mdapiOutput/package.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<Package xmlns="http://soap.sforce.com/2006/04/metadata"> | ||
<types> | ||
<members>Broker__c.Email__c</members> | ||
<name>CustomField</name> | ||
</types> | ||
<version>59.0</version> | ||
</Package> |
9 changes: 9 additions & 0 deletions
9
test/snapshot/sampleProjects/singleCustomFieldRetrieve/sfdx-project.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"packageDirectories": [ | ||
{ | ||
"default": true, | ||
"path": "force-app" | ||
} | ||
], | ||
"sourceApiVersion": "59.0" | ||
} |
74 changes: 74 additions & 0 deletions
74
test/snapshot/sampleProjects/singleCustomFieldRetrieve/snapshots.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* 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 * as fs from 'node:fs'; | ||
import * as path from 'node:path'; | ||
import { MetadataConverter } from '../../../../src/convert/metadataConverter'; | ||
import { ComponentSetBuilder } from '../../../../src/collections/componentSetBuilder'; | ||
import { FORCE_APP, MDAPI_OUT, fileSnap, dirEntsToPaths } from '../../helper/conversions'; | ||
|
||
// we don't want failing tests outputting over each other | ||
/* eslint-disable no-await-in-loop */ | ||
|
||
const folder = 'singleCustomFieldRetrieve'; | ||
const tmpFolder = `${folder}Tmp`; | ||
const testOriginalDir = path.join('test', 'snapshot', 'sampleProjects', folder); | ||
const testDir = testOriginalDir.replace(folder, tmpFolder); | ||
|
||
/** | ||
* retrieving a single field retrieves the object, removes the field from it, and leaves a blank object. | ||
* That blank object should NOT overwrite the existing object if it exists in the merge target | ||
*/ | ||
describe('a single field in a CustomObject xml does not overwrite (blank) the existing Object', () => { | ||
before(async () => { | ||
// because we're applying changes over the existing source, move it to a new place | ||
await fs.promises.cp(testOriginalDir, testDir, { | ||
recursive: true, | ||
force: true, | ||
filter: (src) => !src.includes('__snapshots__'), | ||
}); | ||
}); | ||
it('merge a single retrieved CustomField (Email__c) into project', async () => { | ||
// SDR should match the original source | ||
const cs = await ComponentSetBuilder.build({ | ||
sourcepath: [path.join(testDir, MDAPI_OUT)], | ||
}); | ||
// a CS from the destination | ||
const mergeWith = ( | ||
await ComponentSetBuilder.build({ | ||
sourcepath: [path.join(testDir, FORCE_APP)], | ||
}) | ||
).getSourceComponents(); | ||
|
||
const converter = new MetadataConverter(); | ||
|
||
await converter.convert(cs, 'source', { | ||
type: 'merge', | ||
mergeWith, | ||
defaultDirectory: path.resolve(path.join(testDir, FORCE_APP)), | ||
}); | ||
}); | ||
|
||
it(`verify ${FORCE_APP}`, async () => { | ||
await validateSourceDir(FORCE_APP); | ||
}); | ||
|
||
after(async () => { | ||
await fs.promises.rm(testDir, { recursive: true, force: true }); | ||
}); | ||
}); | ||
|
||
const validateSourceDir = async (dir: string): Promise<void> => { | ||
const sourceFiles = dirEntsToPaths( | ||
await fs.promises.readdir(path.join(testDir, dir), { | ||
recursive: true, | ||
withFileTypes: true, | ||
}) | ||
); | ||
for (const file of sourceFiles) { | ||
await fileSnap(file, testOriginalDir, testDir); | ||
} | ||
}; |
Oops, something went wrong.