Skip to content

Commit 15d021e

Browse files
committed
feat: format faker expressions as YAML block scalars in recipes
Update buildPercentRecipeValueWithPrecisionAndScale and buildCurrencyRecipeValueWithPrecisionAndScale to prepend `|` and add indentation to the returned strings, ensuring they are valid YAML literal block scalars. Adjust corresponding test expectations to match the new formatting for accurate assertion in FakerJS recipe service tests. This improves YAML recipe generation by preserving multi-line structure in generated fake values.
1 parent 990d2e1 commit 15d021e

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

src/treecipe/src/RecipeFakerService.ts/FakerJSRecipeFakerService/FakerJSRecipeFakerService.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -518,19 +518,23 @@ ${this.generateTabs(5)}${randomChoicesBreakdown}`;
518518
const maxValueByPrecision = '9'.repeat(precision);
519519

520520
if (effectiveScale === 0) {
521-
return `${this.openingRecipeSyntax} faker.number.int({min: 0, max: ${maxValueByPrecision}}) ${this.closingRecipeSyntax}`;
521+
return `|
522+
${this.openingRecipeSyntax} faker.number.int({min: 0, max: ${maxValueByPrecision}}) ${this.closingRecipeSyntax}`;
522523
} else {
523-
return `${this.openingRecipeSyntax} faker.finance.amount({min: 0, max: ${maxValueByPrecision}, dec: ${effectiveScale}}) ${this.closingRecipeSyntax}`;
524+
return `|
525+
${this.openingRecipeSyntax} faker.finance.amount({min: 0, max: ${maxValueByPrecision}, dec: ${effectiveScale}}) ${this.closingRecipeSyntax}`;
524526
}
525527

526-
}
528+
}
527529

528530
buildCurrencyRecipeValueWithPrecisionAndScale(precision: number, scale?: number): string {
529531
// Special handling for currency fields - use full precision as left_digits
532+
530533
const effectiveScale = scale ?? 0;
531534
const maxValueByPrecision = '9'.repeat(precision);
532535

533-
return `${this.openingRecipeSyntax} faker.finance.amount({min: 0, max: ${maxValueByPrecision}, dec: ${effectiveScale}}) ${this.closingRecipeSyntax}`;
536+
return `|
537+
${this.openingRecipeSyntax} faker.finance.amount({min: 0, max: ${maxValueByPrecision}, dec: ${effectiveScale}}) ${this.closingRecipeSyntax}`;
534538

535539
}
536540

src/treecipe/src/RecipeService/tests/FakerJSRecipeService.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,8 @@ describe('FakerJSRecipeService IRecipeService Implementation Shared Intstance Te
191191
test('given expected number XMLFieldDetail, returns the expected fakerJS YAML recipe value', () => {
192192

193193
const expectedXMLDetailForNumber:XMLFieldDetail = XMLMarkupMockService.getNumberXMLFieldDetail();
194-
const expectedFakerJSExpressionForNumber = `\${{ faker.number.int({min: 0, max: 999999999999999999}) }}`;
194+
const expectedFakerJSExpressionForNumber = `|
195+
\${{ faker.number.int({min: 0, max: 999999999999999999}) }}`;
195196
const recordTypeNameByRecordTypeNameToXMLMarkup = {};
196197

197198
const actualFakerJSForNumber = recipeServiceWithFakerJS.getRecipeFakeValueByXMLFieldDetail(expectedXMLDetailForNumber, recordTypeNameByRecordTypeNameToXMLMarkup);
@@ -202,7 +203,8 @@ describe('FakerJSRecipeService IRecipeService Implementation Shared Intstance Te
202203
test('given expected currency XMLFieldDetail, returns the expected fakerJS YAML recipe value', () => {
203204

204205
const expectedXMLDetailForCurrency:XMLFieldDetail = XMLMarkupMockService.getCurrencyFieldDetail();
205-
const expectedFakerJSExpressionForCurrency = "\${{ faker.finance.amount({min: 0, max: 999999999999999999, dec: 2}) }}";
206+
const expectedFakerJSExpressionForCurrency = `|
207+
\${{ faker.finance.amount({min: 0, max: 999999999999999999, dec: 2}) }}`;
206208
const recordTypeNameByRecordTypeNameToXMLMarkup = {};
207209
const actualFakerJSForCurrency = recipeServiceWithFakerJS.getRecipeFakeValueByXMLFieldDetail(expectedXMLDetailForCurrency, recordTypeNameByRecordTypeNameToXMLMarkup);
208210

0 commit comments

Comments
 (0)