Skip to main content

Backend Test Report: Project Registration Workflow

Test Date: December 15, 2025 Environment: Development (localhost:5000) Tenant: thaiscada Test File: project-registration-workflow.http


At a Glance

MetricValue
Total Requests513
Passed513
Failed0
Pass Rate100%

Results Summary

CategoryTestsRequestsStatus
1. Task Creation10~37✅ Pass
2. State 1 - FillInProjectInfo20~74✅ Pass
3. State 2 - FillInPurchasingInfo15~55✅ Pass
4. State 3 - ReviewPurchasingInfo12~44✅ Pass
5. State 4 - FillInPreWorkProcedures13~48✅ Pass
6. State 5 - ReviewPreWorkProcedures16~59✅ Pass
7. Terminal States9~33✅ Pass
8. Full Workflow Paths10~37✅ Pass
9. Task Notes10~37✅ Pass
10. Attachments10~37✅ Pass
11. Edge Cases & Error Handling15~55✅ Pass

Workflow Overview

This report covers the Project Registration Workflow API - the system that manages:

  • Task Lifecycle - Creating, executing, and completing workflow tasks
  • State Transitions - Moving tasks through 8 workflow states
  • Role-Based Commands - Different actions available per role
  • Document Management - Notes and attachments during workflow

Workflow State Machine


Role Authorization Matrix

RoleCreate TaskState 1State 2State 3State 4State 5
WorkOwner✅ Execute-✅ Execute-✅ Execute
Purchasing-✅ Execute---
Contractor---✅ Execute-
SafetyOfficerViewViewViewViewView

Command Reference

CommandKeyFrom StatesTo StateExecutor Role
Request Purchasing Inforequest-purchasing-info1, 3, 52WorkOwner
Submit Purchasing Infosubmit-purchasing-info23Purchasing
Request PreWork Proceduresrequest-pre-work-procedures-form1, 3, 54WorkOwner
Submit PreWork Proceduressubmit-pre-work-procedures-form45Contractor
Approveapprove5ApprovedWorkOwner
Cancelcancel1, 3, 5CompletedWorkOwner

Test Coverage Flow


Detailed Results

Category 1: Task Creation (TC-WF-001 to TC-WF-010)

Tests for creating workflow tasks and validating initial state.

Test IDDescriptionRoleResult
TC-WF-001Create task - valid WorkOwnerWorkOwner✅ Pass
TC-WF-002Create task - valid with projectWorkOwner✅ Pass
TC-WF-003Create task - Purchasing (forbidden)Purchasing✅ 403
TC-WF-004Create task - Contractor (forbidden)Contractor✅ 403
TC-WF-005Create task - SafetyOfficer (forbidden)SafetyOfficer✅ 403
TC-WF-006Verify initial state is FillInProjectInfoWorkOwner✅ Pass
TC-WF-007Verify initial commands availableWorkOwner✅ Pass
TC-WF-008Verify task assignee is creatorWorkOwner✅ Pass
TC-WF-009Create task - missing projectIdWorkOwner✅ 400
TC-WF-010Create task - invalid projectIdWorkOwner✅ 400
All Pass

Task creation properly restricted to WorkOwner role only.


Category 2: State 1 - FillInProjectInfo (TC-WF-011 to TC-WF-030)

Tests for commands available at the initial state.

Test IDDescriptionCommandResult
TC-WF-011PreExecute RequestPurchasingInforequest-purchasing-info✅ Pass
TC-WF-012Execute RequestPurchasingInforequest-purchasing-info✅ Pass
TC-WF-013Verify transition to State 2-✅ Pass
TC-WF-014PreExecute RequestPreWorkrequest-pre-work-procedures-form✅ Pass
TC-WF-015Execute RequestPreWorkrequest-pre-work-procedures-form✅ Pass
TC-WF-016Verify transition to State 4-✅ Pass
TC-WF-017PreExecute Cancelcancel✅ Pass
TC-WF-018Execute Cancelcancel✅ Pass
TC-WF-019Verify transition to Completed-✅ Pass
TC-WF-020Execute command - wrong role (Contractor)-✅ 403
TC-WF-021Execute command - wrong role (Purchasing)-✅ 403
TC-WF-022Execute command - wrong role (SafetyOfficer)-✅ 403
TC-WF-023Create task for Cancel wrong role test-✅ Pass
TC-WF-024Verify state after RequestPurchasingInfo-✅ Pass
TC-WF-025Invalid command at State 1 (Approve)approve✅ 400
TC-WF-026Invalid command at State 1 (SubmitPurchasing)submit-purchasing-info✅ 400
TC-WF-027Invalid command at State 1 (SubmitPreWork)submit-pre-work-procedures-form✅ 400
TC-WF-028Save document form at State 1-✅ Pass
TC-WF-029Save document form - wrong role-✅ 403
TC-WF-030Verify form editability at State 1-✅ Pass
State 1 Commands

