Skip to content
Closed
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
34 changes: 31 additions & 3 deletions packages/vlocity-deploy/src/__tests__/datapackExporter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ describe('DatapackExporter', () => {
describeSObjectField: jest.fn(async (type: string, fieldName: string) =>
findDescribeField(describeFor(type), fieldName))
},
replaceNamespace: jest.fn((value: string) => value)
replaceNamespace: jest.fn((value: string) => value),
updateNamespace: jest.fn((value: string) => value)
};
const matchingKeys = {
getMatchingKey: jest.fn(async (type: string) => ({
Expand Down Expand Up @@ -253,6 +254,31 @@ describe('DatapackExporter', () => {
);
});

it('resolves namespace placeholders in filter keys and values', () => {
const { exporter, salesforce } = createExporter();
// Simulate a namespace service that resolves %vlocity_namespace% to the actual namespace
salesforce.updateNamespace.mockImplementation((value: string) =>
value.replace(/%vlocity_namespace%/g, 'vlocity_cmt')
);

const datapack = {
id: 'a0M000000000001AAA',
objectType: 'vlocity_cmt__OmniScript__c',
normalizedObjectType: 'OmniScript__c',
data: {
Id: 'a0M000000000001AAA'
}
};

const filter = exporter.buildLookupFilter({
'%vlocity_namespace%__OmniScriptId__c': '{%vlocity_namespace%__OmniScript__c:Id}'
}, datapack);

expect(filter).toStrictEqual({
'vlocity_cmt__OmniScriptId__c': 'a0M000000000001AAA'
});
});

it('awaits lookup references included in matching key objects', async () => {
const describe = {
name: 'Child__c',
Expand Down Expand Up @@ -1158,7 +1184,8 @@ describe('DatapackExporter', () => {
describeSObjectField: jest.fn(async (type: string, fieldName: string) =>
findDescribeField(type === rootDescribe.name ? rootDescribe : relatedDescribe, fieldName))
},
replaceNamespace: jest.fn((value: string) => value)
replaceNamespace: jest.fn((value: string) => value),
updateNamespace: jest.fn((value: string) => value)
};
const matchingKeys = mockMatchingKeyService();
const expandedResults: any[] = [];
Expand Down Expand Up @@ -1282,7 +1309,8 @@ describe('DatapackExporter', () => {
describeSObjectField: jest.fn(async (_type: string, fieldName: string) =>
findDescribeField(childDescribe, fieldName))
},
replaceNamespace: jest.fn((value: string) => value)
replaceNamespace: jest.fn((value: string) => value),
updateNamespace: jest.fn((value: string) => value)
};
const matchingKeys = mockMatchingKeyService();

Expand Down
7 changes: 6 additions & 1 deletion packages/vlocity-deploy/src/export/datapackExporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1009,7 +1009,7 @@ export class DatapackExporter {
// Object exp with field conditions
if (typeof filter === 'object' && filter) {
const entries = Object.entries(filter).map(([key, value]) => [
key,
this.salesforce.updateNamespace(key),
this.evalFilterValue(value, datapack)
]);
return entries.some(([, value]) => value === undefined)
Expand Down Expand Up @@ -1038,6 +1038,11 @@ export class DatapackExporter {
}

private evalFilterValueExp(stringFormat: string, datapack: ExportDatapack) {
// Resolve namespace placeholders (e.g. %vlocity_namespace%) so that the
// resulting lookup path can be matched against the context keys which use
// the real Salesforce namespace.
stringFormat = this.salesforce.updateNamespace(stringFormat);

const context = {
Id: datapack.id,
[datapack.objectType]: datapack.data,
Expand Down