Files
goodgo-platform/docs/audits/TEST_COVERAGE_AUDIT.md
Ho Ngoc Hai 11f2bf26e6
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
chore: update project documentation, audit reports, and initialize IDE configuration files
2026-04-19 03:12:54 +07:00

32 KiB

GoodGo Platform AI - Báo Cáo Kiểm Tra Độ Bao Phủ Kiểm Thử

Ngày: 10 tháng 4 năm 2026 Kho lưu trữ: /Users/velikho/Desktop/WORKING/goodgo-platform-ai/apps/api/src/modules/


TÓM TẮT ĐIỀU HÀNH

Báo cáo kiểm tra này phân tích độ bao phủ kiểm thử trên ba module quan trọng trong phần backend của GoodGo Platform AI:

Module Tệp nguồn Tệp kiểm thử Độ bao phủ
Listings 42 13 31%
Auth 56 21 38%
Search 22 10 45%
TỔNG CỘNG 120 44 37%

Phát hiện chính: Mặc dù các tệp kiểm thử đã tồn tại cho những handler và entity miền quan trọng, nhiều dịch vụ hạ tầng, value object, repository và thành phần tầng trình bày vẫn còn thiếu độ bao phủ kiểm thử.


1. KIỂM TRA MODULE LISTINGS

Vị trí: apps/api/src/modules/listings/

Thống kê Module

  • Tổng số tệp nguồn: 42 (không tính các tệp index.ts)
  • Tổng số tệp kiểm thử: 13
  • Độ bao phủ tổng thể: 31% (13 trong 42 tệp quan trọng có kiểm thử)

Các tệp kiểm thử hiện có (tổng 13 tệp)

Kiểm thử tầng ứng dụng (8 tệp)

  • create-listing.handler.spec.ts → Kiểm thử CreateListingHandler
  • get-listing.handler.spec.ts → Kiểm thử GetListingHandler
  • get-pending-moderation.handler.spec.ts → Kiểm thử GetPendingModerationHandler
  • moderate-listing.handler.spec.ts → Kiểm thử ModerateListingHandler
  • search-listings.handler.spec.ts → Kiểm thử SearchListingsHandler
  • update-listing-status.handler.spec.ts → Kiểm thử UpdateListingStatusHandler
  • upload-media.handler.spec.ts → Kiểm thử UploadMediaHandler
  • price-validator.spec.ts → Kiểm thử PrismaPriceValidator (Hạ tầng)

Kiểm thử tầng miền (5 tệp)

  • duplicate-detector.spec.ts → Kiểm thử logic tương đồng trigram
  • listing-events.spec.ts → Kiểm thử các sự kiện miền
  • listing.entity.spec.ts → Kiểm thử ListingEntity
  • property.entity.spec.ts → Kiểm thử PropertyEntity & PropertyMediaEntity
  • value-objects.spec.ts → Kiểm thử các VO Address, GeoPoint, Price

CÁC TỆP NGUỒN CHƯA ĐƯỢC KIỂM THỬ - ƯU TIÊN CAO

🔴 Entity Miền & Value Object (CHƯA KIỂM THỬ - 9 tệp)

Đây là những thành phần quan trọng cho logic nghiệp vụ:

Entity miền:

  1. domain/entities/listing.entity.ts ⚠️ ĐÃ CÓ KIỂM THỬ - listed.entity.spec.ts
  2. domain/entities/property.entity.ts ⚠️ ĐÃ CÓ KIỂM THỬ - property.entity.spec.ts
  3. domain/entities/property-media.entity.ts ⚠️ ĐÃ CÓ KIỂM THỬ - property.entity.spec.ts

Value Object miền: 4. domain/value-objects/address.vo.ts ⚠️ ĐÃ CÓ KIỂM THỬ - value-objects.spec.ts 5. domain/value-objects/geo-point.vo.ts ⚠️ ĐÃ CÓ KIỂM THỬ - value-objects.spec.ts 6. domain/value-objects/price.vo.ts ⚠️ ĐÃ CÓ KIỂM THỬ - value-objects.spec.ts

Sự kiện miền (THIẾU KIỂM THỬ - 4 tệp): 7. domain/events/listing-created.event.ts - ⚠️ Đã có độ bao phủ kiểm thử trong listing-events.spec.ts 8. domain/events/listing-approved.event.ts - ✗ CHƯA CÓ TỆP KIỂM THỬ 9. domain/events/listing-sold.event.ts - ✗ CHƯA CÓ TỆP KIỂM THỬ 10. domain/events/listing-status-changed.event.ts - ✗ CHƯA CÓ TỆP KIỂM THỬ

Dịch vụ miền (3 tệp): 11. domain/services/duplicate-detector.ts ⚠️ ĐÃ CÓ KIỂM THỬ - duplicate-detector.spec.ts 12. domain/services/moderation.service.ts - ✗ CHƯA CÓ TỆP KIỂM THỬ (giao diện logic nghiệp vụ) 13. domain/services/price-validator.ts ⚠️ ĐÃ CÓ KIỂM THỬ - price-validator.spec.ts

