chore: update project documentation, audit reports, and initialize IDE configuration files
Some checks failed
CI / Lint → Typecheck → Test → Build (22) (push) Failing after 29s
CI / E2E Tests (push) Has been skipped
CodeQL Analysis / CodeQL (javascript-typescript) (push) Failing after 2m42s
Deploy / Build Web Image (push) Failing after 27s
Deploy / Build AI Services Image (push) Failing after 29s
E2E Tests / Playwright E2E (push) Failing after 43s
Deploy / Build API Image (push) Failing after 1m31s
Security Scanning / Dependency Audit (pnpm) (push) Failing after 6s
Security Scanning / Trivy Scan — API Image (push) Failing after 5m35s
Security Scanning / Trivy Scan — AI Services Image (push) Failing after 3m45s
Deploy / Deploy to Staging (push) Has been skipped
Deploy / Smoke Test Staging (push) Has been skipped
Deploy / Deploy to Production (push) Has been skipped
Deploy / Smoke Test Production (push) Has been skipped
Deploy / Rollback Staging (push) Has been skipped
Deploy / Rollback Production (push) Has been skipped
Security Scanning / Trivy Scan — Web Image (push) Failing after 13m51s
Security Scanning / Trivy Filesystem Scan (push) Failing after 14m46s
Security Scanning / Security Gate (push) Has been cancelled

This commit is contained in:
Ho Ngoc Hai
2026-04-19 03:12:54 +07:00
parent 3be106074d
commit 11f2bf26e6
101 changed files with 21312 additions and 20672 deletions

View File

