feat(t245): use ERP images as procurement references

This commit is contained in:
QiuSW
2026-07-29 17:29:20 +08:00
parent a20590b4b7
commit 15074692a3
22 changed files with 1057 additions and 117 deletions
@@ -766,7 +766,11 @@ func TestAdminProcurementAPIProducesImmutablePendingTask(t *testing.T) {
"",
)
if createRequest.Code != http.StatusCreated ||
!strings.Contains(createRequest.Body.String(), `"status":"NEEDS_IMAGE"`) {
!strings.Contains(createRequest.Body.String(), `"status":"READY"`) ||
!strings.Contains(
createRequest.Body.String(),
`"reference_origin":"ERP_FREIGHT_IMAGE"`,
) {
t.Fatalf(
"create request status/body = %d / %s",
createRequest.Code,
@@ -806,7 +810,11 @@ func TestAdminProcurementAPIProducesImmutablePendingTask(t *testing.T) {
"",
)
if bind.Code != http.StatusOK ||
!strings.Contains(bind.Body.String(), `"status":"READY"`) {
!strings.Contains(bind.Body.String(), `"status":"READY"`) ||
!strings.Contains(
bind.Body.String(),
`"reference_origin":"MANUAL_UPLOAD"`,
) {
t.Fatalf("bind status/body = %d / %s", bind.Code, bind.Body)
}
deleteWithReference := performAdminRequest(
@@ -920,7 +928,7 @@ func TestAdminProcurementAPIProducesImmutablePendingTask(t *testing.T) {
}
func TestAdminFreightDeleteRemovesNeedsImageDraft(t *testing.T) {
fixture := newAdminIntegrationFixture(t)
fixture := newAdminIntegrationFixtureWithReferences(t, false)
createSync := performAdminRequest(
t,
fixture.router,
@@ -1123,6 +1131,9 @@ func TestAdminOrderAuthorizationIsIdempotentAndRevisioned(t *testing.T) {
if err != nil {
t.Fatalf("migration.New() error = %v", err)
}
if err := runner.Down(context.Background()); err != nil {
t.Fatalf("reference source migration down: %v", err)
}
if err := runner.Down(context.Background()); err != nil {
t.Fatalf("image migration down: %v", err)
}
@@ -1406,6 +1417,13 @@ type adminIntegrationFixture struct {
}
func newAdminIntegrationFixture(t *testing.T) *adminIntegrationFixture {
return newAdminIntegrationFixtureWithReferences(t, true)
}
func newAdminIntegrationFixtureWithReferences(
t *testing.T,
autoReferences bool,
) *adminIntegrationFixture {
t.Helper()
ctx := context.Background()
db, err := database.Open(ctx, filepath.Join(t.TempDir(), "admin.db"))
@@ -1482,10 +1500,18 @@ func newAdminIntegrationFixture(t *testing.T) *adminIntegrationFixture {
if err != nil {
t.Fatalf("usecase.NewFreightService() error = %v", err)
}
procurementOptions := make([]usecase.ProcurementServiceOption, 0, 1)
if autoReferences {
procurementOptions = append(
procurementOptions,
usecase.WithProcurementReferenceStore(files),
)
}
procurement, err := usecase.NewProcurementService(
repositories,
clock,
ids,
procurementOptions...,
)
if err != nil {
t.Fatalf("usecase.NewProcurementService() error = %v", err)
@@ -713,6 +713,9 @@ func TestDeviceExecutionResultsAreIdempotentAndAuditable(t *testing.T) {
if err != nil {
t.Fatalf("migration.New() after review error = %v", err)
}
if err := runner.Down(context.Background()); err != nil {
t.Fatalf("reference source migration down: %v", err)
}
if err := runner.Down(context.Background()); err != nil {
t.Fatalf("image migration down: %v", err)
}
@@ -742,8 +745,8 @@ func TestDeviceExecutionResultsAreIdempotentAndAuditable(t *testing.T) {
}
if applied, err := runner.Up(context.Background()); err != nil {
t.Fatalf("restore device command migration: %v", err)
} else if applied != 8 {
t.Fatalf("restored migrations = %d, want 8", applied)
} else if applied != 9 {
t.Fatalf("restored migrations = %d, want 9", applied)
}
completePayload := fmt.Sprintf(
@@ -1432,6 +1435,9 @@ func TestDeviceOrderCommandDeliveryAndAcknowledgementAreRecoverable(
if err != nil {
t.Fatalf("migration.New() error = %v", err)
}
if err := runner.Down(context.Background()); err != nil {
t.Fatalf("reference source migration down: %v", err)
}
if err := runner.Down(context.Background()); err != nil {
t.Fatalf("image migration down: %v", err)
}
@@ -160,6 +160,7 @@ func procurementRequestResponse(
"status": request.Status,
"blocking_code": request.BlockingCode,
"reference_asset_id": request.ReferenceAssetID,
"reference_origin": request.ReferenceOrigin,
"purchase_task_id": request.PurchaseTaskID,
"source_changed": request.SourceChanged,
"created_at": formatTime(request.CreatedAt),