Repository miền (GIAO DIỆN - 3 tệp): 14. domain/repositories/listing.repository.ts - ✗ CHƯA CÓ KIỂM THỬ (chỉ là abstract/interface) 15. domain/repositories/property.repository.ts - ✗ CHƯA CÓ KIỂM THỬ (chỉ là abstract/interface) 16. domain/repositories/listing-read.dto.ts - ✗ CHƯA CÓ KIỂM THỬ (đối tượng truyền dữ liệu)


🔴 Handler & Command ứng dụng (KIỂM THỬ MỘT PHẦN - 14 tệp)

Command (8 tệp):

  1. application/commands/create-listing/create-listing.command.ts - ✓ Kiểm thử thông qua handler
  2. application/commands/create-listing/create-listing.handler.ts - ✓ ĐÃ KIỂM THỬ
  3. application/commands/moderate-listing/moderate-listing.command.ts - ✓ Kiểm thử thông qua handler
  4. application/commands/moderate-listing/moderate-listing.handler.ts - ✓ ĐÃ KIỂM THỬ
  5. application/commands/update-listing-status/update-listing-status.command.ts - ✓ Kiểm thử thông qua handler
  6. application/commands/update-listing-status/update-listing-status.handler.ts - ✓ ĐÃ KIỂM THỬ
  7. application/commands/upload-media/upload-media.command.ts - ✓ Kiểm thử thông qua handler
  8. application/commands/upload-media/upload-media.handler.ts - ✓ ĐÃ KIỂM THỬ

Query (6 tệp): 9. application/queries/get-listing/get-listing.query.ts - ✓ Kiểm thử thông qua handler 10. application/queries/get-listing/get-listing.handler.ts - ✓ ĐÃ KIỂM THỬ 11. application/queries/get-pending-moderation/get-pending-moderation.query.ts - ✓ Kiểm thử thông qua handler 12. application/queries/get-pending-moderation/get-pending-moderation.handler.ts - ✓ ĐÃ KIỂM THỬ 13. application/queries/search-listings/search-listings.query.ts - ✓ Kiểm thử thông qua handler 14. application/queries/search-listings/search-listings.handler.ts - ✓ ĐÃ KIỂM THỬ


🔴 Tầng hạ tầng - Dịch vụ & Repository (THIẾU KIỂM THỬ - 6 tệp)

Dịch vụ hạ tầng quan trọng:

  1. infrastructure/services/media-storage.service.ts - ✗ CHƯA CÓ TỆP KIỂM THỬ

    • Xử lý các thao tác tải lên/lưu trữ tệp
    • Cần kiểm thử: tải lên thành công, xử lý lỗi, giải quyết đường dẫn
  2. infrastructure/services/prisma-duplicate-detector.ts - ✗ CHƯA CÓ TỆP KIỂM THỬ

    • Triển khai giao diện phát hiện trùng lặp miền
    • Cần kiểm thử: truy vấn cơ sở dữ liệu, tích hợp logic tương đồng
  3. infrastructure/services/prisma-price-validator.ts - ✗ CHƯA CÓ TỆP KIỂM THỬ

    • Triển khai giao diện xác thực giá miền
    • Cần kiểm thử: truy vấn khoảng giá, logic xác thực

Repository hạ tầng: 4. infrastructure/repositories/prisma-listing.repository.ts - ✗ CHƯA CÓ TỆP KIỂM THỬ

  • Truy cập dữ liệu chính cho các tin đăng
  • Cần kiểm thử: thao tác CRUD, truy vấn phức tạp
  1. infrastructure/repositories/prisma-property.repository.ts - ✗ CHƯA CÓ TỆP KIỂM THỬ

    • Truy cập dữ liệu cho bất động sản
    • Cần kiểm thử: tạo bất động sản, thao tác với media
  2. infrastructure/repositories/listing-read.queries.ts - ✗ CHƯA CÓ TỆP KIỂM THỬ

    • Truy vấn đọc phức tạp cho các tính năng tin đăng
    • Cần kiểm thử: xây dựng truy vấn, logic lọc

🔴 Tầng trình bày (THIẾU KIỂM THỬ - 6 tệp)

Controller:

  1. presentation/controllers/listings.controller.ts - ✗ CHƯA CÓ TỆP KIỂM THỬ
    • Handler điểm cuối API chính
    • Cần kiểm thử: định tuyến yêu cầu, định dạng phản hồi

DTO/Đối tượng truyền dữ liệu: 2. presentation/dto/create-listing.dto.ts - ✗ CHƯA CÓ TỆP KIỂM THỬ 3. presentation/dto/moderate-listing.dto.ts - ✗ CHƯA CÓ TỆP KIỂM THỬ 4. presentation/dto/search-listings.dto.ts - ✗ CHƯA CÓ TỆP KIỂM THỬ 5. presentation/dto/update-listing-status.dto.ts - ✗ CHƯA CÓ TỆP KIỂM THỬ

