Skip to content

Commit

Permalink
fix: remove deprecated vars for templates
Browse files Browse the repository at this point in the history
  • Loading branch information
vscaiceanu-1a committed Jan 28, 2025
1 parent 118f782 commit cd2cd05
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,6 @@
"value": {
"type": "string"
},
"vars": {
"deprecated": true,
"description": "Deprecated: will be removed in V12. List of variables that can be used in the localization string",
"type": "array",
"items": {
"type": "string"
}
},
"parameters": {
"type": "object",
"additionalProperties": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,61 +109,20 @@ describe('Rules Engine Effects', () => {
expect(effect).toBeDefined();
});

it('should resolve vars', async () => {
const setPlaceholderEffect$ = effect.setPlaceholderRequestEntityFromUrl$.pipe(shareReplay(1));
const response: PlaceholderRequestReply = {
vars: {
myRelPath: {
type: 'relativeUrl',
value: 'assets-demo-app/img/logo/logo-positive.png'
},
test: {
type: 'localisation',
value: 'localisationKey',
vars: ['parameterForLoc']
},
parameterForLoc: {
type: 'fact',
value: 'parameter'
},
factInTemplate: {
type: 'fact',
value: 'factInTemplate',
path: '$.myKey'
}
},
template: '<img src=\'<%= myRelPath %>\'> <div><%= test %></div><span><%= factInTemplate %></span>'
};
actions.next(setPlaceholderRequestEntityFromUrl({
call: Promise.resolve(response),
id: 'myPlaceholderUrl',
resolvedUrl: 'myPlaceholderResolvedUrl'
}));
factsStream.myFact.next('ignored');
factsStream.parameter.next('success');
factsStream.factInTemplate.next({ myKey: 'Outstanding fact' });

const result = (await firstValueFrom(setPlaceholderEffect$)) as UpdateAsyncStoreItemEntityActionPayloadWithId<PlaceholderRequestModel>
& Action<'[PlaceholderRequest] update entity'>;
expect(result.type).toBe('[PlaceholderRequest] update entity');
expect(result.entity.renderedTemplate).toBe('<img src=\'fakeUrl\'> <div>This is a test with a success</div><span>Outstanding fact</span>');
expect(result.entity.unknownTypeFound).toBeFalsy();
});

it('should resolve vars and parameters', async () => {
it('should resolve parameters', async () => {
const setPlaceholderEffect$ = effect.setPlaceholderRequestEntityFromUrl$.pipe(shareReplay(1));
const response: PlaceholderRequestReply = {
vars: {
test: {
type: 'localisation',
value: 'locForUser',
vars: ['varForLoc'],
parameters: {
userEmail: 'email',
userPhone: 'phone'
userPhone: 'phone',
parameter: 'paramForLoc'
}
},
varForLoc: {
paramForLoc: {
type: 'fact',
value: 'parameter'
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,15 +152,10 @@ export class PlaceholderTemplateResponseEffect {
break;
}
case 'localisation': {
const linkedVars = (vars[varName].vars || []).reduce((acc: { [key: string]: any }, parameter) => {
const paramName = vars[parameter].value;
acc[paramName] = factMap[paramName];
return acc;
}, {});
const linkedParams = (Object.entries(vars[varName].parameters || {})).reduce((acc: { [key: string]: any }, [paramKey, paramValue]) => {
acc[paramKey] = factMapFromVars[paramValue];
return acc;
}, linkedVars);
}, {});
replacements$.push(
this.translationService
? this.translationService.translate(vars[varName].value, linkedParams).pipe(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
export interface PlaceholderVariable {
type: 'fact' | 'fullUrl' | 'relativeUrl' | 'localisation';
value: string;
vars?: string[];
parameters?: Record<string, string>;
path?: string;
}
Expand Down

0 comments on commit cd2cd05

Please sign in to comment.