Skip to content

feat: Add randomZipCode support.#7701

Open
W-Floyd wants to merge 1 commit intousebruno:mainfrom
W-Floyd:feat/randomZipCode
Open

feat: Add randomZipCode support.#7701
W-Floyd wants to merge 1 commit intousebruno:mainfrom
W-Floyd:feat/randomZipCode

Conversation

@W-Floyd
Copy link
Copy Markdown
Contributor

@W-Floyd W-Floyd commented Apr 7, 2026

Resolves #7693

Description

Adds a randomZipCode function that uses faker.location.zipCode()

Contribution Checklist:

  • I've used AI significantly to create this pull request
  • The pull request only addresses one issue or adds one feature.
  • The pull request does not introduce any breaking changes
  • I have added screenshots or gifs to help explain the change if applicable.
  • I have read the contribution guidelines.
  • Create an issue and link to the pull request.

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

    • Added capability to generate random zip codes formatted as 5-digit numeric values.
  • Tests

    • Added validation tests for the new zip code generation functionality.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 7, 2026

Walkthrough

This PR adds support for generating random zip codes using Faker.js's location.zipCode() method, enabling the {{$randomZipCode}} variable in Bruno templates alongside test validation for the 5-digit numeric pattern.

Changes

Cohort / File(s) Summary
Random Zip Code Support
packages/bruno-common/src/utils/faker-functions.ts, packages/bruno-common/src/utils/faker-functions.spec.ts
Added randomZipCode function leveraging faker.location.zipCode() and corresponding regex validation test for 5-digit numeric pattern /^[0-9]{5}$/.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Suggested reviewers

  • lohit-bruno
  • naman-bruno
  • bijin-bruno
  • helloanoop

Poem

Five digits twirl in faker's hands,
Zip codes bloom across the lands,
Templates breathe with Bruno's grace,
Random addresses find their place! 🎉✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding a randomZipCode function to support zip code generation.
Linked Issues check ✅ Passed The implementation fully satisfies issue #7693 by adding randomZipCode to faker-functions.ts using faker.location.zipCode() and including corresponding test coverage.
Out of Scope Changes check ✅ Passed All changes are scoped to the randomZipCode feature: updates to faker-functions.ts and its test file with no extraneous modifications.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between d4cd34f and d954d2d.

📒 Files selected for processing (2)
  • packages/bruno-common/src/utils/faker-functions.spec.ts
  • packages/bruno-common/src/utils/faker-functions.ts

randomStreetAddress: () => faker.location.streetAddress(),
randomCountry: () => faker.location.country(),
randomCountryCode: () => faker.location.countryCode(),
randomZipCode: () => faker.location.zipCode(),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 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’s faker.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 digits 0–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 -20

Repository: usebruno/bruno

Length of output: 1230


🏁 Script executed:

# Search for ZIP-5 pattern expectation
rg '/\^?\[0-9\]\{5\}\$?\|#####' --type ts --type json

Repository: 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 -50

Repository: usebruno/bruno

Length of output: 2610


🏁 Script executed:

cat packages/bruno-common/src/utils/faker-functions.spec.ts | head -80

Repository: 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.ts

Repository: 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.

Suggested change
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support random zip codes

1 participant