@@ -1,77 +1,77 @@
# 🎯 QUICK REFERENCE: 3 Missing Test Files
# 🎯 THAM KHẢO NHANH: 3 Tệp Test Còn Thiếu
## Priority: HIGH - All need tests
## Ưu tiên: CAO - Tất cả đều cần viết test
### 1⃣ reject-listing.handler.spec.ts
**Location:** `apps/api/src/modules/admin/application/__tests__/`
**Pattern to follow:** `approve-listing.handler.spec.ts`
**Test coverage needed:**
-Happy path: Successfully rejects PENDING_REVIEW listing
-Error: NotFoundException when listing doesn't exist
-Error: ValidationException for wrong listing status
-Verify: listingRepo.update() called once
-Verify: ListingRejectedEvent published with correct data
**Vị trí:** `apps/api/src/modules/admin/application/__tests__/`
**Mẫu tham khảo:** `approve-listing.handler.spec.ts`
**Phạm vi test cần có:**
-Trường hợp thành công: Từ chối listing ở trạng thái PENDING_REVIEW thành công
-Lỗi: NotFoundException khi listing không tồn tại
-Lỗi: ValidationException khi trạng thái listing không hợp lệ
-Xác minh: listingRepo.update() được gọi đúng một lần
-Xác minh: ListingRejectedEvent được phát với dữ liệu chính xác
**Key code:**
**Code quan trọng:**
- Command: RejectListingCommand(listingId, adminId, reason)
- Handler: RejectListingHandler
- Event: ListingRejectedEvent
- Result: { listingId, status: 'REJECTED', message }
- Kết quả trả về: { listingId, status: 'REJECTED', message }
---
### 2⃣ get-revenue-stats.handler.spec.ts
**Location:** `apps/api/src/modules/admin/application/__tests__/`
**Pattern to follow:** `get-dashboard-stats.handler.spec.ts`
**Test coverage needed:**
- ✅ Query returns RevenueStatsItem[] from repository
-Verify: adminQueryRepo.getRevenueStats() called with startDate, endDate, groupBy
-Support both 'day' and 'month' groupBy values
-Default groupBy is 'month'
-Handle empty results (empty array)
**Vị trí:** `apps/api/src/modules/admin/application/__tests__/`
**Mẫu tham khảo:** `get-dashboard-stats.handler.spec.ts`
**Phạm vi test cần có:**
- ✅ Query trả về RevenueStatsItem[] từ repository
-Xác minh: adminQueryRepo.getRevenueStats() được gọi với startDate, endDate, groupBy
-Hỗ trợ cả hai giá trị 'day' 'month' cho groupBy
-Mặc định groupBy 'month'
-Xử lý kết quả rỗng (mảng trống)
**Key code:**
**Code quan trọng:**
- Query: GetRevenueStatsQuery(startDate, endDate, groupBy='month')
- Handler: GetRevenueStatsHandler
- Returns: RevenueStatsItem[] with { period, totalRevenue, subscriptionRevenue, listingFeeRevenue, featuredListingRevenue, transactionCount }
- Trả về: RevenueStatsItem[] với { period, totalRevenue, subscriptionRevenue, listingFeeRevenue, featuredListingRevenue, transactionCount }
---
### 3⃣ user-deactivated.listener.spec.ts
**Location:** `apps/api/src/modules/admin/application/__tests__/`
**Pattern to follow:** `user-banned.listener.spec.ts`
**Test coverage needed:**
- ✅ Event listener handles 'user.deactivated' event
-Expires listings with status ACTIVE or PENDING_REVIEW
-Only updates deactivated user's listings
-Logs initial handling and result
-Handle case with 0 listings updated
-Handle case with multiple listings updated
**Vị trí:** `apps/api/src/modules/admin/application/__tests__/`
**Mẫu tham khảo:** `user-banned.listener.spec.ts`
**Phạm vi test cần có:**
- ✅ Event listener xử lý sự kiện 'user.deactivated'
-Hết hạn các listing có trạng thái ACTIVE hoặc PENDING_REVIEW
-Chỉ cập nhật listing của người dùng bị vô hiệu hóa
-Ghi log ban đầu khi xử lý và kết quả
-Xử lý trường hợp 0 listing được cập nhật
-Xử lý trường hợp nhiều listing được cập nhật
**Key code:**
**Code quan trọng:**
- Listener: UserDeactivatedListener
- Event: UserDeactivatedEvent (async: true)
- Action: prisma.listing.updateMany() where sellerId matches & status in [ACTIVE, PENDING_REVIEW]
- Logging: Initial + result count
- Hành động: prisma.listing.updateMany() với điều kiện sellerId khớp & status thuộc [ACTIVE, PENDING_REVIEW]
- Ghi log: Khởi tạo + số lượng kết quả
---
## Mock Setup Templates
## Mẫu Thiết Lập Mock
### For Handler (Command):
### Dành cho Handler (Command):
```typescript
mockListingRepo = { findById, update, ... };
mockEventBus = { publish };
handler = new RejectListingHandler(mockListingRepo, mockEventBus);
```
### For Query Handler:
### Dành cho Query Handler:
```typescript
mockAdminQueryRepo = { getRevenueStats };
handler = new GetRevenueStatsHandler(mockAdminQueryRepo);
```
### For Listener:
### Dành cho Listener:
```typescript
mockPrisma = { listing: { updateMany }, user: { findUnique } };
mockLogger = { log };
@@ -80,10 +80,10 @@ listener = new UserDeactivatedListener(mockPrisma, mockLogger);
---
## Testing Checklist
## Danh Sách Kiểm Tra Test
- [ ] reject-listing.handler.spec.ts created
- [ ] get-revenue-stats.handler.spec.ts created
- [ ] user-deactivated.listener.spec.ts created
- [ ] All tests pass: `npm test admin`
- [ ] Coverage report shows green for all 3 files
- [ ] reject-listing.handler.spec.ts đã được tạo
- [ ] get-revenue-stats.handler.spec.ts đã được tạo
- [ ] user-deactivated.listener.spec.ts đã được tạo
- [ ] Tất cả test đều vượt qua: `npm test admin`
- [ ] Báo cáo độ phủ hiển thị màu xanh cho cả 3 tệp