diff --git a/TEST_COVERAGE.md b/TEST_COVERAGE.md new file mode 100644 index 00000000..6e133dc2 --- /dev/null +++ b/TEST_COVERAGE.md @@ -0,0 +1,42 @@ +# Functional Test Coverage Report + +_Assessed 2026-08-11. This is not a code/line coverage report. It asks a different question: for the things a real user does in this app — log in, open a list, fill a form, download a report, call in and report attendance by phone — is there an automated test that actually exercises that behavior?_ + +## TL;DR + +- **Phone (Yemot IVR) attendance reporting is the best-tested feature in the app** — every call flow (transport confirmation, deadline cutoff, seminar attendance, manager report call) has a scenario test. +- **Report/export generation (Excel, PDF, "michlol" file) is well covered** at the data/business-logic level. +- ✅ **Client resource smoke tests and a Student CRUD e2e pilot have since been added** (see "What's genuinely covered"). +- **The client (browser UI) still has thin functional coverage** — the new smoke test confirms every resource list page renders, but no create/edit form, or button click is ever exercised. +- Login/auth itself is tested in the shared `nra-server`/`nra-client` libraries this app depends on, so it's inherited "for free" — not a gap specific to this app. + +## Coverage by area + +| Area | Client (browser) | Server (API / business logic) | Verdict | +|---|---|---|---| +| Phone attendance reporting (Yemot) | n/a | Every call-flow branch scenario-tested (`yemot-handler.service.test.ts`) | ✅ Strong | +| Report/export generation (Excel, PDF, michlol file) | Not applicable (triggered server-side) | `reportGenerator.spec.ts`, `michlolPopulatedFile.spec.ts`, `teacherReportFile.spec.ts`, `studentReportData.util.spec.ts` | ✅ Strong | +| Entity business logic (custom export headers, computed fields, per-entity services) | — | 20 entity-config spec files exercise these, but against mocked repos, not a real DB/HTTP call | 🟡 Partial | +| Entity list pages render (all 24 entities) | ✅ `client/src/entities.test.js` (added) | — | ✅ Covered | +| Entity CRUD over real HTTP | — | ✅ Student: create/list/update/delete (`server/test/student-crud.e2e-spec.ts`, added); other 23 entities: none | 🟡 Partial (1 of 24) | +| Entity Create/Edit forms (fill + submit in a browser-level test) | None | — | 🔴 Gap | +| Login / permissions | Inherited from shared libraries (`nra-client`/`nra-server`) | Inherited from shared libraries | 🟢 Covered elsewhere, no action needed | + +## What's genuinely covered + +- **`server/src/yemot-handler.service.test.ts`** — this is a real functional test suite for the phone-based attendance flow teachers use daily: past-deadline hangups, transport confirmation happy/error paths, seminar attendance (with and without signature permission), "already reported today" guards, and the manager's daily report call. If this suite is green, the phone flow genuinely works. +- **`server/src/reports/__tests__/`** — Excel/PDF/michlol report generation is tested against realistic data, so a broken report layout or missing field would be caught. +- **`server/src/entity-modules/__tests__/*.config.spec.ts`** — covers custom business logic living in entity configs (e.g. `StudentConfig`'s report-type routing), but only at the service level with a mocked repository. It proves the logic is correct in isolation, not that the API endpoint built on top of it works end to end. +- **`client/src/entities.test.js`** (added) — wires the shared `createResourceTests` helper; renders every registered resource's list page and confirms it loads without crashing. +- **`server/test/student-crud.e2e-spec.ts`** (added) — real HTTP create/list/update/delete lifecycle for Student, against the in-memory test DB (not a mocked repo). + +## What's not covered / at risk + +1. **Create/Edit forms are still unverified.** The client smoke test confirms list pages render; no test fills in and submits a Create or Edit form for any of the 24 entities. A broken field or crashing form would only be caught by a human clicking through the app. +2. **CRUD e2e covers only 1 of 24 entities** (Student). The other 23 (Teacher, Klass, AttReport, Grade, Transportation, …) still have no HTTP-level test. +3. **Bulk actions and admin-only screens** (grade entry, report-group sessions, teacher salary report) have no test above the config/service layer — same gap as #1 and #2. + +## Test inventory (what was reviewed) + +- Server: `server/src/__tests__/entities.module.spec.ts`, `server/src/entity-modules/__tests__/*.config.spec.ts` (20 files), `server/src/reports/__tests__/*.spec.ts` (3 files), `server/src/utils/__tests__/studentReportData.util.spec.ts`, `server/src/yemot-handler.service.test.ts`, `server/test/app.e2e-spec.ts`, `server/test/student-crud.e2e-spec.ts` (added). +- Client: `client/src/App.test.js`, `client/src/entities.test.js` (added). diff --git a/client/src/entities.test.js b/client/src/entities.test.js new file mode 100644 index 00000000..278b28f2 --- /dev/null +++ b/client/src/entities.test.js @@ -0,0 +1,5 @@ +// Smoke-tests every React Admin resource page registered in this app's App. +import { createResourceTests } from '@shared/utils/testing/createResourceTests'; +import App from 'src/App'; + +createResourceTests(App); diff --git a/server/test/student-crud.e2e-spec.ts b/server/test/student-crud.e2e-spec.ts new file mode 100644 index 00000000..569dd57b --- /dev/null +++ b/server/test/student-crud.e2e-spec.ts @@ -0,0 +1,85 @@ +import '@shared/config/crud.config'; +import * as cookieParser from 'cookie-parser'; +import { Test, TestingModule } from '@nestjs/testing'; +import { INestApplication } from '@nestjs/common'; +import { DataSource } from 'typeorm'; +import { AppModule } from 'src/app.module'; +import { HttpTestUtils } from '@shared/utils/testing/e2e/test-utils'; + +// The CRUD list endpoint returns a plain array by default, or a paginated +// { data: [...] } object once pagination kicks in (e.g. a page/limit query param). +// Normalize so list assertions below don't depend on which shape came back. +const asList = (body: any): any[] => (Array.isArray(body) ? body : body.data); + +describe('student CRUD (e2e)', () => { + let app: INestApplication; + let dataSource: DataSource; + let httpUtils: HttpTestUtils; + let cookie: string; + let moduleFixture: TestingModule; + + beforeAll(async () => { + moduleFixture = await Test.createTestingModule({ imports: [AppModule] }).compile(); + app = moduleFixture.createNestApplication(); + app.use(cookieParser()); + await app.init(); + dataSource = moduleFixture.get(DataSource); + httpUtils = new HttpTestUtils(app); + + const registerRes = await httpUtils + .post('/auth/register', { username: 'e2e_student_user', password: 'TestPass_123', name: 'E2E' }) + .expect(200); + const setCookieHeader = registerRes.headers['set-cookie']; + const authCookie = setCookieHeader?.[0]?.match(/Authentication=[^;]+/)?.[0]; + if (!authCookie) { + throw new Error(`Expected an Authentication cookie from /auth/register, got Set-Cookie: ${JSON.stringify(setCookieHeader)}`); + } + cookie = authCookie; + }); + + afterAll(async () => { + if (dataSource?.isInitialized) { + await dataSource.destroy(); + } + await app?.close(); + await moduleFixture?.close(); + }); + + it('runs a full create -> list -> update -> delete lifecycle over real HTTP', async () => { + // Create + const createRes = await httpUtils + .post('/student', { tz: '123456789', name: 'תלמידה בדיקה' }) + .set('Cookie', cookie) + .expect(201); + const studentId = createRes.body.id; + expect(studentId).toBeDefined(); + expect(createRes.body).toEqual(expect.objectContaining({ tz: '123456789', name: 'תלמידה בדיקה' })); + + // List + const listRes = await httpUtils + .get(`/student?filter[0]=tz||$eq||123456789`) + .set('Cookie', cookie) + .expect(200); + expect(asList(listRes.body).some((s: any) => s.id === studentId)).toBe(true); + + // Update + const updateRes = await httpUtils + .patch(`/student/${studentId}`, { name: 'תלמידה מעודכנת' }) + .set('Cookie', cookie) + .expect(200); + expect(updateRes.body).toEqual(expect.objectContaining({ id: studentId, name: 'תלמידה מעודכנת' })); + + const getAfterUpdateRes = await httpUtils.get(`/student/${studentId}`).set('Cookie', cookie).expect(200); + expect(getAfterUpdateRes.body.name).toBe('תלמידה מעודכנת'); + + // Delete + await httpUtils.delete(`/student/${studentId}`).set('Cookie', cookie).expect(200); + + await httpUtils.get(`/student/${studentId}`).set('Cookie', cookie).expect(404); + }); + + it('rejects creating a student without the required fields', async () => { + const res = await httpUtils.post('/student', {}).set('Cookie', cookie); + expect(res.status).toBe(400); + }); +});