Repository navigation
feat: estabiliza contrato admin e gate de testes - #6
Conversation
Resumo do que foi implementado:
- Corrige retorno inconsistente dos mutators do CatalogProvider (remove/toggle/update)
- Padroniza respostas com objeto { ok, error } para fluxo admin
- Ajusta validacao de existencia de produto antes da mutacao via productMap
- Inclui/atualiza estrutura de testes: unitarios, integracao e smoke e2e
- Adiciona configuracoes de Vitest/Playwright e documentacao de testes
- Documenta a branch em BRANCH_IMPLEMENTATION_NOTES.md
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Pull request overview
This PR stabilizes the admin-facing mutation contract in CatalogProvider (standard { ok, error } responses and more deterministic mutator behavior) and introduces a full automated “quality gate” test stack (unit, integration, build, and smoke E2E) wired into local scripts and GitHub Actions.
Changes:
- Standardizes
CatalogProvidermutator returns to{ ok: boolean, error?: string }and adds existence checks viaproductMapbefore mutating. - Adds/organizes automated tests across unit, integration, known-issues, and Playwright smoke E2E; plus shared Vitest config and test setup files.
- Adds CI workflow and docs for the test gate, plus supporting configs and ignores for test artifacts.
Reviewed changes
Copilot reviewed 36 out of 38 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| vitest.unit.config.js | Adds Vitest unit-suite config. |
| vitest.shared.js | Shared Vitest/Vite base config (plugins + alias). |
| vitest.known-issues.config.js | Adds non-blocking “known issues” suite config w/ CI reporters. |
| vitest.integration.config.js | Adds Vitest integration-suite config (jsdom). |
| tests/unit/lib/whatsapp-attendant-open.test.js | Unit coverage for WhatsApp link opening behavior. |
| tests/unit/lib/store-utils.test.js | Unit coverage for pricing/currency and WhatsApp message generation. |
| tests/unit/lib/attendants-utils.test.js | Unit coverage for attendant sanitization + validation (incl. duplicates). |
| tests/unit/lib/attendants-flow.test.js | Unit coverage for attendant flow resolution and action resolution. |
| tests/unit/lib/admin-input-formatters.test.js | Unit coverage for admin input parsing/formatting. |
| tests/unit/lib/admin-auth.test.js | Unit coverage for admin auth/session token behavior. |
| tests/unit/api/admin-attendants-route.test.js | Unit coverage for admin attendants API route (auth + error mapping). |
| tests/setup/unit.setup.js | Unit-suite setup: mocks server-only, resets mocks/env. |
| tests/setup/jsdom.setup.js | jsdom setup: Testing Library hooks + browser API shims. |
| tests/known-issues/unavailable-item-warning.test.js | Tracks known issue around unavailable items warning text. |
| tests/known-issues/attendants-duplicates-policy.test.js | Tracks known issue / policy around duplicate attendants. |
| tests/known-issues/admin-contracts.test.jsx | Tracks known issue around provider/admin mutator contract. |
| tests/integration/providers/catalog-provider.integration.test.jsx | Integration coverage for CatalogProvider hydration + addProduct behavior. |
| tests/integration/providers/catalog-provider-admin-contract.integration.test.jsx | Integration coverage for admin mutator contract { ok, error }. |
| tests/integration/providers/cart-provider.integration.test.jsx | Integration coverage for CartProvider hydration/sanitization/limits. |
| tests/fixtures/catalog.fixture.js | Shared fixtures/helpers for catalog/cart persistence in tests. |
| tests/fixtures/attendants.fixture.js | Shared attendants fixtures for tests. |
| tests/e2e/smoke/runtime-mocks.js | Playwright init-script helpers for deterministic runtime state. |
| tests/e2e/smoke/contact-flow.smoke.spec.js | Smoke E2E for contact/attendant flow modes. |
| tests/e2e/smoke/checkout.smoke.spec.js | Smoke E2E for checkout flow and WhatsApp handoff. |
| playwright.smoke.config.js | Playwright config for smoke suite + webServer orchestration. |
| package.json | Adds test scripts and devDependencies for Vitest/Playwright/testing libs. |
| package-lock.json | Locks new devDependencies and transitive deps for test toolchain. |
| lib/store-utils.js | Adds unavailable-items warning into WhatsApp checkout message. |
| lib/attendants-utils.js | Deduplicates attendants by canonical phone; validates duplicates explicitly. |
| lib/attendants-data.js | Adds non-production runtime override hook for attendants (test support). |
| components/whatsapp-float-widget.js | Switches to default resolveAttendantFlow() usage. |
| components/providers/catalog-provider.js | Standardizes admin mutator returns; uses productMap existence checks. |
| app/contato/page.js | Switches to default resolveAttendantFlow() usage. |
| app/carrinho/page.js | Uses resolveAttendantFlow() and passes resolved attendants into action resolver. |
| TESTING.md | Documents test stack, commands, and gate/known-issues policy. |
| BRANCH_IMPLEMENTATION_NOTES.md | Branch notes documenting admin contract stabilization + gate setup. |
| .gitignore | Ignores Playwright/Vitest artifact directories. |
| .github/workflows/quality-gate.yml | Adds CI quality gate job + non-blocking known-issues job with artifacts. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @@ -382,107 +390,130 @@ export function CatalogProvider({ children }) { | |||
| }; | |||
| }); | |||
|
|
|||
| return { ok: true, id: createdId }; | |||
| return okResult({ id: createdId }); | |||
There was a problem hiding this comment.
addProduct preenche createdId via efeito colateral dentro do callback de setCatalog e retorna { ok: true, id: createdId } logo em seguida. Isso depende do momento em que o updater é executado (e pode ser reexecutado em dev/StrictMode), o que pode resultar em id vazio/instável ou divergente do estado aplicado. Sugestão: calcule o id de forma síncrona antes do setCatalog (usando o snapshot atual de productMap/catalog.products) e use esse id dentro do updater, ou use um gerador de ID estável (ex.: UUID) para não depender de efeitos colaterais do updater.
|
|
||
| ## Why this change | ||
| - The UI/admin layer expects stable return objects from provider actions. | ||
| - Previous implementation could return `{"ok":false,"error":"Produto nao encontrado."}` even when state updates were actually applied. |
There was a problem hiding this comment.
Correção de acentuação em documentação: "nao" → "não".
| - Previous implementation could return `{"ok":false,"error":"Produto nao encontrado."}` even when state updates were actually applied. | |
| - Previous implementation could return `{"ok":false,"error":"Produto não encontrado."}` even when state updates were actually applied. |
Resumo do que foi implementado:
Corrige retorno inconsistente dos mutators do CatalogProvider (remove/toggle/update)
Padroniza respostas com objeto { ok, error } para fluxo admin
Ajusta validacao de existencia de produto antes da mutacao via productMap
Inclui/atualiza estrutura de testes: unitarios, integracao e smoke e2e
Adiciona configuracoes de Vitest/Playwright e documentacao de testes
Documenta a branch em BRANCH_IMPLEMENTATION_NOTES.md