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: change error message, add UT #1355

Merged
merged 3 commits into from
Jun 28, 2024
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
4 changes: 3 additions & 1 deletion src/resolve/sourceComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,9 @@ export class SourceComponent implements MetadataComponent {
const uniqueElement = this.type.uniqueIdElement;
const matched = uniqueElement ? children.find((c) => getString(c, uniqueElement) === this.name) : undefined;
if (!matched) {
throw new SfError(`Unable to find matching parent xml file for ${this.xml}`);
throw new SfError(
`Invalid XML tags or unable to find matching parent xml file for ${this.type.name} "${this.name}"`
);
}
return matched;
}
Expand Down
20 changes: 20 additions & 0 deletions test/resolve/sourceComponent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
CHILD_1_NAME,
CHILD_1_XML,
CHILD_2_NAME,
CHILD_2_XML,
COMPONENT_1,
COMPONENT_1_XML,
COMPONENT_1_XML_PATH,
Expand All @@ -37,6 +38,7 @@ import {
} from '../mock/type-constants/customObjectTranslationConstant';
import { DecomposedSourceAdapter } from '../../src/resolve/adapters';
import { DE_METAFILE } from '../mock/type-constants/digitalExperienceBundleConstants';
import { XML_NS_KEY, XML_NS_URL } from '../../src/common';
import { RegistryTestUtil } from './registryTestUtil';

Messages.importMessagesDirectory(__dirname);
Expand Down Expand Up @@ -487,6 +489,24 @@ describe('SourceComponent', () => {
expect(COMPONENT_1.parseFromParentXml(COMPONENT_1_XML)).to.deep.equal(COMPONENT_1_XML);
});

it('throw an error when it cant find the parent xml', () => {
try {
expectedChild.parseFromParentXml({
// notice "B" not "b"
CustomLaBels: {
[XML_NS_KEY]: XML_NS_URL,
[type.directoryName]: [CHILD_1_XML, CHILD_2_XML],
},
});
assert.fail('this should throw');
} catch (e) {
assert(e instanceof Error);
expect(e.message).to.equal(
'Invalid XML tags or unable to find matching parent xml file for CustomLabel "Child_1"'
);
}
});

// https://github.com/forcedotcom/salesforcedx-vscode/issues/3210
it('should return empty children for types that do not have uniqueIdElement but xmlPathToChildren returns elements', () => {
const noUniqueIdElementType: MetadataType = JSON.parse(JSON.stringify(MATCHING_RULES_TYPE));
Expand Down
Loading