Skip to content

Commit 53d1c83

Browse files
committed
Merge branch 'main' into chore/SOF-6463
2 parents 5ba232e + a48d84f commit 53d1c83

File tree

4 files changed

+30
-21
lines changed

4 files changed

+30
-21
lines changed

src/utils/index.js

+5-8
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,17 @@ import { getSchemaWithDependencies } from "./schemas";
3030
import { getSearchQuerySelector } from "./selector";
3131
import {
3232
convertArabicToRoman,
33-
generateName,
3433
randomAlphanumeric,
3534
removeCommentsFromSourceCode,
3635
removeEmptyLinesFromString,
3736
removeNewLinesAndExtraSpaces,
37+
renderTextWithSubstitutes,
3838
toFixedLocale,
3939
} from "./str";
4040
import { mapTree } from "./tree";
4141
import { containsEncodedComponents } from "./url";
4242
import { getUUID } from "./uuid";
43-
import { allYAMLSchemas, combineType, esseType, includeType, parameterType } from "./yaml";
43+
import { JsYamlAllSchemas, JsYamlTypes } from "./yaml";
4444

4545
export {
4646
compareEntitiesInOrderedSetForSorting,
@@ -81,12 +81,9 @@ export {
8181
mapTree,
8282
getSchemaWithDependencies,
8383
mergeTerminalNodes,
84-
combineType,
85-
parameterType,
86-
allYAMLSchemas,
87-
esseType,
88-
includeType,
89-
generateName,
84+
JsYamlTypes,
85+
JsYamlAllSchemas,
86+
renderTextWithSubstitutes,
9087
filterEntityList,
9188
getFilesInDirectory,
9289
getDirectories,

src/utils/str.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ export function convertArabicToRoman(num) {
105105
* {user001: "John Doe"}
106106
* ); // "Hello John Doe!"
107107
*/
108-
export function generateName(template, data, substitutionMap = {}) {
108+
export function renderTextWithSubstitutes(template, data, substitutionMap = {}) {
109109
if (!template) return "";
110110
// Create a copy of data to avoid modifying the original
111111
const renderData = lodash.cloneDeep(data);

src/utils/yaml.js

+16-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import path from "path";
55

66
import { JSONSchemasInterface } from "../JSONSchemasInterface";
77
import { safeMakeArray } from "./array";
8-
import { generateName } from "./str";
8+
import { renderTextWithSubstitutes } from "./str";
99

1010
/**
1111
* Generate objects with combinations of parameters.
@@ -75,7 +75,7 @@ function readFromYaml(ref) {
7575
const { filePath, objPath } = splitReference(ref);
7676
const fileContent = fs.readFileSync(path.resolve(filePath), "utf8");
7777
// eslint-disable-next-line no-use-before-define
78-
const parsedContent = yaml.load(fileContent, { schema: allYAMLSchemas });
78+
const parsedContent = yaml.load(fileContent, { schema: JsYamlAllSchemas });
7979

8080
return objPath ? lodash.get(parsedContent, objPath) : parsedContent;
8181
}
@@ -133,7 +133,12 @@ export const combineType = new yaml.Type("!combine", {
133133

134134
const configs = combinations.map((c) => lodash.merge(c, config));
135135
configs.forEach(
136-
(c) => (c.name = generateName(name?.template || name, c, name?.substitutions)),
136+
(c) =>
137+
(c.name = renderTextWithSubstitutes(
138+
name?.template || name,
139+
c,
140+
name?.substitutions,
141+
)),
137142
);
138143
return extraConfigs.length ? configs.concat(extraConfigs.flat()) : configs;
139144
},
@@ -177,7 +182,14 @@ export const includeType = new yaml.Type("!include", {
177182
},
178183
});
179184

180-
export const allYAMLSchemas = yaml.DEFAULT_SCHEMA.extend([
185+
export const JsYamlTypes = {
186+
include: includeType,
187+
parameter: parameterType,
188+
combine: combineType,
189+
esse: esseType,
190+
};
191+
192+
export const JsYamlAllSchemas = yaml.DEFAULT_SCHEMA.extend([
181193
parameterType,
182194
combineType,
183195
esseType,

tests/utils/str.tests.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { expect } from "chai";
22

3-
import { generateName } from "../../src/utils";
3+
import { renderTextWithSubstitutes } from "../../src/utils";
44

5-
describe("generateName", () => {
5+
describe("renderTextWithSubstitutes", () => {
66
it("should substitute flat properties", () => {
77
const template = "Hello {{ user }}!";
88
const data = { user: "user001" };
99
const substitutionMap = { user001: "John Doe" };
1010

11-
const result = generateName(template, data, substitutionMap);
11+
const result = renderTextWithSubstitutes(template, data, substitutionMap);
1212

1313
expect(result).to.be.equal("Hello John Doe!");
1414
});
@@ -18,7 +18,7 @@ describe("generateName", () => {
1818
const data = { parameters: { user: "user001" } };
1919
const substitutionMap = { user001: "John Doe" };
2020

21-
const result = generateName(template, data, substitutionMap);
21+
const result = renderTextWithSubstitutes(template, data, substitutionMap);
2222

2323
expect(result).to.be.equal("Hello John Doe!");
2424
});
@@ -28,7 +28,7 @@ describe("generateName", () => {
2828
const data = { user: "user001" };
2929
const substitutionMap = {};
3030

31-
const result = generateName(template, data, substitutionMap);
31+
const result = renderTextWithSubstitutes(template, data, substitutionMap);
3232

3333
expect(result).to.be.equal("Hello user001!");
3434
});
@@ -38,7 +38,7 @@ describe("generateName", () => {
3838
const data = { user: "user001" };
3939
const substitutionMap = {};
4040

41-
const result = generateName(template, data, substitutionMap);
41+
const result = renderTextWithSubstitutes(template, data, substitutionMap);
4242

4343
expect(result).to.be.equal("Hello world!");
4444
});
@@ -48,7 +48,7 @@ describe("generateName", () => {
4848
const data = { user: "user001" };
4949
const substitutionMap = {};
5050

51-
const result = generateName(template, data, substitutionMap);
51+
const result = renderTextWithSubstitutes(template, data, substitutionMap);
5252

5353
expect(result).to.be.equal("");
5454
});
@@ -58,7 +58,7 @@ describe("generateName", () => {
5858
const data = { user: null };
5959
const substitutionMap = {};
6060

61-
const result = generateName(template, data, substitutionMap);
61+
const result = renderTextWithSubstitutes(template, data, substitutionMap);
6262

6363
expect(result).to.be.equal("Hello !");
6464
});

0 commit comments

Comments
 (0)