Skip to content

feat: add dynamic users - #49

Open
mutambaraf wants to merge 12 commits into
masterfrom
46-add-dynamic-users
Open

mutambaraf wants to merge 12 commits into
masterfrom
46-add-dynamic-users

Conversation

@mutambaraf

@mutambaraf mutambaraf commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Description

Rewrites the mock UOWS client in TypeScript. Users are now held in memory and can be created at runtime, instead of being written by hand as static JSON response files.

Users

  • All fixture users now live in one file, src/data/users.json (11 users). They are loaded into an in-memory UserStore at startup.
  • This replaces the per-endpoint response files under src/responses/ (getbasicpersondetails/, getpersondetailsfromsessionid/, getrolesforuser/, etc.), which have been removed.
  • A User model holds each user's data once and renders it into each endpoint's response shape: basic person details, roles and session.
  • The store looks users up by user number, email, session ID or surname (email and surname are case-insensitive).
  • FAP group memberships are now stateful. Adding or removing a group changes the user in memory.

UOWS endpoints (same paths as before, now backed by the store)

  • GET /users-service/v1/basic-person-details and /basic-person-details/searchable (by userNumbers, emails or surname)
  • GET /users-service/v1/role/{userNumber}
  • GET /users-service/v1/sessions/{sessionId}
  • POST /users-service/v1/token
  • POST and DELETE /users-service/v1/group-memberships/fap

New endpoints for managing the mock

  • POST /mock-server/users with { "userCount": 100, "startUserNumber": 1000 } generates users with Faker. startUserNumber is optional and defaults to the number after the highest existing user. The count is capped by MAX_USERS_PER_REQUEST, which defaults to 1000. If any requested user number is already taken, it returns 409 and creates none of the users.
  • POST /mock-server/reset drops generated users and reseeds from users.json.
  • GET /mock-server/status returns { status, totalUsers }.

Tooling and build

  • TypeScript (npm run build compiles to dist/), with oxlint (type-aware), Prettier, and a Husky + lint-staged pre-commit hook.
  • The Dockerfile is a multi-stage build that compiles the TypeScript, pinned to node:24.22-alpine.

CI and releases

  • New workflows: lint, unit tests, CodeQL, and a PR title checker (Conventional Commits, same config as user-office-core).
  • build-image-test.yml now pushes an image for every PR, tagged with the branch name (e.g. stfc-mockserver-client:46-add-dynamic-users), so a branch can be tested with core before merging. It skips the push for dependabot and fork PRs.
  • build-push.yml now works like core's release workflow. On every merge into master:
    • the version is bumped based on the commit messages (fix gives a patch, feat a minor, ! a major)
    • a tag and GitHub Release with a changelog are created
    • the image is pushed as :vX.Y.Z and :latest
  • Dependabot now also updates GitHub Actions and the Docker base image (minor and patch only). It opens one PR at a time on a fixed weekend schedule, with chore(deps): titles.

Motivation and Context

Adding a user used to mean hand-writing JSON files in three separate folders, which doesn't scale to load testing or to tests that need many users. With one data file, an in-memory store and a generation endpoint, users can be added in one place or created in bulk at runtime. The rewrite also brings the repo in line with user-office-core: TypeScript, linting, tests in CI, and automatic versioned releases.

How Has This Been Tested

-We have added tests, run using npm test

Fixes

Closes #46

Changes

  • Breaking: the mock is now TypeScript (src/index.ts → dist/index.js). src/mockserver.js and src/responses/ have been removed.
  • Breaking: release images are tagged :vX.Y.Z and :latest. :master is no longer published.
  • New: in-memory user store, src/data/users.json, and the /mock-server/users, /mock-server/reset and /mock-server/status endpoints.
  • New: unit tests, lint/test/CodeQL/PR-title workflows, branch images for PRs, automated releases.
  • Updated: Dockerfile, dependabot config, README.

Depends on

Nothing needs to be merged first, but before or when merging:

  • user-office-core: apps/backend/docker-compose-stfc.e2e.yml pulls stfc-mockserver-client:master. Once this PR is merged, that tag stops being updated, so core needs to switch to :latest (planned as a follow-up).
  • Repo settings: enable squash merging, so PR titles become the commit messages that drive version bumps.
  • Starting version: tag the current master as v1.0.0 so this PR (feat!) releases as v2.0.0.

Tests included/Docs Updated?

  • I have added tests to cover my changes.
  • All relevant doc has been updated

@github-advanced-security

Copy link
Copy Markdown

You are seeing this message because GitHub Code Scanning has recently been set up for this repository, or this pull request contains the workflow file for the Code Scanning tool.

What Enabling Code Scanning Means:

  • The 'Security' tab will display more code scanning analysis results (e.g., for the default branch).
  • Depending on your configuration and choice of analysis tool, future pull requests will be annotated with code scanning analysis results.
  • You will be able to see the analysis results for the pull request's branch on this overview once the scans have completed and the checks have passed.

For more information about GitHub Code Scanning, check out the documentation.

@mutambaraf mutambaraf added review: please A request for an ad-hoc review. AI Generated labels Oct 23, 2026
@mutambaraf
mutambaraf marked this pull request as ready for review October 23, 2026 10:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI Generated review: please A request for an ad-hoc review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Redesign for dynamic users

2 participants