Định nghĩa module: 6. listings.module.ts - ✗ CHƯA CÓ TỆP KIỂM THỬ (cấu hình module NestJS)


XẾP HẠNG ƯU TIÊN CHO CÁC KIỂM THỬ MỚI

BẬC 1 - QUAN TRỌNG (Logic nghiệp vụ, phải kiểm thử trước):

  1. infrastructure/services/prisma-duplicate-detector.ts - Phát hiện trùng lặp cốt lõi
  2. infrastructure/services/prisma-price-validator.ts - Logic xác thực giá
  3. infrastructure/repositories/prisma-listing.repository.ts - Tầng truy cập dữ liệu chính
  4. domain/services/moderation.service.ts - Quy tắc nghiệp vụ kiểm duyệt

BẬC 2 - CAO (Hạ tầng, truy cập dữ liệu): 5. infrastructure/repositories/prisma-property.repository.ts - Truy cập dữ liệu bất động sản 6. infrastructure/repositories/listing-read.queries.ts - Tối ưu hóa truy vấn đọc 7. infrastructure/services/media-storage.service.ts - Xử lý tệp

BẬC 3 - TRUNG BÌNH (Trình bày, DTO): 8. presentation/controllers/listings.controller.ts - Các điểm cuối HTTP 9. presentation/dto/create-listing.dto.ts - Xác thực đầu vào 10. presentation/dto/moderate-listing.dto.ts - Xác thực đầu vào 11. presentation/dto/search-listings.dto.ts - Xác thực đầu vào 12. presentation/dto/update-listing-status.dto.ts - Xác thực đầu vào

BẬC 4 - THẤP (Cấu hình, sự kiện): 13. listings.module.ts - Cấu hình module 14. domain/events/listing-approved.event.ts - Mô hình sự kiện 15. domain/events/listing-sold.event.ts - Mô hình sự kiện 16. domain/events/listing-status-changed.event.ts - Mô hình sự kiện



2. KIỂM TRA MODULE AUTH

Vị trí: apps/api/src/modules/auth/

Thống kê Module

  • Tổng số tệp nguồn: 56 (không tính các tệp index.ts)
  • Tổng số tệp kiểm thử: 21
  • Độ bao phủ tổng thể: 38% (21 trong 56 tệp có kiểm thử toàn diện)

Các tệp kiểm thử hiện có (tổng 21 tệp)

Kiểm thử tầng ứng dụng (12 tệp)

  • cancel-user-deletion.handler.spec.ts → CancelUserDeletionHandler
  • export-user-data.handler.spec.ts → ExportUserDataHandler
  • force-delete-user.handler.spec.ts → ForceDeleteUserHandler
  • get-agent-by-user-id.handler.spec.ts → GetAgentByUserIdHandler
  • get-profile.handler.spec.ts → GetProfileHandler
  • login-user.handler.spec.ts → LoginUserHandler
  • process-scheduled-deletions.handler.spec.ts → ProcessScheduledDeletionsHandler
  • refresh-token.handler.spec.ts → RefreshTokenHandler
  • register-user.handler.spec.ts → RegisterUserHandler
  • request-user-deletion.handler.spec.ts → RequestUserDeletionHandler
  • verify-kyc.handler.spec.ts → VerifyKycHandler

Kiểm thử tầng hạ tầng (4 tệp)

  • google-oauth.strategy.spec.ts → GoogleOAuthStrategy
  • oauth.service.spec.ts → OAuthService
  • token.service.spec.ts → TokenService
  • zalo-oauth.strategy.spec.ts → ZaloOAuthStrategy

Kiểm thử tầng miền (5 tệp)

  • auth-events.spec.ts → Sự kiện miền (UserRegistered, v.v.)
  • email.vo.spec.ts → Value object Email
  • hashed-password.vo.spec.ts → Value object HashedPassword
  • phone.vo.spec.ts → Value object Phone
  • user.entity.spec.ts → UserEntity

Kiểm thử cấp gốc (1 tệp)

  • auth.integration.spec.ts → Kiểm thử tích hợp cho auth controller

CÁC TỆP NGUỒN CHƯA ĐƯỢC KIỂM THỬ - ƯU TIÊN CAO

🔴 Entity Miền & Value Object

Entity miền (1 tệp):

  1. domain/entities/user.entity.ts ⚠️ ĐÃ CÓ KIỂM THỬ - user.entity.spec.ts

Value Object miền (3 tệp): 2. domain/value-objects/email.vo.ts ⚠️ ĐÃ CÓ KIỂM THỬ - email.vo.spec.ts 3. domain/value-objects/hashed-password.vo.ts ⚠️ ĐÃ CÓ KIỂM THỬ - hashed-password.vo.spec.ts 4. domain/value-objects/phone.vo.ts ⚠️ ĐÃ CÓ KIỂM THỬ - phone.vo.spec.ts