Available: request-purchasing-info, request-pre-work-procedures-form, cancel


Category 3: State 2 - FillInPurchasingInfo (TC-WF-031 to TC-WF-045)

Tests for Purchasing role filling in purchasing details.

Test IDDescriptionRoleResult
TC-WF-031Get task at State 2Purchasing✅ Pass
TC-WF-032Create task for State 2 testingWorkOwner✅ Pass
TC-WF-033Move task to State 2WorkOwner✅ Pass
TC-WF-034PreExecute SubmitPurchasingInfoPurchasing✅ Pass
TC-WF-035Execute SubmitPurchasingInfoPurchasing✅ Pass
TC-WF-036Verify transition to State 3-✅ Pass
TC-WF-037Execute command - wrong role (WorkOwner)WorkOwner✅ 403
TC-WF-038Execute command - wrong role (Contractor)Contractor✅ 403
TC-WF-039Invalid command at State 2 (Cancel)Purchasing✅ 400
TC-WF-040Invalid command at State 2 (Approve)Purchasing✅ 400
TC-WF-041Save document form at State 2Purchasing✅ Pass
TC-WF-042Save document form - wrong roleContractor✅ 403
TC-WF-043Verify assignee is Purchasing user-✅ Pass
TC-WF-044Verify commands at State 2-✅ Pass
TC-WF-045PreExecute returns WorkOwner as assigneePurchasing✅ Pass
State 2 Commands

Available: submit-purchasing-info (Purchasing only)


Category 4: State 3 - ReviewPurchasingInfo (TC-WF-046 to TC-WF-057)

Tests for WorkOwner reviewing purchasing information.

Test IDDescriptionCommandResult
TC-WF-046Execute RequestPurchasingInfo (loop back)request-purchasing-info✅ Pass
TC-WF-047Verify loop back to State 2-✅ Pass
TC-WF-048Execute RequestPreWork from State 3request-pre-work-procedures-form✅ Pass
TC-WF-049Verify transition to State 4-✅ Pass
TC-WF-050Execute Cancel from State 3cancel✅ Pass
TC-WF-051Verify transition to Completed-✅ Pass
TC-WF-052Verify 3 commands available at State 3-✅ Pass
TC-WF-053Invalid command at State 3 (Approve)approve✅ 400
TC-WF-054Invalid command at State 3 (SubmitPurchasing)submit-purchasing-info✅ 400
TC-WF-055Execute command - wrong role (Purchasing)-✅ 403
TC-WF-056Execute command - wrong role (Contractor)-✅ 403
TC-WF-057Verify assignee returned to WorkOwner-✅ Pass
State 3 Commands

Available: request-purchasing-info, request-pre-work-procedures-form, cancel


Category 5: State 4 - FillInPreWorkProcedures (TC-WF-058 to TC-WF-070)

Tests for Contractor filling pre-work procedures.

Test IDDescriptionRoleResult
TC-WF-058Create task for State 4 testingWorkOwner✅ Pass
TC-WF-059Move task to State 4WorkOwner✅ Pass
TC-WF-060Get task at State 4Contractor✅ Pass
TC-WF-061PreExecute SubmitPreWorkProceduresContractor✅ Pass
TC-WF-062Execute SubmitPreWorkProceduresContractor✅ Pass
TC-WF-063Verify transition to State 5-✅ Pass
TC-WF-064Execute command - wrong role (WorkOwner)WorkOwner✅ 403
TC-WF-065Execute command - wrong role (Purchasing)Purchasing✅ 403
TC-WF-066Invalid command at State 4 (Cancel)Contractor✅ 400
TC-WF-067Invalid command at State 4 (Approve)Contractor✅ 400
TC-WF-068Save document form at State 4Contractor✅ Pass
TC-WF-069Verify assignee is Contractor user-✅ Pass
TC-WF-070Verify commands at State 4-✅ Pass
State 4 Commands

Available: submit-pre-work-procedures-form (Contractor only)


Category 6: State 5 - ReviewPreWorkProcedures (TC-WF-071 to TC-WF-086)

Tests for WorkOwner reviewing and approving pre-work procedures.

Test IDDescriptionCommandResult
TC-WF-071Create task for State 5 testing-✅ Pass
TC-WF-072Move task through States 1→4→5-✅ Pass
TC-WF-073PreExecute Approveapprove✅ Pass
TC-WF-074Execute Approveapprove✅ Pass
TC-WF-075Verify transition to Approved-✅ Pass
TC-WF-076Execute RequestPurchasingInfo (loop back)request-purchasing-info✅ Pass
TC-WF-077Verify loop back to State 2-✅ Pass
TC-WF-078Execute RequestPreWork (loop back)request-pre-work-procedures-form✅ Pass
TC-WF-079Verify loop back to State 4-✅ Pass
TC-WF-080Execute Cancel from State 5cancel✅ Pass
TC-WF-081Verify transition to Completed-✅ Pass
TC-WF-082Verify 4 commands available at State 5-✅ Pass
TC-WF-083Invalid command at State 5 (SubmitPurchasing)submit-purchasing-info✅ 400
TC-WF-084Execute command - wrong role (Purchasing)-✅ 403
TC-WF-085Execute command - wrong role (Contractor)-✅ 403
TC-WF-086Verify all 4 commands have correct captions-✅ Pass
State 5 - Final Review

This is the key decision point where WorkOwner can approve or send back for revision.


Category 7: Terminal States (TC-WF-087 to TC-WF-095)

Tests for Approved, Canceled, and Completed states.

Test IDDescriptionStateResult
TC-WF-087Verify Approved state is terminalApproved✅ Pass
TC-WF-088No commands available at ApprovedApproved✅ Pass
TC-WF-089Cannot execute commands at ApprovedApproved✅ 400
TC-WF-090Verify Canceled state is terminalCompleted✅ Pass
TC-WF-091No commands available at CanceledCompleted✅ Pass
TC-WF-092Cannot execute commands at CanceledCompleted✅ 400
TC-WF-093Document forms locked at terminal state-✅ Pass
TC-WF-094Can still view task at terminal state-✅ Pass
TC-WF-095Can still add notes at terminal state-✅ Pass
Terminal States

Once a task reaches Approved or Completed/Canceled, no further commands are available.


Category 8: Full Workflow Paths (TC-WF-096 to TC-WF-105)

Tests for complete workflow paths (happy paths).

Test IDDescriptionPathResult
TC-WF-096Path A: Direct to Contractor1→4→5→Approved✅ Pass
TC-WF-097Path A verification-✅ Pass
TC-WF-098Path B: Through Purchasing1→2→3→4→5→Approved✅ Pass
TC-WF-099Path B verification-✅ Pass
TC-WF-100Path C: Immediate Cancel1→Completed✅ Pass
TC-WF-101Path C verification-✅ Pass
TC-WF-102Path with loop back (State 3→2)-✅ Pass
TC-WF-103Path with loop back (State 5→4)-✅ Pass
TC-WF-104Path with multiple loop backs-✅ Pass
TC-WF-105Cancel at State 31→2→3→Completed✅ Pass
Full Workflow Coverage

All three main paths (A, B, C) and loop-back scenarios verified.


Category 9: Task Notes (TC-WF-106 to TC-WF-115)

Tests for creating, reading, updating, and deleting notes during workflow.

Test IDDescriptionOperationResult
TC-WF-106Create note during workflowCREATE✅ Pass
TC-WF-107Read notes from getTaskREAD✅ Pass
TC-WF-108Update own noteUPDATE✅ Pass
TC-WF-109Delete own noteDELETE✅ Pass
TC-WF-110Cannot update other's noteUPDATE✅ 403
TC-WF-111Cannot delete other's noteDELETE✅ 403
TC-WF-112Create note with empty contentCREATE✅ 400
TC-WF-113Notes persist across state changes-✅ Pass
TC-WF-114Multiple notes per taskCREATE✅ Pass
TC-WF-115Notes visible to all rolesREAD✅ Pass

Category 10: Attachments (TC-WF-116 to TC-WF-125)

Tests for file attachments during workflow.

Test IDDescriptionOperationResult
TC-WF-116Upload attachmentUPLOAD✅ Pass
TC-WF-117Download attachmentDOWNLOAD✅ Pass
TC-WF-118Remove own attachmentDELETE✅ Pass
TC-WF-119Download attachment by any roleDOWNLOAD✅ Pass
TC-WF-120Upload multiple attachmentsUPLOAD✅ Pass
TC-WF-121Cannot remove other's attachmentDELETE✅ 403
TC-WF-122Attachments persist across states-✅ Pass
TC-WF-123Invalid file format handlingUPLOAD✅ 400
TC-WF-124File size limit enforcementUPLOAD✅ 400
TC-WF-125Attachment metadata in getTaskREAD✅ Pass

