🧪 API route tests with an in-memory MongoDB

未关闭
#106 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
48/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
活跃
技术栈
javascript, mongodb, nextjs
领域
backend, testing

调研方向

Start by reading src/lib/mongodb.js to see how the connection is made, then one handler under src/pages/api/ such as the auth register route. Add the in-memory server setup and a separate Jest node-environment project in package.json, and put the tests under tests/. Done means auth flow, file ownership and sharing permissions from src/middleware/permissions.js are covered and run in CI without an external database.

由索引模型根据 Issue 内容生成。

描述

backend difficulty: medium help wanted testing

🚀 OrbitOS is growing — and you can grow with it!

We're building an open-source Web Operating System together, and the momentum is real. Every issue picked up, every PR merged, pushes OrbitOS closer to becoming something people use every day. Early contributors are the ones who shape the direction, earn the trust of the community and collect their stake in what OrbitOS becomes.

💬 Join the crew on Discord: https://discord.gg/NW2YZACf4k — ask questions, share progress, pair up with others, and meet the team.


🧭 Overview — what & why

Our backend (auth, files, sharing, users, packages) currently has no automated tests. Bugs there can lose user data or break login for everyone. Adding API tests gives us confidence to refactor and add features.

🔧 Technical details

  • Use mongodb-memory-server to spin up a real Mongo in tests and node-mocks-http (or next-test-api-route-handler) to call handlers directly.
  • Make src/lib/mongodb.js connection reusable/overridable in tests.
  • Cover: register → login → me → logout flow; file CRUD + ownership (user A cannot read user B's file); document sharing permissions (src/middleware/permissions.js); preferences update.
  • Separate Jest project for API tests (node environment) vs UI tests (jsdom) in package.json jest config.

🗺️ How it fits together

sequenceDiagram
    participant T as Jest test
    participant H as API handler
    participant M as mongodb-memory-server
    T->>M: start in-memory DB
    T->>H: POST /api/auth/register
    H->>M: insert user
    T->>H: POST /api/auth/login
    H-->>T: Set-Cookie token
    T->>H: GET /api/files (as other user)
    H-->>T: 403 ✅

📁 Where to look in the code

  • src/pages/api/
  • src/lib/mongodb.js
  • src/middleware/permissions.js
  • package.json
  • tests/

✅ Tasks

  • Test infra (memory server + jest projects)
  • Auth flow tests
  • File ownership tests
  • Sharing permission tests

🎯 Acceptance criteria

  • API tests run in CI without external DB
  • Ownership/permission rules covered

💡 Tips to get started

Start with the auth flow; it unlocks testing everything else.

👥 Teams

cc @codehubbers/core-contributors @codehubbers/javascript-typescript-advocates — this one is open for anyone in the org (and outside contributors too!). Reviewers and mentors welcome.


🙋 How to get involved

  1. Comment "I'd like to take this" so others know it's claimed (a maintainer will assign you).
  2. Fork the repo, create a branch like feat/short-name, and follow our Conventional Commit style (feat:, fix:, docs: …).
  3. Stuck? Drop a message in Discord — nobody builds alone here.
  4. Open a PR that references this issue (Closes #<number>) with screenshots / test output.

Difficulty: 🟡 Medium — whether this is your first open-source contribution or your hundredth, there's a place for you.

🌱 Every contribution counts

OrbitOS has huge growth potential, and the people building it now are the ones who will lead it tomorrow. Your PR is not just code — it's your name in the history of the project, your reputation in the community, and your stake in where we go next.

💬 Connect with us: https://discord.gg/NW2YZACf4k
⭐ If you believe in OrbitOS, star the repo and invite a friend — the bigger the crew, the faster we orbit! 🪐

主要语言
JavaScript
星标
16
派生
8
平均合并
4 小时 24 分钟
30 天内合并 PR
10

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 有 Pull Request 模板
  • 没有贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

codehubbers/OrbitOS 的其他 Issue

查看 codehubbers/OrbitOS 的全部 Issue

相似的 Issue

更多 JavaScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。