0cce9ef1b5
- Introduced the `tender_submission` domain, including entity, repository, service, and handler implementations for managing tender submissions. - Added new routes for both admin and public access to tender submissions, allowing for listing, ensuring, and retrieving submissions by ID and tender. - Enhanced the tender approval service to synchronize submission workflows with approval changes, ensuring proper state management. - Implemented validation and response structures for tender submission operations, improving API consistency and usability. - Added unit tests for tender submission status transitions and workflow logic, ensuring robust functionality. This update enhances the tender management system by providing comprehensive support for tender submissions, improving overall workflow and user experience.
99 lines
2.9 KiB
Go
99 lines
2.9 KiB
Go
package tender_submission
|
|
|
|
import "testing"
|
|
|
|
func TestStageForStatus(t *testing.T) {
|
|
tests := []struct {
|
|
status SubmissionStatus
|
|
stage SubmissionStage
|
|
}{
|
|
{StatusOpportunity, StageOpportunity},
|
|
{StatusValidating, StageInProgress},
|
|
{StatusPartnerPending, StageInProgress},
|
|
{StatusApplying, StageInProgress},
|
|
{StatusSentWaiting, StageSubmitted},
|
|
{StatusRejected, StageSubmitted},
|
|
{StatusContract, StageSubmitted},
|
|
{StatusNotApplied, StageNotApplied},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
if got := StageForStatus(tt.status); got != tt.stage {
|
|
t.Fatalf("StageForStatus(%q) = %q, want %q", tt.status, got, tt.stage)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestAllowedNextStatuses(t *testing.T) {
|
|
tests := []struct {
|
|
current SubmissionStatus
|
|
next SubmissionStatus
|
|
allowed bool
|
|
}{
|
|
{StatusOpportunity, StatusValidating, true},
|
|
{StatusOpportunity, StatusNotApplied, true},
|
|
{StatusOpportunity, StatusApplying, false},
|
|
{StatusValidating, StatusPartnerPending, true},
|
|
{StatusValidating, StatusApplying, true},
|
|
{StatusValidating, StatusNotApplied, true},
|
|
{StatusPartnerPending, StatusApplying, true},
|
|
{StatusApplying, StatusSentWaiting, true},
|
|
{StatusSentWaiting, StatusContract, true},
|
|
{StatusSentWaiting, StatusRejected, true},
|
|
{StatusContract, StatusRejected, false},
|
|
{StatusNotApplied, StatusValidating, false},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
allowed := false
|
|
for _, candidate := range AllowedNextStatuses(tt.current) {
|
|
if candidate == tt.next {
|
|
allowed = true
|
|
break
|
|
}
|
|
}
|
|
if allowed != tt.allowed {
|
|
t.Fatalf("transition %q -> %q allowed=%v, want %v", tt.current, tt.next, allowed, tt.allowed)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestAddStatusChangeUpdatesStage(t *testing.T) {
|
|
submission := NewTenderSubmission("tender-1", "company-1", "customer-1")
|
|
submission.AddStatusChange(StatusValidating, "", "customer-1", "Accepted tender")
|
|
|
|
if submission.Status != StatusValidating {
|
|
t.Fatalf("status = %q, want %q", submission.Status, StatusValidating)
|
|
}
|
|
if submission.Stage != StageInProgress {
|
|
t.Fatalf("stage = %q, want %q", submission.Stage, StageInProgress)
|
|
}
|
|
if len(submission.History) != 2 {
|
|
t.Fatalf("history length = %d, want 2", len(submission.History))
|
|
}
|
|
}
|
|
|
|
func TestValidateStatusTransition(t *testing.T) {
|
|
service := &tenderSubmissionService{}
|
|
|
|
if err := service.validateStatusTransition(StatusOpportunity, StatusValidating); err != nil {
|
|
t.Fatalf("expected valid transition, got %v", err)
|
|
}
|
|
|
|
if err := service.validateStatusTransition(StatusContract, StatusRejected); err == nil {
|
|
t.Fatal("expected terminal status error")
|
|
}
|
|
|
|
err := service.validateStatusTransition(StatusOpportunity, StatusApplying)
|
|
if err == nil {
|
|
t.Fatal("expected invalid transition error")
|
|
}
|
|
transitionErr, ok := err.(*InvalidStatusTransitionError)
|
|
if !ok {
|
|
t.Fatalf("expected InvalidStatusTransitionError, got %T", err)
|
|
}
|
|
if transitionErr.CurrentStatus != string(StatusOpportunity) {
|
|
t.Fatalf("current status = %q", transitionErr.CurrentStatus)
|
|
}
|
|
}
|