33 lines
2.3 KiB
Markdown
33 lines
2.3 KiB
Markdown
# FitOS — zasady pracy z kodem
|
|
|
|
## Struktura
|
|
- `app` (React+Vite, 5173), `admin` (React+Vite, 5174), `api` (Express+Prisma+PostgreSQL, 9002).
|
|
|
|
## Testy — obowiązkowe po każdej zmianie
|
|
- Konwencja: WSZYSTKIE testy projektu żyją w `<pkg>/test/` — unit/komponent w `test/*` (api: `test/unit/` + `test/integration/`), e2e w `test/e2e/`. Rezultaty i artefakty też pod `test/`: `test/results/` (trace/screenshoty Playwright) i `test/report/` (raport HTML) — oba gitignore'owane. Nie twórz katalogów testowych poza `test/`.
|
|
- `app`/`admin`: `npm test` (vitest), `npm run test:e2e` (Playwright, API mockowane, dev server sam). `api`: `npm test` (unit+integration, supertest).
|
|
- Testy aktualizujesz w tej samej zmiance co kod. Zmiana UI → najpierw grep starych tekstów/selectorów w testach.
|
|
- e2e: `import { test } from './fixtures'` (NIE `@playwright/test`) — guard FAIL przy `console.error`/`pageerror`; wyjątek: `allowConsoleError(page, /re/)` + komentarz. Ignorowane: 401. 403/404/5xx = FAIL.
|
|
- e2e bez API/DB: `mockApi(page, ...)` z `test/e2e/mock-api.ts`. Nowe pliki: `test/e2e/<obszar>.spec.ts`, opisy PL.
|
|
- Selektory: `getByRole`/`getByText`/`input[type=...]` — `getByLabel` NIE działa (`Field` bez `<label>`).
|
|
|
|
## Zmiana kontraktu API — aktualizuj WSZYSTKO w jednej zmiance
|
|
1. `api/src/routes/**` + walidacja zod + `api/test/**`
|
|
2. typy: `app/src/api/types.ts` i/lub `admin/src/api/types.ts`
|
|
3. front: `api/queries.ts`, `pages/**`, `store/auth.ts`
|
|
4. mocki `app|admin/test/e2e/mock-api.ts` + testy e2e
|
|
5. `npm test` (api) + `npm test`/`test:e2e` (dotknięte fronty)
|
|
|
|
`prisma/schema.prisma` → `npm run prisma:migrate` (kontener API sam robi `migrate deploy` + seed przy starcie).
|
|
|
|
## Kontenery — rebuilduj tylko dotknięte
|
|
- `api/`: `fitos-api` (9002) + `fitos-db` (pg16, wolumen `fitos_pgdata`). `admin/`: 9000 (nginx+dist). `app/`: 9001 (nginx+dist).
|
|
- Zmiana `<pkg>/src/**` (albo `api/prisma/**`, `index.html`) → w katalogu `<pkg>/`: `docker compose build <pkg> && docker compose up -d`.
|
|
- `.env` api → `up -d --force-recreate api`. Nigdy nie ruszaj wolumenu `fitos_pgdata`.
|
|
- Weryfikacja po zmianie api: `docker compose ps` + `curl localhost:9002/health`.
|
|
|
|
## Komendy
|
|
| | komenda |
|
|
| --- | --- |
|
|
| app/admin | `npm test`, `npm run test:e2e`, `test:e2e:ui`, `test:e2e:install` |
|
|
| api | `npm test`, `npm run seed`, `npm run prisma:migrate` | |