Conversation
WalkthroughThis PR adds support for generating random zip codes using Faker.js's Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/bruno-common/src/utils/faker-functions.ts`:
- Line 42: randomZipCode currently calls faker.location.zipCode() without
enforcing a 5-digit US format causing locale-dependent output; update the
randomZipCode implementation to return exactly five digits by calling
faker.location.zipCode with an explicit 5-digit format (e.g. '#####') or
otherwise generate a 5-digit string (e.g. faker.string.numeric(5)), so the
randomZipCode function always matches /^[0-9]{5}$/ as expected by the tests.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 41fd6401-0221-46b9-9c21-651f102f3671
📒 Files selected for processing (2)
packages/bruno-common/src/utils/faker-functions.spec.tspackages/bruno-common/src/utils/faker-functions.ts
| randomStreetAddress: () => faker.location.streetAddress(), | ||
| randomCountry: () => faker.location.country(), | ||
| randomCountryCode: () => faker.location.countryCode(), | ||
| randomZipCode: () => faker.location.zipCode(), |
There was a problem hiding this comment.
🧩 Analysis chain
🌐 Web query:
In @faker-js/faker v9.7.0, is faker.location.zipCode() locale-dependent by default, and is faker.location.zipCode('#####') the supported way to force a 5-digit numeric ZIP code?
💡 Result:
Yes.
faker.location.zipCode()is locale-dependent by default: if you don’t pass a format, it uses the current locale’sfaker.definitions.location.postcode(i.e., the locale’s ZIP/postcode pattern). [1] (Locale selection/fallback behavior is part of Faker’s localization system.) [3]faker.location.zipCode('#####')is a supported way to force 5 digits:zipCode()accepts a string format (or{ format }), and#placeholders are replaced with digits0–9, so'#####'yields a 5-digit numeric code. [1][2]
Sources: [1] [2] [3]
🏁 Script executed:
# Find the test file that references randomZipCode and the ZIP-5 pattern
find . -type f \( -name "*.test.ts" -o -name "*.spec.ts" \) | head -20Repository: usebruno/bruno
Length of output: 1230
🏁 Script executed:
# Search for ZIP-5 pattern expectation
rg '/\^?\[0-9\]\{5\}\$?\|#####' --type ts --type jsonRepository: usebruno/bruno
Length of output: 40
🏁 Script executed:
# Verify the faker-functions.ts file content around line 42
cat packages/bruno-common/src/utils/faker-functions.ts | head -50Repository: usebruno/bruno
Length of output: 2610
🏁 Script executed:
cat packages/bruno-common/src/utils/faker-functions.spec.ts | head -80Repository: usebruno/bruno
Length of output: 3156
🏁 Script executed:
# Search specifically for randomZipCode test
rg -A 5 -B 5 'randomZipCode' packages/bruno-common/src/utils/faker-functions.spec.tsRepository: usebruno/bruno
Length of output: 456
Enforce ZIP-5 format constraint in randomZipCode
Line 42 uses faker.location.zipCode() without a format argument, which makes output locale-dependent. The test at line 57 of faker-functions.spec.ts expects exactly 5 digits (/^[0-9]{5}$/), so this will fail or be flaky on non-US locales.
Fix
- randomZipCode: () => faker.location.zipCode(),
+ randomZipCode: () => faker.location.zipCode('#####'),📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| randomZipCode: () => faker.location.zipCode(), | |
| randomZipCode: () => faker.location.zipCode('#####'), |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@packages/bruno-common/src/utils/faker-functions.ts` at line 42, randomZipCode
currently calls faker.location.zipCode() without enforcing a 5-digit US format
causing locale-dependent output; update the randomZipCode implementation to
return exactly five digits by calling faker.location.zipCode with an explicit
5-digit format (e.g. '#####') or otherwise generate a 5-digit string (e.g.
faker.string.numeric(5)), so the randomZipCode function always matches
/^[0-9]{5}$/ as expected by the tests.
Resolves #7693
Description
Adds a
randomZipCodefunction that usesfaker.location.zipCode()Contribution Checklist:
Note: Keeping the PR small and focused helps make it easier to review and merge. If you have multiple changes you want to make, please consider submitting them as separate pull requests.
Publishing to New Package Managers
Please see here for more information.
Summary by CodeRabbit
New Features
Tests