Skip to content

Add unit tests for the user preferences validation and supported currency/language/timezone constants #580

Description

@Baskarayelu

📋 Description

The preferences write path validates input with utils/validation/preferences-validation.ts (validateCurrency, validateLanguage, validateNotificationsEnabled, validateTimezone, validatePreferencesUpdate) against the allow-lists in utils/constants/supported-values.ts (SUPPORTED_CURRENCIES, SUPPORTED_LANGUAGES, COMMON_TIMEZONES, DEFAULT_PREFERENCES). This is used by app/api/user/preferences/route.ts (PATCH). There is no test file for either.

Why this matters: preferences validation is the guard that keeps an unsupported currency or bogus locale out of the database and out of the currency formatter / i18n layer. A gap here surfaces later as broken formatting or a missing translation. Validation against a fixed allow-list is trivially testable and worth locking down.

🎯 Requirements & Context

Functional requirements

  • Add tests/unit/preferences-validation.test.ts (Vitest).
  • Assert each validator accepts every value in its allow-list and rejects out-of-list / wrong-type values (throwing the module's ValidationError).
  • Assert validatePreferencesUpdate accepts a partial update, ignores undefined fields, and rejects when any provided field is invalid.
  • Assert DEFAULT_PREFERENCES is internally consistent (its currency/language are members of the supported lists).
  • Assert notifications_enabled rejects non-boolean inputs.

Context & constraints

  • Vitest 4.0.18; pure-function tests, no I/O.
  • Test-only unless a real validation gap is found (document it in the PR).

🛠️ Suggested Execution

1. Fork & branch

git checkout -b test/preferences-validation

2. Implement changes

  • Add table-driven tests iterating the allow-lists; add a consistency check for defaults.

3. Test & commit

npm run test:coverage
npx tsc --noEmit
  • Cover edge cases: empty string, wrong case (e.g. "usd" vs "USD"), null, numeric language, unknown timezone.

Example commit message

test(preferences): add coverage for preferences validation + supported values

Proves allow-list acceptance/rejection and DEFAULT_PREFERENCES consistency.

✅ Acceptance Criteria & Guidelines

Requirement Target
All validators covered Required
Defaults-consistency assertion Required
Coverage of preferences validation ≥ 95% lines
npx tsc --noEmit, npm run lint clean Required
Timeframe 96 hours from assignment

💬 Community & Support

Join the RemitWise contributor community on Discord: https://discord.gg/CtQuPZFMA

Please comment when you pick this up so we can avoid duplicate work. 🚀

Metadata

Metadata

Assignees

Type

Fields

No fields configured for Task.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions