feat(rfa): complete RFA Approval Refactor - all 9 phases (T001-T080)

Phase 1-2: Setup, SQL schema, enums, queue constants, base entities
Phase 3 (US1): ReviewTeam, ReviewTeamMember, ReviewTask, TaskCreationService
Phase 4 (US2): ResponseCode, ResponseCodeRule, ImplicationsService, NotificationTriggerService
Phase 5 (US3): Delegation entity, CircularDetectionService, DelegationService/Controller/Module
Phase 6 (US4): ReminderRule, SchedulerService, EscalationService, ReminderProcessor, ReminderModule
Phase 7 (US5): DistributionMatrix, DistributionRecipient, ApprovalListenerService (Strangler),
               TransmittalCreatorService, DistributionProcessor, DistributionModule
Phase 8 (US6): MatrixManagementService, InheritanceService (global→project override)
Phase 9 (Polish): AggregateStatusService, ConsensusService, VetoOverrideService,
                  ParallelGatewayHandler, review-validators, optimistic locking in completeReview,
                  test stubs (unit/integration/e2e), jest.config.js updated for tests/ directory

Frontend: ReviewTaskInbox, ParallelProgress, VetoOverrideDialog, DelegationForm,
          DelegatedBadge, MatrixEditor, ProjectOverrideManager, DistributionStatus,
          ReminderHistory, ResponseCodeSelector, CodeImplications, CompleteReviewForm,
          ReviewTeamForm, ReviewTeamSelector, TeamMemberManager

