Skip to content

Commit

Permalink
feat: use data management in object keys (#359)
Browse files Browse the repository at this point in the history
  • Loading branch information
ASaiAnudeep authored May 29, 2024
1 parent 851d1f2 commit 351f8f5
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
1 change: 0 additions & 1 deletion src/exports/stash.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ const stash = {

getDataTemplate(path) {
if (path) {
console.log(dataTemplate)
return jq(path, { data: dataTemplate }).value;
}
return dataTemplate;
Expand Down
9 changes: 8 additions & 1 deletion src/helpers/dataProcessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,14 @@ const dataProcessor = {
}
if (typeof data === 'object') {
for (const prop in data) {
data[prop] = this.processDataRefs(data[prop]);
const updated_prop = this.getDataRefValue(prop);
if (typeof updated_prop === 'string' && updated_prop !== prop) {
data[updated_prop] = data[prop];
delete data[prop];
data[updated_prop] = this.processDataRefs(data[updated_prop]);
} else {
data[prop] = this.processDataRefs(data[prop]);
}
}
}
return data;
Expand Down
22 changes: 21 additions & 1 deletion test/unit/dataProcessor.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ describe('Data Processing - Templates - Direct Overrides', () => {
});
expect(config.data.template.enabled).equals(true);
expect(config.data.template.processed).equals(true);
});
});

});

Expand Down Expand Up @@ -786,6 +786,26 @@ describe('Data Processing - Actual Data - Only Maps', () => {
});
});

it('processData - should replace object key with string', () => {
let data = {
'$M{User.Name}': 'Name'
};
data = dp.processData(data);
expect(data).deep.equals({
'Snow': 'Name'
});
});

it('processData - should not replace object key', () => {
let data = {
'$M{User}': 'Name'
};
data = dp.processData(data);
expect(data).deep.equals({
'$M{User}': 'Name'
});
});

after(() => {
stash.clearDataMaps();
});
Expand Down

0 comments on commit 351f8f5

Please sign in to comment.