Skip to content

Strengthen UserRole contract tests beyond length/regex invariants #223

Description

@marassteiner

Context

Follow-up from review of #205 (feat(core): add the non-custodial wallet partner user role).

Finding

packages/core/src/__tests__/user-role.test.ts pins three invariants over Object.values(UserRole):

  1. no duplicate values (user-role.test.ts:6-15)
  2. anchored PascalCase /^[A-Z][A-Za-z]*$/ (user-role.test.ts:18-24)
  3. fixed member count 13 (user-role.test.ts:26-28)

These do not pin the exact contract string for the new member in packages/core/src/definitions/jwt.ts:16:

NON_CUSTODIAL_WALLET_PARTNER = 'NonCustodialWalletPartner',

A typo such as 'NonCustodialWalletPartnr' would still satisfy uniqueness, regex, and length. The PR body intentionally rejected a tautological one-liner and preferred invariants — that is a valid design choice, not a merge-blocker for #205.

Separately, a fixed toHaveLength(13) fails on any parallel role addition (e.g. historical PARTNER work on other branches) and forces mechanical updates that do not improve contract safety on their own.

Evidence

Suggested fix

Either:

  • add an explicit pin for the new member:
    expect(UserRole.NON_CUSTODIAL_WALLET_PARTNER).toBe('NonCustodialWalletPartner')
    (and keep or drop the length check), or
  • pin the full expected value list and update that list deliberately when roles change.

Not a merge-blocker for #205: production behaviour of the additive enum member is correct; this is test strength only.

Related

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions