Skip to content

fix(pci-project): map voucher eligibility errors to existing translation keys - #23361

Closed
AdrienPensart wants to merge 1 commit into
ovh:masterfrom
AdrienPensart:fix/PCINT-9351-fix-pci-project-voucher-error-key
Closed

AdrienPensart wants to merge 1 commit into
ovh:masterfrom
AdrienPensart:fix/PCINT-9351-fix-pci-project-voucher-error-key

Conversation

@AdrienPensart

Copy link
Copy Markdown

Fix in useVoucher.tsx:92: the regex changed from /(VOUCHER_\w+)/i to /VOUCHER_(\w+)/i, so the VOUCHER_ prefix is no longer part of the captured code. VOUCHER_EXPIRED now gives pci_projects_new_voucher_form_field_error_voucher_expired, which exists in the translation file.

Tests in UseVoucher.spec.tsx: I replaced the two old error tests with one it.each. Each case goes through checkEligibility and checks the exact key:

VOUCHER_INVALID gives ..._voucher_invalid
VOUCHER_EXPIRED gives ..._voucher_expired
VOUCHER_ALREADY_USED_2 gives ..._voucher_already_used_2
Voucher rejected: VOUCHER_COUNTRY gives ..._voucher_country
Internal error falls back to ..._voucher_invalid
The old "specific codes" test called setError with the hand-built key instead of going through the hook, so it could never catch this bug.

An API code that isn't in the translation file, for example VOUCHER_FOO, still shows the raw key. The file has a pci_projects_new_voucher_form_field_error_default key that could cover that case. I left it alone to keep the fix small.

Description

Ticket Reference: #...

Additional Information

…ion keys

Signed-off-by: Adrien Pensart <adrien.pensart@corp.ovh.com>

Copilot AI left a comment

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.

Note

Copilot was unable to run its full agentic suite in this review.

Copilot review overview

No open issues 🎉

What changed in this PR

Updates voucher eligibility error parsing to produce correct i18n translation keys, and strengthens test coverage around error-to-translation mapping.

Changes:

  • Adjusted the error-code regex to avoid including the VOUCHER_ prefix in the extracted code portion.
  • Reworked voucher eligibility error tests into a parameterized table covering multiple message formats and fallbacks.
File Description
packages/​manager/​apps/​pci-project/​src/​pages/​creation/​hooks/​useVoucher.tsx Fixes voucher error-code extraction so translation keys don’t contain a duplicated voucher_ segment.
packages/​manager/​apps/​pci-project/​src/​pages/​creation/​hooks/​__tests__/​UseVoucher.spec.tsx Adds broader, table-driven coverage for mapping eligibility error messages to translation keys.

Review effort: Lite

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.

2 participants