Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/bruno-common/src/utils/faker-functions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ describe('mockDataFunctions Regex Validation', () => {
randomStreetAddress: /^[\s\S]+$/,
randomCountry: /^[\s\S]+$/,
randomCountryCode: /^[\s\S]+$/,
randomZipCode: /^[0-9]{5}$/,
randomLatitude: /^[\s\S]+$/,
randomLongitude: /^[\s\S]+$/,
randomAvatarImage: /^[\s\S]+$/,
Expand Down
1 change: 1 addition & 0 deletions packages/bruno-common/src/utils/faker-functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export const mockDataFunctions = {
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.

randomLatitude: () => faker.location.latitude(),
randomLongitude: () => faker.location.longitude(),
randomAvatarImage: () => faker.image.avatar(),
Expand Down
Loading