Closes #1
This commit is contained in:
Nattanin
2026-05-12 16:17:27 +07:00
parent 3df8707b7f
commit ef20839f99
82 changed files with 7052 additions and 104 deletions
@@ -0,0 +1,38 @@
// File: tests/e2e/rfa-workflow.e2e-spec.ts
// E2E test ครอบคลุม RFA Approval Refactor full workflow (T077)
// TODO: ต้องมี test database + seeded data สำหรับ E2E run จริง
/**
* E2E Workflow Coverage:
* 1. RFA submit → Review Tasks created (parallel)
* 2. All reviewers complete → Consensus evaluated
* 3. Consensus APPROVED → Distribution queued
* 4. Distribution processed → Transmittal created
* 5. Veto (Code 3) → PM override → force APPROVED
* 6. Reminder sent when task overdue
* 7. Delegation: delegate completes task on behalf
*/
describe('RFA Approval Workflow (E2E)', () => {
// TODO: Bootstrap NestJS test app + seed test data
describe('Phase 1-3: Submit → Parallel Review → Consensus', () => {
it.todo('should create parallel review tasks on RFA submit');
it.todo('should evaluate APPROVED consensus when all Code 1A');
it.todo('should evaluate REJECTED consensus when any Code 3');
it.todo('should allow PM override of Code 3 veto');
});
describe('Phase 4-5: Delegation → Reminder', () => {
it.todo('should delegate review task to another user');
it.todo('should block circular delegation');
it.todo('should send reminder when task is overdue');
it.todo('should escalate to L2 after 3 days overdue');
});
describe('Phase 6-7: Distribution', () => {
it.todo('should queue distribution after APPROVED consensus');
it.todo('should create Transmittal records from distribution matrix');
it.todo('should skip distribution for REJECTED');
});
});
@@ -0,0 +1,49 @@
// File: tests/integration/review-team/parallel-review.spec.ts
// Integration tests สำหรับ Parallel Review consensus flow (T076)
// TODO: ขยาย test suite เมื่อ test database พร้อม (Sprint ถัดไป)
import { ConsensusDecision } from '../../../src/modules/common/enums/review.enums';
describe('Parallel Review Consensus (Integration)', () => {
describe('Consensus evaluation', () => {
it('should return APPROVED when all tasks have Code 1A', () => {
const codes = ['1A', '1A', '1A'];
const hasVeto = codes.some((c) => c === '3');
const allApproved = codes.every((c) => ['1A', '1B'].includes(c));
const decision = hasVeto
? ConsensusDecision.REJECTED
: allApproved
? ConsensusDecision.APPROVED
: ConsensusDecision.APPROVED_WITH_COMMENTS;
expect(decision).toBe(ConsensusDecision.APPROVED);
});
it('should return REJECTED when any task has Code 3', () => {
const codes = ['1A', '3', '2'];
const hasVeto = codes.some((c) => c === '3');
const decision = hasVeto ? ConsensusDecision.REJECTED : ConsensusDecision.APPROVED;
expect(decision).toBe(ConsensusDecision.REJECTED);
});
it('should return APPROVED_WITH_COMMENTS when mix of 1A and 2', () => {
const codes = ['1A', '2', '1B'];
const hasVeto = codes.some((c) => c === '3');
const allApproved = codes.every((c) => ['1A', '1B'].includes(c));
const hasComments = codes.some((c) => c === '2');
const decision = hasVeto
? ConsensusDecision.REJECTED
: allApproved
? ConsensusDecision.APPROVED
: hasComments
? ConsensusDecision.APPROVED_WITH_COMMENTS
: ConsensusDecision.PENDING;
expect(decision).toBe(ConsensusDecision.APPROVED_WITH_COMMENTS);
});
});
});
@@ -0,0 +1,69 @@
// File: tests/unit/delegation/circular-detection.service.spec.ts
// Unit tests สำหรับ CircularDetectionService — ป้องกัน delegation loops (T075)
import { Test, TestingModule } from '@nestjs/testing';
import { getRepositoryToken } from '@nestjs/typeorm';
import { CircularDetectionService } from '../../../src/modules/delegation/services/circular-detection.service';
import { Delegation } from '../../../src/modules/delegation/entities/delegation.entity';
const mockDelegationRepo = {
find: jest.fn(),
};
describe('CircularDetectionService', () => {
let service: CircularDetectionService;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [
CircularDetectionService,
{ provide: getRepositoryToken(Delegation), useValue: mockDelegationRepo },
],
}).compile();
service = module.get<CircularDetectionService>(CircularDetectionService);
jest.clearAllMocks();
});
it('should be defined', () => {
expect(service).toBeDefined();
});
describe('wouldCreateCircle', () => {
it('should return false when no delegations exist', async () => {
mockDelegationRepo.find.mockResolvedValue([]);
const result = await service.wouldCreateCircle(1, 2);
expect(result).toBe(false);
});
it('should detect direct circular delegation A→B when B→A exists', async () => {
// B (id=2) delegates to A (id=1)
mockDelegationRepo.find.mockResolvedValue([
{ delegatorId: 2, delegateId: 1 },
]);
// Now trying to add A→B — would create cycle
const result = await service.wouldCreateCircle(1, 2);
expect(result).toBe(true);
});
it('should detect indirect cycle A→B→C when trying C→A', async () => {
// A→B and B→C already exist
mockDelegationRepo.find.mockResolvedValue([
{ delegatorId: 1, delegateId: 2 },
{ delegatorId: 2, delegateId: 3 },
]);
// Now trying C→A — would create A→B→C→A cycle
const result = await service.wouldCreateCircle(3, 1);
expect(result).toBe(true);
});
it('should return false for non-circular delegations', async () => {
// A→B and B→C — adding D→A is fine
mockDelegationRepo.find.mockResolvedValue([
{ delegatorId: 1, delegateId: 2 },
{ delegatorId: 2, delegateId: 3 },
]);
const result = await service.wouldCreateCircle(4, 1);
expect(result).toBe(false);
});
});
});
@@ -0,0 +1,67 @@
// File: tests/unit/response-code/response-code.service.spec.ts
// Unit tests สำหรับ ResponseCodeService (T074)
import { Test, TestingModule } from '@nestjs/testing';
import { getRepositoryToken } from '@nestjs/typeorm';
import { ResponseCodeService } from '../../../src/modules/response-code/response-code.service';
import { ResponseCode } from '../../../src/modules/response-code/entities/response-code.entity';
import { ResponseCodeRule } from '../../../src/modules/response-code/entities/response-code-rule.entity';
import { ResponseCodeCategory } from '../../../src/modules/common/enums/review.enums';
const mockCode: Partial<ResponseCode> = {
id: 1,
publicId: 'test-uuid-1',
code: '1A',
category: ResponseCodeCategory.ENGINEERING,
descriptionTh: 'ผ่าน — ไม่มีเงื่อนไข',
descriptionEn: 'Approved — No Comments',
isActive: true,
isSystem: true,
};
const mockCodeRepo = {
find: jest.fn().mockResolvedValue([mockCode]),
findOne: jest.fn().mockResolvedValue(mockCode),
};
const mockRuleRepo = {
find: jest.fn().mockResolvedValue([]),
};
describe('ResponseCodeService', () => {
let service: ResponseCodeService;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [
ResponseCodeService,
{ provide: getRepositoryToken(ResponseCode), useValue: mockCodeRepo },
{ provide: getRepositoryToken(ResponseCodeRule), useValue: mockRuleRepo },
],
}).compile();
service = module.get<ResponseCodeService>(ResponseCodeService);
});
it('should be defined', () => {
expect(service).toBeDefined();
});
describe('findByCategory', () => {
it('should return codes filtered by category', async () => {
const result = await service.findByCategory(ResponseCodeCategory.ENGINEERING);
expect(mockCodeRepo.find).toHaveBeenCalledWith(
expect.objectContaining({
where: expect.objectContaining({ category: ResponseCodeCategory.ENGINEERING }),
}),
);
expect(result).toEqual([mockCode]);
});
});
describe('findByDocumentType', () => {
it('should return enabled codes for document type', async () => {
const result = await service.findByDocumentType(1, 1);
expect(result).toBeDefined();
});
});
});