How rahul-mygit/mid-test works
Purpose and Entry Points
This repository is a black-box conformance test suite for a Live Attendance System server; it does not contain the server implementation. The primary execution entry point is npm test, which runs the integration suite in index.test.js. Watch execution is exposed through npm run test:watch.
Paths: index.test.js, package.json, vitest.config.js
System Boundary Under Test
Tests target an independently running Node-compatible HTTP/WebSocket server. Default endpoints are http://localhost:3000 and ws://localhost:3000/ws; SERVER_URL and WS_URL override them. MongoDB is an external persistence dependency expected to be connected to that server.
The harness validates API contracts rather than directly accessing application internals or the database.
Paths: README.md, index.test.js
Authentication Contract
The first control-flow stage establishes user identity and authorization through POST /auth/signup, POST /auth/login, and GET /auth/me. Tests cover validation, duplicate-email handling, invalid credentials, authenticated identity lookup, and unauthorized access.
Authentication output is also a prerequisite for protected HTTP routes and authenticated WebSocket connections.
Paths: index.test.js
Class and Enrollment Boundary
Class management models the teacher-owned domain boundary. The tested server must support class creation, teacher-controlled student enrollment, and class retrieval with ownership/access checks. Student listing is restricted to teachers.
This stage supplies the class membership and ownership state required before attendance can begin.
Paths: index.test.js
Attendance Session Lifecycle
Attendance begins over HTTP via POST /attendance/start, which must validate class ownership and input. A student can retrieve personal class attendance through GET /class/:id/my-attendance, subject to enrollment checks.
The suite assumes a global constraint of only one active attendance session at a time. Completion must persist attendance, mark remaining students absent, and clear the active session.
Paths: index.test.js, README.md
Real-Time WebSocket Protocol
The WebSocket endpoint handles authenticated, event-based attendance operations. Teacher-only events include ATTENDANCE_MARKED and TODAY_SUMMARY, which broadcast relevant updates. Student-only MY_ATTENDANCE is expected to unicast the student’s status. DONE closes and persists the session.
Messages use { "event": "...", "data": ... }; invalid tokens, malformed messages, unknown events, role violations, and missing sessions are tested error boundaries.
Paths: index.test.js, README.md
Response and Verification Infrastructure
HTTP responses must consistently use { success: true, data } or { success: false, error }. Vitest provides the test runtime and timeout configuration; package scripts and lockfile define the Node dependency environment. The suite includes an end-to-end workflow covering signup through persisted attendance.
Paths: vitest.config.js, package.json, package-lock.json
Main entry points: README.md HTTP API · index.test.js Attendance session · vitest.config.js Vitest runtime · package.json npm test / watch
Components 15
Conformance Suite
Black-box integration tests and Node test tooling.
- npm test / watch
package.json - Vitest runtime · Provides integration execution and timeout settings.
vitest.config.js - Integration suite · Validates public HTTP and WebSocket contracts end to end.
index.test.js - End-to-end workflow · Covers signup through persisted attendance.
index.test.js
Server Under Test
Independently running Live Attendance System.
- HTTP API · Default target is localhost:3000; SERVER_URL can override it.
README.md - Authentication · Signup, login, and identity lookup establish authorized users.
index.test.js - Classes & enrollment · Teacher ownership and membership gate attendance access.
index.test.js - Attendance session · One global active session; completion persists results and marks absences.
index.test.js - Personal attendance · Enrolled students retrieve their own class attendance.
index.test.js - WebSocket protocol · Authenticated event channel at /ws; WS_URL can override it.
README.md - Teacher events · ATTENDANCE_MARKED and TODAY_SUMMARY broadcast updates.
index.test.js - Student events · MY_ATTENDANCE unicasts a student's status.
index.test.js - DONE event · Closes the active session and persists attendance.
index.test.js - Response & error contract · HTTP envelopes and protocol errors cover invalid input, tokens, roles, and sessions.
index.test.js
Other components
- MongoDB · Persistence dependency connected to the server under test.
README.md
Connections 22
- npm test / watch → Vitest runtime: runs
- Vitest runtime → Integration suite: executes
- Integration suite → End-to-end workflow: includes
- Integration suite → HTTP API: tests
- Integration suite → WebSocket protocol: tests
- HTTP API → Authentication: serves
- HTTP API → Classes & enrollment: serves
- HTTP API → Attendance session: starts
- HTTP API → Personal attendance: retrieves
- Authentication → Classes & enrollment: authorizes
- Classes & enrollment → Attendance session: supplies ownership and enrollment
- Classes & enrollment → Personal attendance: gates access
- Authentication → WebSocket protocol: authenticates connections
- WebSocket protocol → Teacher events: handles
- WebSocket protocol → Student events: handles
- WebSocket protocol → DONE event: handles
- Teacher events → Attendance session: updates active attendance
- Student events → Attendance session: reads status
- DONE event → Attendance session: completes
- Attendance session → MongoDB: persists attendance
- HTTP API → Response & error contract: returns
- WebSocket protocol → Response & error contract: enforces errors