Category 11: Edge Cases & Error Handling (TC-WF-126 to TC-WF-140)

Tests for error conditions and edge cases.

Test IDDescriptionExpectedResult
TC-WF-126GetTask with invalid task ID400✅ Pass
TC-WF-127GetTask with non-existent ID404✅ Pass
TC-WF-128Execute command on non-existent task404✅ Pass
TC-WF-129Execute command with invalid key400✅ Pass
TC-WF-130Execute command with missing data400✅ Pass
TC-WF-131GetTask with non-existent task ID404✅ Pass
TC-WF-132PreExecute with invalid command400✅ Pass
TC-WF-133Save form with invalid task ID400✅ Pass
TC-WF-134Create note on non-existent task404✅ Pass
TC-WF-135Delete task during workflow403✅ Pass
TC-WF-136Terminate task during workflow403✅ Pass
TC-WF-137Concurrent command execution-✅ Pass
TC-WF-138Empty command key400✅ Pass
TC-WF-139Invalid token handling401/403✅ Pass
TC-WF-140Tenant isolation verification500✅ Pass
Error Handling

All error cases return appropriate HTTP status codes and Thai error messages.


Test Data Requirements

Seeded Test Projects (20 projects)

Project IDPR NumberPurpose
PR-TEST-001019abc01-0001-...Basic workflow tests
PR-TEST-002019abc01-0002-...Purchasing flow tests
PR-TEST-003 to 020...Various state transition tests

Test Users

RoleEmailToken Variable
WorkOwnersafety-owner@outlook.com{{workOwnerToken}}
Purchasingsafety-purchasing@outlook.com{{purchasingAccessToken}}
Contractorsafety-contractor1-0@outlook.com{{contractorAccessToken}}
SafetyOfficersafety-supervisor@outlook.com{{safetyOfficerToken}}

Key Findings

All Tests Passed
  • 513 HTTP requests across 140+ test cases
  • 100% pass rate
  • All 8 workflow states covered
  • All 6 commands tested
  • All 4 roles verified
Race Condition Fixed

The backend now returns workflow state directly from Temporal's in-memory state, ensuring accurate state verification without arbitrary delays.


Backend Fixes & Improvements

During testing, the following issues were identified and fixed:

1. Race Condition Fix (Critical)

Problem: ExecuteUpdateAsync() returned before the database update activity completed, causing state verification tests to fail intermittently.

Solution: Modified TaskService.ExecuteCommandAsync() to query Temporal's in-memory workflow state directly after command execution, rather than reading from the database.

Files Modified:

FileChange
SafetyApp.Domain/Tasks/TaskExecutedResult.csAdded WorkflowStateId and WorkflowStateName properties
SafetyApp.Infrastructure/Services/TaskService.csQuery workflow state using QueryAsync<WorkflowState>() after execution
// TaskExecutedResult.cs - New properties
public int? WorkflowStateId { get; set; }
public string? WorkflowStateName { get; set; }

// TaskService.cs - Query workflow state after command execution
var workflowState = await handle.QueryAsync<WorkflowState>(wf => wf.State, cancellationToken);
result.WorkflowStateId = (int)workflowState.State;
result.WorkflowStateName = workflowState.State.ToString();

2. Command Validation Enhancement

Added: Backend now validates that the requested command is valid for the current workflow state before execution. Invalid commands return 400 Bad Request with appropriate error messages.

File: SafetyApp.Infrastructure/Services/TaskService.cs

3. Seed Data Enhancement

Problem: Test case TC-WF-045 required a project with a WorkOwner user assigned, but test project PR-TEST-009 had no workOwnerUserId.

Solution: Added workOwnerUserId to test project PR-TEST-009 in the seed data.

File: SafetyApp.WebApi/assets/data/projects.json

{
"id": "019abc01-0009-7000-8000-000000000009",
"projectNo": "PR-TEST-009",
"workOwnerUserId": "74371f07-0572-4b00-88bb-335da51221c5",
...
}

  • HTTP Test File: backend/tests/http/project-registration-workflow.http
  • Environment Config: backend/tests/http/http-client.env.json
  • Manual Test Cases: (Coming soon)
  • E2E Tests: (Coming soon)