Skip to content

[registration] add member repository unit tests #74

Description

@WilliamTayNZ

Description

createMembershipRegistration (in the member repository) converts a validated MemberRegistration into a Prisma .create() call against the Member table, handling per-path field mapping (returning member, current UoA student, non-UoA student) and translating a P2002 unique-constraint violation into a distinct duplicate error, versus a generic database error for anything else. It currently has no test coverage.

Requirements

  • Mock getPrisma() entirely - no real database connection should be required to run this suite
  • Cover the successful-creation path
  • Cover field mapping for all three MemberRegistration variants: what gets included/omitted per branch (e.g. a returning member should not receive programme/primaryAffiliation; a current UoA student should receive faculty/programme/yearLevel; a non-UoA student should receive an empty faculty array and primaryAffiliation)
  • Cover optional field pass-through (discordUsername)
  • Cover error translation: a Prisma error with code P2002{ type: "duplicate" }; any other Prisma error code → { type: "database" }; a non-Prisma error → also { type: "database" }

Acceptance Criteria

  • memberRepository.test.ts exists, with getPrisma mocked, no live database required to run
  • All three registration variants have a dedicated field-mapping test
  • All three error scenarios (duplicate, other Prisma error, non-Prisma error) are covered
  • Test file includes comments explaining the mocking pattern (vi.mock, spy call inspection via .mock.calls) for anyone unfamiliar with it

Notes

This is a self-contained unit test task with no dependency on the faculty/major redesign - the repository's field-mapping logic for faculty/programme will need a small update once that redesign lands, but the mocking setup and most of the file structure won't change.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions