Skip to content

Conversation

@jdschleicher
Copy link
Owner

@jdschleicher jdschleicher commented Nov 17, 2025

Motivation and Context

This change enhances the handling of text, numeric, and currency fields in recipe generation by adding proper support for length, precision, and scale, correcting calculation bugs, and improving YAML formatting. These improvements ensure limits provided to faker functions are based on the xml of the associated field and field type

Any Technical Decisions to Note??

  • n/a

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Other (please describe):

How Has This Been Tested?

  • Tested on Windows
  • Tested on macOS
  • Tested on Linux
  • Added new unit tests
  • Updated existing tests

Test Details

  • New unit tests added for precision and scale calculations
  • Existing numeric field tests updated to verify overflow prevention
  • All tests pass locally, including edge cases for large precision values

Checklist

  • Pull Request title captures expected version update
  • package.json version number updated
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Reviewers

@mention-team-members-or-specific-reviewers

…nstraints

- Added buildTextRecipeValueWithLength(length: number) and buildNumericRecipeValueWithPrecision(precision: number) to IRecipeFakerService interface
- Implemented methods in FakerJSRecipeFakerService and SnowfakeryRecipeFakerService to generate faker data respecting length/precision limits
- Updated RecipeService to utilize new methods for improved fake data generation in text and numeric fields
- Renamed `buildNumericRecipeValueWithPrecision` to `buildNumericRecipeValueWithPrecisionAndScale` in IRecipeFakerService and implementations
- Added optional `scale` parameter to handle decimal fields (currency, percent) with appropriate precision and decimal places
- Updated FakerJS and Snowfakery services to generate integers for scale=0 and decimals for scale>0
- Modified RecipeService to pass scale for percent fields, ensuring accurate fake data generation for numeric types
…erflow

Updated FakerJSRecipeFakerService and SnowfakeryRecipeFakerService to limit precision to 15 digits for integer and decimal fields, preventing loss of accuracy in large numbers. Adjusted test expectations in FakerJSRecipeService.test.ts to reflect the new max value (10^15 - 1) for integer fields.
… method

- Refactored buildNumericRecipeValueWithPrecisionAndScale in FakerJS and Snowfakery services to remove redundant calculations and improve readability.
- Added buildCurrencyRecipeValueWithPrecisionAndScale method to handle currency fields separately, ensuring full precision usage.
- Updated IRecipeFakerService interface to include the new currency method.
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.
Refactor the buildNumericRecipeValueWithPrecisionAndScale and buildCurrencyRecipeValueWithPrecisionAndScale methods to use precision minus scale as the digit count left of the decimal for max value generation, fixing inaccurate faker outputs for decimal fields. Updated corresponding test expectations.
…and currency fields based on precision - scale

- Updated buildNumericRecipeValueWithPrecisionAndScale and buildCurrencyRecipeValueWithPrecisionAndScale to use left_digits = precision - effectiveScale, ensuring accurate representation of digits before the decimal point.
- Adjusted the corresponding test to expect left_digits=16 for a currency field with 18 precision and 2 scale, matching the correct calculation. This fixes a potential issue where total precision was mistakenly used as left_digits, leading to incorrect fake data generation.
…peFakerService

Removed inline comments from buildNumericRecipeValueWithPrecisionAndScale and
buildCurrencyRecipeValueWithPrecisionAndScale methods, and added missing closing
braces to fix syntax errors.
- Add support for scale in numeric value generation for accurate currency and number fields
- Format faker expressions as YAML block scalars and add constraints for text/numeric values
- Fix max value calculations, precision-based left digits, JS overflow, and code cleanup
- Bump version to 2.7.0
…and fixes

Remove entries for numeric scale support, YAML formatting, value constraints, and bug fixes in numeric handling to reflect accurate pre-release state, preventing confusion in release notes.
@jdschleicher jdschleicher marked this pull request as ready for review November 24, 2025 10:26
@jdschleicher jdschleicher merged commit d2d4193 into main Nov 24, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant