Add a contract test: public endpoints never return private fields

Open Beginner friendly
#132 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
Half a day
Newbie friendliness
72/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Active
Domain
backend, testing

Research direction

Read apps/api/src/tests/security.test.ts first to copy the existing mocking style, then apps/api/src/tests/helpers.ts for user/post creation, and apps/api/src/utils/serializers.ts to learn which keys each response can emit. Add the expectNoKeys recursive walker plus a new test covering profile, search, feed, post and comments, written so it fails if any listed key appears in the raw JSON body. Done means the suite runs without a real database and npm test, npm run typecheck and npm run lint all pass.

Written by the indexing model from the issue text.

Description

api good first issue tests

Difficulty: Beginner to Intermediate · Estimated size: half a day

Context

Several responses are built by serializer functions. A future change could accidentally add a private field such as an email address, a password hash or a token.

Problem or goal

Add tests that scan real API responses for fields that must never appear.

Suggested approach

  • In apps/api/src/tests, create users and a post using the existing helpers, call the profile, search, feed and post endpoints, and assert that the JSON text never contains the keys passwordHash, password, email (for other users), refreshToken, tokenHash, or googleId.
  • Write a small helper expectNoKeys(body, keys) that walks the JSON recursively.

Where to look

  • apps/api/src/tests/helpers.ts
  • apps/api/src/tests/security.test.ts
  • apps/api/src/utils/serializers.ts

Acceptance criteria

  • The test fails if one of those keys is added to any checked response.
  • It covers at least profile, search, feed, post and comments.
  • It is fast and does not need a real database (follow the existing mocking style).

How to work on it

  1. Comment here to claim it, so two people do not do the same work.
  2. Fork the repo and branch from main (feat/short-name or fix/short-name). Setup steps are in docs/DEVELOPMENT.md.
  3. Keep the change focused and add tests for backend logic.
  4. Run npm run typecheck, npm test and npm run lint and npm run format before opening the pull request.
  5. Use a Conventional Commits title (for example feat(web): add bookmarks). More in CONTRIBUTING.md.

Stuck? Ask in this issue. Questions are welcome.


Generated by Claude Code

Dominant language
TypeScript
Stars
6
Forks
6
Avg merge
1h 59m
Merged PRs (30d)
59

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Haseeb-MernStack/commune

All issues in Haseeb-MernStack/commune

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.