# 🧪 QA & Testing Guide — GOFLOW Enterprise AI OS Portal

**QA & Testing Guide**
เวอร์ชัน 1.0 · Confidential – GOFLOW Enterprise · อัปเดตล่าสุด: 2026-08-07

---

## 1. หลักการ (Testing Philosophy)

- **คุณภาพคือความรับผิดชอบของทุกทีม** — QA กำหนดมาตรฐาน แต่ Developer เขียน test ของตัวเอง
- **Test Pyramid:** Unit มาก → Integration กลาง → E2E น้อยแต่ครอบคลุมเส้นทางหลัก
- **Quality Gate บังคับ:** งานจะถือว่าเสร็จต่อเมื่อผ่านทุกชั้นของ pipeline
- **AI ช่วยสร้าง Test:** ใช้ AI กำเนิด test cases, test data และ test reports (ตาม Testing Framework ของ GOFLOW)

---

## 2. ชั้นการทดสอบ (Test Pyramid)

```
        ▲  E2E (Playwright)         ~10%  — เส้นทางผู้ใช้หลัก
       ▲   Integration (Supertest)  ~30%  — API + DB + Services
      ▲    Unit (Jest/Vitest)       ~60%  — components, utils, logic
     ▲     Static (ESLint/TS)        ทุก commit — ผ่านก่อนเริ่ม
```

---

## 3. ประเภทการทดสอบ (ตาม GOFLOW AI Testing Framework)

| ประเภท | เครื่องมือ | ขอบเขต |
|---|---|---|
| Unit Testing | Jest / Vitest | component, util, hook, service logic เดี่ยว |
| Integration Testing | Supertest + Testcontainers | API → DB/Redis/MinIO จริง (container) |
| Runtime Testing | Playwright | พฤติกรรม AIOS: chat flow, agent status |
| E2E Testing | Playwright | เส้นทางผู้ใช้: จอง Demo, สมัครงาน, ติดต่อ |
| Security Testing | OWASP ZAP + npm audit | ช่องโหว่, dependency, header, injection |
| Performance Testing | Lighthouse CI + k6 | LCP/FCP/CLS + load test API |
| Accessibility Testing | axe-core + manual | WCAG 2.1 AA |

---

## 4. Test Plan แยกรายโมดูล

### 4.1 Frontend (Web App)

| เรื่อง | รายละเอียด |
|---|---|
| Component test | ทุก component มี test: render, interaction, states (hover/disabled/error) |
| Route test | ทุกหน้าเปิดได้, nav ครบ, 404 ทำงาน |
| Responsive test | 320px / 768px / 1280px / 1920px ไม่มี overflow |
| Form test | validation: required, email, tel, url; error + success states |
| Accessibility | keyboard ครบ, aria ถูก, contrast ผ่าน, axe ไม่มี violation |

### 4.2 Backend (API)

| เรื่อง | รายละเอียด |
|---|---|
| Contract test | request/response ตรงตาม OpenAPI spec |
| Auth test | login/refresh, token หมดอายุ, RBAC 403 |
| Input validation | 400 พร้อม details, SQL injection, XSS payload |
| Rate limit | 429 หลังเกิน limit |
| Idempotency | ส่ง request ซ้ำด้วย key เดียว → ผลลัพธ์เดียว |
| AI endpoints | mock NEXUS AI: success, timeout, 503 fallback |

### 4.3 AI (NEXUS AI Integration)

| เรื่อง | รายละเอียด |
|---|---|
| Chat correctness | ตอบตาม knowledge base, sources ถูกต้อง |
| Memory fusion | recall user/org memory ถูกต้อง (v7.3 behaviors) |
| Fallback | LLM down → ตอบ graceful error ไม่ hang |
| Latency | p95 < 5s (รวม RAG) |
| Cost guard | token usage ถูก metering และมี cap |

### 4.4 DevOps / Security

| เรื่อง | รายละเอียด |
|---|---|
| Container scan | Trivy ไม่มี critical vulnerability |
| Dependency scan | npm audit / renovate |
| Header check | CSP, HSTS, X-Frame-Options ครบ |
| Backup drill | restore ภายใน RTO |
| Load test | k6: 100 concurrent bookings, error rate < 1% |

---

## 5. Quality Gate (บังคับก่อน Merge)

```
Pull Request
   │
   ├─ 1. Lint + Type check (ESLint, tsc --noEmit) ── FAIL → กลับไปแก้
   ├─ 2. Unit Test (Jest) ────────────────────────── FAIL → กลับไปแก้
   ├─ 3. AI Code Review ──────────────────────────── พบปัญหา → แก้/ตอบ comment
   ├─ 4. Human Review (≥ 1 คน) ──────────────────── Approve เท่านั้น
   ├─ 5. Build + Preview deploy ──────────────────── ตรวจด้วยตา
   └─ 6. QA smoke test (critical path) ───────────── ผ่าน → Merge
```

**Release Gate (ก่อน Deploy Production):**
1. Full regression (E2E suite) ผ่าน
2. Security scan ผ่าน
3. Lighthouse ≥ 95 หน้าหลัก
4. Human Approval (Critical systems ตาม Release Process ของ GOFLOW)
5. Rollback plan พร้อม

---

## 6. เกณฑ์การยอมรับด้านคุณภาพ (Quality Metrics)

| Metric | เป้า |
|---|---|
| Unit coverage | ≥ 80% (critical modules ≥ 90%) |
| E2E pass rate | 100% ก่อน release |
| Lighthouse Performance | ≥ 95 |
| CLS | < 0.1 |
| LCP | < 2.5s |
| FCP | < 1.5s |
| Open bugs (blocker) | 0 |
| a11y violations | 0 (axe) |
| API p95 latency | < 500ms (ไม่รวม AI) |
| AI chat p95 | < 5s |

---

## 7. Test Environment

| Environment | ใช้กับ | ข้อมูล |
|---|---|---|
| Local | dev | Docker Compose + seed data |
| Staging | UAT, regression | สำเนา production, mock payment |
| Production | smoke test หลัง deploy | ไม่เขียนข้อมูลจริงจาก test |

**Test data:** ใช้ factory + seed script — ห้ามใช้ข้อมูลลูกค้าจริงในการทดสอบ (Privacy)

---

## 8. การรายงานผล

- ทุก Sprint: QA Summary Report (ผ่าน/ไม่ผ่าน/ความเสี่ยง) ในการ Sprint Review
- ทุก Release: Test Evidence (ผล E2E, Lighthouse, security scan) แนบใน release note
- Defect ระดับ blocker: แจ้ง Lead + DevOps ทันที ไม่รอ sprint meeting

---

*เอกสารนี้เป็นส่วนหนึ่งของ GOFLOW Developer Kit — สอดคล้องกับ GOFLOW-AI-Testing-Framework.md และ GOFLOW-Quality-Gate-System.md ใน D:\GOFLOW-DOCS*