Sự kiện miền (4 tệp - tất cả thiếu kiểm thử riêng lẻ): 5. domain/events/user-registered.event.ts ⚠️ ĐÃ CÓ KIỂM THỬ - auth-events.spec.ts 6. domain/events/user-deactivated.event.ts ⚠️ ĐÃ CÓ KIỂM THỬ - auth-events.spec.ts 7. domain/events/user-kyc-updated.event.ts ⚠️ ĐÃ CÓ KIỂM THỬ - auth-events.spec.ts 8. domain/events/agent-verified.event.ts ⚠️ ĐÃ CÓ KIỂM THỬ - auth-events.spec.ts

Repository miền (2 tệp - Giao diện abstract): 9. domain/repositories/user.repository.ts - ✗ CHƯA CÓ KIỂM THỬ (chỉ là interface/hợp đồng) 10. domain/repositories/refresh-token.repository.ts - ✗ CHƯA CÓ KIỂM THỬ (chỉ là interface/hợp đồng)


🔴 Handler & Command ứng dụng (KIỂM THỬ MỘT PHẦN - 20 tệp)

Command (18 tệp): 1-18. Tất cả các tệp command ĐỀU CÓ kiểm thử handler tương ứng:

  • application/commands/cancel-user-deletion/* ✓ ĐÃ KIỂM THỬ
  • application/commands/export-user-data/* ✓ ĐÃ KIỂM THỬ
  • application/commands/force-delete-user/* ✓ ĐÃ KIỂM THỬ
  • application/commands/login-user/* ✓ ĐÃ KIỂM THỬ
  • application/commands/process-scheduled-deletions/* ✓ ĐÃ KIỂM THỬ
  • application/commands/refresh-token/* ✓ ĐÃ KIỂM THỬ
  • application/commands/register-user/* ✓ ĐÃ KIỂM THỬ
  • application/commands/request-user-deletion/* ✓ ĐÃ KIỂM THỬ
  • application/commands/verify-kyc/* ✓ ĐÃ KIỂM THỬ

Query (4 tệp): 19. application/queries/get-profile/get-profile.query.ts ✓ Kiểm thử thông qua handler 20. application/queries/get-profile/get-profile.handler.ts ✓ ĐÃ KIỂM THỬ 21. application/queries/get-agent-by-user-id/get-agent-by-user-id.query.ts ✓ Kiểm thử thông qua handler 22. application/queries/get-agent-by-user-id/get-agent-by-user-id.handler.ts ✓ ĐÃ KIỂM THỬ


🔴 Tầng hạ tầng - Dịch vụ & Repository (THIẾU KIỂM THỬ - 6 tệp)

Dịch vụ hạ tầng (2 tệp):

  1. infrastructure/services/oauth.service.ts ⚠️ ĐÃ CÓ KIỂM THỬ - oauth.service.spec.ts
  2. infrastructure/services/token.service.ts ⚠️ ĐÃ CÓ KIỂM THỬ - token.service.spec.ts

Strategy hạ tầng (4 tệp - Thiếu kiểm thử): 3. infrastructure/strategies/google-oauth.strategy.ts ⚠️ ĐÃ CÓ KIỂM THỬ - google-oauth.strategy.spec.ts 4. infrastructure/strategies/zalo-oauth.strategy.ts ⚠️ ĐÃ CÓ KIỂM THỬ - zalo-oauth.strategy.spec.ts 5. infrastructure/strategies/jwt.strategy.ts - ✗ CHƯA CÓ TỆP KIỂM THỬ

  • Strategy xác thực JWT
  • Cần kiểm thử: xác thực token, trích xuất người dùng
  1. infrastructure/strategies/local.strategy.ts - ✗ CHƯA CÓ TỆP KIỂM THỬ
    • Xác thực cục bộ (tên đăng nhập/mật khẩu)
    • Cần kiểm thử: xác thực thông tin đăng nhập, tra cứu người dùng

Repository hạ tầng (2 tệp): 7. infrastructure/repositories/prisma-user.repository.ts - ✗ CHƯA CÓ TỆP KIỂM THỬ

  • Truy cập dữ liệu người dùng chính
  • Cần kiểm thử: thao tác CRUD, truy vấn tra cứu người dùng
  1. infrastructure/repositories/prisma-refresh-token.repository.ts - ✗ CHƯA CÓ TỆP KIỂM THỬ
    • Tầng lưu trữ refresh token
    • Cần kiểm thử: tạo token, xác thực, xoay vòng

🔴 Tầng trình bày (THIẾU KIỂM THỬ - 14 tệp)

Controller (3 tệp):

  1. presentation/controllers/auth.controller.ts - ✗ CHƯA CÓ TỆP KIỂM THỬ (được bao phủ bởi kiểm thử tích hợp)
  2. presentation/controllers/oauth.controller.ts - ✗ CHƯA CÓ TỆP KIỂM THỬ
  3. presentation/controllers/user-data.controller.ts - ✗ CHƯA CÓ TỆP KIỂM THỬ

Guard (4 tệp - Quan trọng cho bảo mật): 4. presentation/guards/jwt-auth.guard.ts - ✗ CHƯA CÓ TỆP KIỂM THỬ

  • Guard xác thực JWT token
  • QUAN TRỌNG: Cần kiểm thử: token hợp lệ, token hết hạn, chữ ký không hợp lệ
  1. presentation/guards/local-auth.guard.ts - ✗ CHƯA CÓ TỆP KIỂM THỬ

    • Guard xác thực cục bộ
    • Cần kiểm thử: luồng xác thực, xác minh người dùng
  2. presentation/guards/google-oauth.guard.ts - ✗ CHƯA CÓ TỆP KIỂM THỬ

    • Guard OAuth cho Google
    • Cần kiểm thử: OAuth callback, truy xuất hồ sơ người dùng
  3. presentation/guards/roles.guard.ts - ✗ CHƯA CÓ TỆP KIỂM THỬ

    • Kiểm soát truy cập dựa trên vai trò
    • QUAN TRỌNG: Cần kiểm thử: quyền truy cập admin, quyền truy cập người dùng, truy cập bị từ chối

Decorator (2 tệp): 8. presentation/decorators/current-user.decorator.ts - ✗ CHƯA CÓ TỆP KIỂM THỬ

  • Trích xuất người dùng hiện tại từ yêu cầu
  • Cần kiểm thử: áp dụng decorator, trích xuất người dùng
  1. presentation/decorators/roles.decorator.ts - ✗ CHƯA CÓ TỆP KIỂM THỬ
    • Đánh dấu các route với các vai trò yêu cầu
    • Cần kiểm thử: thiết lập metadata decorator

DTO (6 tệp): 10. presentation/dto/login.dto.ts - ✗ CHƯA CÓ TỆP KIỂM THỬ 11. presentation/dto/register.dto.ts - ✗ CHƯA CÓ TỆP KIỂM THỬ 12. presentation/dto/refresh-token.dto.ts - ✗ CHƯA CÓ TỆP KIỂM THỬ 13. presentation/dto/verify-kyc.dto.ts - ✗ CHƯA CÓ TỆP KIỂM THỬ 14. presentation/dto/force-delete-user.dto.ts - ✗ CHƯA CÓ TỆP KIỂM THỬ 15. presentation/dto/request-deletion.dto.ts - ✗ CHƯA CÓ TỆP KIỂM THỬ

Định nghĩa module: 16. auth.module.ts - ✗ CHƯA CÓ TỆP KIỂM THỬ (cấu hình module NestJS)


XẾP HẠNG ƯU TIÊN CHO CÁC KIỂM THỬ MỚI

BẬC 1 - QUAN TRỌNG (Bảo mật tối quan trọng, phải kiểm thử trước):

  1. presentation/guards/jwt-auth.guard.ts - Bảo mật xác thực token
  2. presentation/guards/roles.guard.ts - Thực thi ủy quyền
  3. infrastructure/repositories/prisma-user.repository.ts - Truy cập dữ liệu người dùng
  4. infrastructure/repositories/prisma-refresh-token.repository.ts - Quản lý token

BẬC 2 - CAO (Strategy xác thực): 5. infrastructure/strategies/jwt.strategy.ts - Strategy JWT 6. infrastructure/strategies/local.strategy.ts - Strategy xác thực cục bộ 7. presentation/guards/local-auth.guard.ts - Guard xác thực cục bộ 8. presentation/guards/google-oauth.guard.ts - Guard OAuth

BẬC 3 - TRUNG BÌNH (Trình bày & DTO): 9. presentation/controllers/auth.controller.ts - Controller auth chính 10. presentation/controllers/oauth.controller.ts - Điểm cuối OAuth 11. presentation/controllers/user-data.controller.ts - Điểm cuối dữ liệu người dùng 12. presentation/decorators/current-user.decorator.ts - Trích xuất người dùng hiện tại 13. presentation/decorators/roles.decorator.ts - Đánh dấu vai trò 14. presentation/dto/login.dto.ts - Xác thực đầu vào đăng nhập 15. presentation/dto/register.dto.ts - Xác thực đầu vào đăng ký 16. presentation/dto/refresh-token.dto.ts - Xác thực làm mới token

BẬC 4 - THẤP (Cấu hình): 17. auth.module.ts - Cấu hình module



Vị trí: apps/api/src/modules/search/

Thống kê Module

  • Tổng số tệp nguồn: 22 (không tính các tệp index.ts)
  • Tổng số tệp kiểm thử: 10
  • Độ bao phủ tổng thể: 45% (10 trong 22 tệp có kiểm thử - CAO NHẤT trong ba module!)

Các tệp kiểm thử hiện có (tổng 10 tệp)

Kiểm thử tầng ứng dụng (4 tệp)

  • geo-search.handler.spec.ts → GeoSearchHandler
  • reindex-all.handler.spec.ts → ReindexAllHandler
  • search-properties.handler.spec.ts → SearchPropertiesHandler
  • sync-listing.handler.spec.ts → SyncListingHandler

Kiểm thử tầng hạ tầng (4 tệp)

  • listing-approved.handler.spec.ts → ListingApprovedEventHandler
  • listing-indexer.service.spec.ts → ListingIndexerService
  • resilient-search.repository.spec.ts → ResilientSearchRepository
  • typesense-search.repository.spec.ts → TypesenseSearchRepository

Kiểm thử tầng miền (1 tệp)

  • search-domain.spec.ts → Value object SearchFilter & GeoFilter

Kiểm thử tầng trình bày (1 tệp)

  • search.controller.spec.ts → SearchController

CÁC TỆP NGUỒN CHƯA ĐƯỢC KIỂM THỬ - ƯU TIÊN CAO

🔴 Tầng miền (3 tệp)

Repository (1 tệp - Giao diện abstract):

  1. domain/repositories/search.repository.ts - ✗ CHƯA CÓ KIỂM THỬ (chỉ là interface/hợp đồng)
    • Định nghĩa hợp đồng repository tìm kiếm
    • Không quan trọng để kiểm thử (giao diện abstract)

Value Object (2 tệp - Thiếu kiểm thử): 2. domain/value-objects/search-filter.vo.ts ⚠️ ĐÃ CÓ KIỂM THỬ - search-domain.spec.ts 3. domain/value-objects/geo-filter.vo.ts ⚠️ ĐÃ CÓ KIỂM THỬ - search-domain.spec.ts


🔴 Handler & Command ứng dụng (4 tệp)

Command (4 tệp - Tất cả đã kiểm thử):

  1. application/commands/reindex-all/reindex-all.command.ts ✓ Kiểm thử thông qua handler
  2. application/commands/reindex-all/reindex-all.handler.ts ✓ ĐÃ KIỂM THỬ
  3. application/commands/sync-listing/sync-listing.command.ts ✓ Kiểm thử thông qua handler
  4. application/commands/sync-listing/sync-listing.handler.ts ✓ ĐÃ KIỂM THỬ

Query (4 tệp - Tất cả đã kiểm thử): 5. application/queries/geo-search/geo-search.query.ts ✓ Kiểm thử thông qua handler 6. application/queries/geo-search/geo-search.handler.ts ✓ ĐÃ KIỂM THỬ 7. application/queries/search-properties/search-properties.query.ts ✓ Kiểm thử thông qua handler 8. application/queries/search-properties/search-properties.handler.ts ✓ ĐÃ KIỂM THỬ


🔴 Tầng hạ tầng - Dịch vụ & Repository (5 tệp)

Dịch vụ hạ tầng (3 tệp - Được kiểm thử một phần):

  1. infrastructure/services/listing-indexer.service.ts ⚠️ ĐÃ CÓ KIỂM THỬ - listing-indexer.service.spec.ts
  2. infrastructure/services/resilient-search.repository.ts ⚠️ ĐÃ CÓ KIỂM THỬ - resilient-search.repository.spec.ts
  3. infrastructure/services/typesense-search.repository.ts ⚠️ ĐÃ CÓ KIỂM THỬ - typesense-search.repository.spec.ts

Dịch vụ hạ tầng còn thiếu: 4. infrastructure/services/typesense-client.service.ts - ✗ CHƯA CÓ TỆP KIỂM THỬ

  • Wrapper trực tiếp của Typesense client
  • Cần kiểm thử: khởi tạo client, kết nối, xử lý lỗi
  1. infrastructure/services/postgres-search.repository.ts - ✗ CHƯA CÓ TỆP KIỂM THỬ
    • Triển khai tìm kiếm dự phòng PostgreSQL
    • Cần kiểm thử: xây dựng truy vấn SQL, logic dự phòng

🔴 Handler sự kiện hạ tầng (2 tệp)

Handler sự kiện (Thiếu kiểm thử):

  1. infrastructure/event-handlers/listing-approved.handler.ts ⚠️ ĐÃ CÓ KIỂM THỬ - listing-approved.handler.spec.ts
  2. infrastructure/event-handlers/listing-status-changed.handler.ts - ✗ CHƯA CÓ TỆP KIỂM THỬ
    • Xử lý các sự kiện thay đổi trạng thái tin đăng
    • Cần kiểm thử: xử lý sự kiện, cập nhật chỉ mục tìm kiếm

🔴 Tầng trình bày (3 tệp)

Controller (1 tệp - Đã kiểm thử!):

  1. presentation/controllers/search.controller.ts ⚠️ ĐÃ CÓ KIỂM THỬ - search.controller.spec.ts

DTO (2 tệp - Thiếu kiểm thử): 2. presentation/dto/geo-search.dto.ts - ✗ CHƯA CÓ TỆP KIỂM THỬ

  • Xác thực đầu vào tìm kiếm địa lý
  • Cần kiểm thử: xác thực tọa độ địa lý, xác thực bán kính
  1. presentation/dto/search-properties.dto.ts - ✗ CHƯA CÓ TỆP KIỂM THỬ
    • Xác thực đầu vào tìm kiếm bất động sản
    • Cần kiểm thử: xác thực bộ lọc, xác thực phân trang

Định nghĩa module: 4. search.module.ts - ✗ CHƯA CÓ TỆP KIỂM THỬ (cấu hình module NestJS)


XẾP HẠNG ƯU TIÊN CHO CÁC KIỂM THỬ MỚI

BẬC 1 - QUAN TRỌNG (Chức năng tìm kiếm cốt lõi):

  1. infrastructure/services/typesense-client.service.ts - Tích hợp Typesense
  2. infrastructure/services/postgres-search.repository.ts - Tìm kiếm dự phòng

BẬC 2 - CAO (Xử lý sự kiện): 3. infrastructure/event-handlers/listing-status-changed.handler.ts - Lập chỉ mục khi thay đổi trạng thái

BẬC 3 - TRUNG BÌNH (Trình bày & DTO): 4. presentation/dto/geo-search.dto.ts - Xác thực tìm kiếm địa lý 5. presentation/dto/search-properties.dto.ts - Xác thực tìm kiếm bất động sản

BẬC 4 - THẤP (Cấu hình): 6. search.module.ts - Cấu hình module



PHÂN TÍCH KHO HỔNG KIỂM THỬ TỔNG HỢP

Các tệp THIẾU kiểm thử quan trọng (Ưu tiên bảo mật & Logic nghiệp vụ)

Module AUTH - QUAN TRỌNG VỀ BẢO MẬT:

  1. ⚠️ presentation/guards/jwt-auth.guard.ts - PHẢI KIỂM THỬ (xác thực token)
  2. ⚠️ presentation/guards/roles.guard.ts - PHẢI KIỂM THỬ (ủy quyền)
  3. ⚠️ infrastructure/repositories/prisma-user.repository.ts - PHẢI KIỂM THỬ (truy cập dữ liệu)
  4. ⚠️ infrastructure/strategies/jwt.strategy.ts - PHẢI KIỂM THỬ (xác thực)

Module LISTINGS - QUAN TRỌNG VỀ LOGIC NGHIỆP VỤ:

  1. ⚠️ infrastructure/services/prisma-duplicate-detector.ts - Phát hiện trùng lặp
  2. ⚠️ infrastructure/services/prisma-price-validator.ts - Xác thực giá
  3. ⚠️ infrastructure/repositories/prisma-listing.repository.ts - Truy cập dữ liệu tin đăng
  4. ⚠️ domain/services/moderation.service.ts - Logic kiểm duyệt

Module SEARCH - QUAN TRỌNG VỀ TÍCH HỢP:

  1. ⚠️ infrastructure/services/typesense-client.service.ts - Tích hợp công cụ tìm kiếm
  2. ⚠️ infrastructure/services/postgres-search.repository.ts - Tìm kiếm dự phòng

Tóm tắt độ bao phủ kiểm thử theo tầng

Tầng Module Tệp Kiểm thử Độ bao phủ
Domain/Entities Listings 3 3 100% ✓
Domain/Entities Auth 1 1 100% ✓
Domain/Value Objects Listings 3 3 100% ✓
Domain/Value Objects Auth 3 3 100% ✓
Domain/Value Objects Search 2 2 100% ✓
Domain/Events Listings 4 1 25%
Domain/Events Auth 4 1 25%
Domain/Services Listings 3 2 67%
Domain/Repositories Listings 3 0 0%
Domain/Repositories Auth 2 0 0%
Domain/Repositories Search 1 0 0%
Application/Handlers Listings 8 8 100% ✓
Application/Handlers Auth 12 12 100% ✓
Application/Handlers Search 8 8 100% ✓
Infrastructure/Repositories Listings 3 0 0%
Infrastructure/Repositories Auth 2 0 0%
Infrastructure/Services Listings 3 1 33%
Infrastructure/Services Auth 2 2 100% ✓
Infrastructure/Services Search 5 3 60%
Infrastructure/Strategies Auth 4 2 50%
Infrastructure/Event Handlers Search 2 1 50%
Presentation/Controllers Listings 1 0 0%
Presentation/Controllers Auth 3 0 0%
Presentation/Controllers Search 1 1 100% ✓
Presentation/Guards Auth 4 0 0%
Presentation/Decorators Auth 2 0 0%
Presentation/DTOs Tất cả 17 0 0%

KHUYẾN NGHỊ

Hành động ngay lập tức (Tuần 1)

  1. Tạo 5 kiểm thử quan trọng cho module AUTH:

    • presentation/guards/jwt-auth.guard.spec.ts
    • presentation/guards/roles.guard.spec.ts
    • infrastructure/repositories/prisma-user.repository.spec.ts
    • infrastructure/strategies/jwt.strategy.spec.ts
    • infrastructure/strategies/local.strategy.spec.ts
  2. Tạo 4 kiểm thử quan trọng cho module LISTINGS:

    • infrastructure/repositories/prisma-listing.repository.spec.ts
    • infrastructure/services/prisma-duplicate-detector.spec.ts
    • infrastructure/services/prisma-price-validator.spec.ts
    • domain/services/moderation.service.spec.ts

Ngắn hạn (Tuần 2-3)

  1. Kiểm thử repository hạ tầng:

    • Tất cả các triển khai Prisma repository
    • Các triển khai search repository
  2. Kiểm thử tích hợp/sự kiện:

    • Kiểm thử event handler cho tất cả sự kiện miền
    • Xác minh việc phát sinh sự kiện
  3. Kiểm thử tầng trình bày:

    • Tất cả các controller
    • Tất cả các guard và decorator
    • Kiểm thử xác thực DTO

Trung hạn (Tuần 4 trở đi)

  1. Kiểm thử đầu cuối đến đầu cuối:
    • Kiểm thử luồng người dùng đầy đủ (đăng ký → xác thực → truy cập dữ liệu)
    • Kiểm thử vòng đời tin đăng (tạo → kiểm duyệt → xuất bản)
    • Kiểm thử tính năng tìm kiếm (lập chỉ mục → truy xuất)

Tài liệu tham khảo nhanh về tệp kiểm thử

Tệp kiểm thử Listings (tổng 13 tệp)

application/__tests__/
  ├── create-listing.handler.spec.ts
  ├── get-listing.handler.spec.ts
  ├── get-pending-moderation.handler.spec.ts
  ├── moderate-listing.handler.spec.ts
  ├── price-validator.spec.ts
  ├── search-listings.handler.spec.ts
  ├── update-listing-status.handler.spec.ts
  └── upload-media.handler.spec.ts

domain/__tests__/
  ├── duplicate-detector.spec.ts
  ├── listing-events.spec.ts
  ├── listing.entity.spec.ts
  ├── property.entity.spec.ts
  └── value-objects.spec.ts

Tệp kiểm thử Auth (tổng 21 tệp)

application/__tests__/ (12 tệp)
  ├── cancel-user-deletion.handler.spec.ts
  ├── export-user-data.handler.spec.ts
  ├── force-delete-user.handler.spec.ts
  ├── get-agent-by-user-id.handler.spec.ts
  ├── get-profile.handler.spec.ts
  ├── login-user.handler.spec.ts
  ├── process-scheduled-deletions.handler.spec.ts
  ├── refresh-token.handler.spec.ts
  ├── register-user.handler.spec.ts
  ├── request-user-deletion.handler.spec.ts
  └── verify-kyc.handler.spec.ts

infrastructure/__tests__/ (4 tệp)
  ├── google-oauth.strategy.spec.ts
  ├── oauth.service.spec.ts
  ├── token.service.spec.ts
  └── zalo-oauth.strategy.spec.ts

domain/__tests__/ (5 tệp)
  ├── auth-events.spec.ts
  ├── email.vo.spec.ts
  ├── hashed-password.vo.spec.ts
  ├── phone.vo.spec.ts
  └── user.entity.spec.ts

__tests__/
  └── auth.integration.spec.ts

Tệp kiểm thử Search (tổng 10 tệp)

application/__tests__/ (4 tệp)
  ├── geo-search.handler.spec.ts
  ├── reindex-all.handler.spec.ts
  ├── search-properties.handler.spec.ts
  └── sync-listing.handler.spec.ts

infrastructure/__tests__/ (4 tệp)
  ├── listing-approved.handler.spec.ts
  ├── listing-indexer.service.spec.ts
  ├── resilient-search.repository.spec.ts
  └── typesense-search.repository.spec.ts

domain/__tests__/
  └── search-domain.spec.ts

presentation/__tests__/
  └── search.controller.spec.ts

Kết luận

Monorepo GoodGo Platform AI có độ bao phủ kiểm thử 37% trên ba module quan trọng được kiểm tra, với các khoảng trống đáng kể tại:

  • Guard và strategy quan trọng về bảo mật (AUTH)
  • Tầng truy cập dữ liệu hạ tầng (tất cả module)
  • Controller và DTO tầng trình bày (tất cả module)
  • Mô hình sự kiện miền (LISTINGS & AUTH)

Module Search thể hiện độ bao phủ kiểm thử mạnh nhất ở mức 45%, với hầu hết các handler và dịch vụ đã được kiểm thử. Module Listings và Auth cần được chú ý ngay đến các thành phần bảo mật và logic nghiệp vụ được xác định trong khuyến nghị Bậc 1.