docs/test(P19ERP2-5,P19ERP2-6): 收口采购ERP文档矩阵与回归
这个提交包含在:
@@ -6,6 +6,10 @@ MOCK_ERP_PORT="${MOCK_ERP_PORT:-$((3900 + RANDOM % 500))}"
|
||||
APP_PORT="${APP_PORT:-$((4300 + RANDOM % 500))}"
|
||||
BASE_URL="http://127.0.0.1:${APP_PORT}"
|
||||
DEVICE_FINGERPRINT="${DEVICE_FINGERPRINT:-regression-integrations}"
|
||||
EMPLOYEE_IDENTIFIER="${EMPLOYEE_IDENTIFIER:-employee@hyinda.com}"
|
||||
EMPLOYEE_PASSWORD="${EMPLOYEE_PASSWORD:-EmployeePassword1234}"
|
||||
MANAGER_IDENTIFIER="${MANAGER_IDENTIFIER:-manager@hyinda.com}"
|
||||
MANAGER_PASSWORD="${MANAGER_PASSWORD:-ManagerPassword1234}"
|
||||
FINANCE_MGR_IDENTIFIER="${FINANCE_MGR_IDENTIFIER:-finance_mgr@hyinda.com}"
|
||||
FINANCE_MGR_PASSWORD="${FINANCE_MGR_PASSWORD:-FinanceMgrPassword1234}"
|
||||
RUN_SUFFIX="$(date +%s)-$RANDOM"
|
||||
@@ -155,7 +159,11 @@ const server = http.createServer(async (req, res) => {
|
||||
|
||||
if (
|
||||
req.method === 'POST' &&
|
||||
(url.pathname === '/erp/journals/reimbursements/paid' || url.pathname === '/erp/reimbursements/paid')
|
||||
(
|
||||
url.pathname === '/erp/journals/export' ||
|
||||
url.pathname === '/erp/journals/reimbursements/paid' ||
|
||||
url.pathname === '/erp/reimbursements/paid'
|
||||
)
|
||||
) {
|
||||
const mode = url.searchParams.get('mode') || 'success';
|
||||
const chunks = [];
|
||||
@@ -176,6 +184,7 @@ const server = http.createServer(async (req, res) => {
|
||||
ok: true,
|
||||
scenario: 'timeout',
|
||||
externalId: `ERP-TIMEOUT-${Date.now()}`,
|
||||
externalCode: `ERP-TIMEOUT-${Date.now()}`,
|
||||
reimbursementId: parsedBody?.reimbursementId || parsedBody?.entityId || null,
|
||||
});
|
||||
}, 1500);
|
||||
@@ -200,14 +209,68 @@ const server = http.createServer(async (req, res) => {
|
||||
});
|
||||
}
|
||||
|
||||
const documentNo = parsedBody?.documentNo || parsedBody?.formNumber || parsedBody?.entityId || Date.now();
|
||||
return sendJson(res, 200, {
|
||||
ok: true,
|
||||
scenario: 'success',
|
||||
externalId: `ERP-${parsedBody?.documentNo || parsedBody?.formNumber || parsedBody?.entityId || Date.now()}`,
|
||||
externalId: `ERP-${documentNo}`,
|
||||
externalCode: `ERP-${documentNo}`,
|
||||
reimbursementId: parsedBody?.reimbursementId || parsedBody?.entityId || null,
|
||||
});
|
||||
}
|
||||
|
||||
if (req.method === 'POST' && url.pathname === '/erp/procurement/export') {
|
||||
const mode = url.searchParams.get('mode') || 'success';
|
||||
const chunks = [];
|
||||
for await (const chunk of req) {
|
||||
chunks.push(chunk);
|
||||
}
|
||||
|
||||
let parsedBody = null;
|
||||
try {
|
||||
parsedBody = JSON.parse(Buffer.concat(chunks).toString('utf8') || '{}');
|
||||
} catch {
|
||||
parsedBody = null;
|
||||
}
|
||||
|
||||
if (mode === 'timeout') {
|
||||
setTimeout(() => {
|
||||
sendJson(res, 200, {
|
||||
ok: true,
|
||||
externalPoId: `ERP-PO-${Date.now()}`,
|
||||
externalPoNo: `ERP-PO-${parsedBody?.poNo || Date.now()}`,
|
||||
});
|
||||
}, 1500);
|
||||
return;
|
||||
}
|
||||
|
||||
if (mode === 'client') {
|
||||
return sendJson(res, 422, {
|
||||
ok: false,
|
||||
code: 'invalid_payload',
|
||||
message: 'mock procurement client error',
|
||||
});
|
||||
}
|
||||
|
||||
if (mode === 'server') {
|
||||
return sendJson(res, 503, {
|
||||
ok: false,
|
||||
code: 'service_unavailable',
|
||||
message: 'mock procurement server error',
|
||||
});
|
||||
}
|
||||
|
||||
return sendJson(res, 200, {
|
||||
ok: true,
|
||||
externalId: `ERP-PROC-${parsedBody?.poNo || parsedBody?.entityId || Date.now()}`,
|
||||
externalCode: `ERP-PROC-${parsedBody?.poNo || parsedBody?.entityId || Date.now()}`,
|
||||
externalPoId: parsedBody?.poNo ? `ERP-PO-${parsedBody.poNo}` : null,
|
||||
externalPoNo: parsedBody?.poNo ? `ERP-PO-${parsedBody.poNo}` : null,
|
||||
externalContractId: parsedBody?.contractNo ? `ERP-CT-${parsedBody.contractNo}` : null,
|
||||
externalContractNo: parsedBody?.contractNo ? `ERP-CT-${parsedBody.contractNo}` : null,
|
||||
});
|
||||
}
|
||||
|
||||
sendJson(res, 404, { ok: false, message: 'not_found' });
|
||||
});
|
||||
|
||||
@@ -239,9 +302,11 @@ start_app_server() {
|
||||
ERP_SYNC_ENABLED=true \
|
||||
ERP_SYNC_PROVIDER=http \
|
||||
ERP_MASTER_DATA_ENDPOINT="http://127.0.0.1:$MOCK_ERP_PORT/erp/master-data/pull?mode=success" \
|
||||
ERP_JOURNAL_EXPORT_ENDPOINT="http://127.0.0.1:$MOCK_ERP_PORT/erp/journals/reimbursements/paid?mode=success" \
|
||||
ERP_JOURNAL_EXPORT_ENDPOINT="http://127.0.0.1:$MOCK_ERP_PORT/erp/journals/export?mode=success" \
|
||||
ERP_PROCUREMENT_EXPORT_ENDPOINT="http://127.0.0.1:$MOCK_ERP_PORT/erp/procurement/export?mode=success" \
|
||||
ERP_SYNC_ENDPOINT="http://127.0.0.1:$MOCK_ERP_PORT/erp/reimbursements/paid?mode=success" \
|
||||
ERP_SYNC_TIMEOUT_MS="$ERP_SYNC_TIMEOUT_MS" \
|
||||
ERP_PROCUREMENT_TIMEOUT_MS="$ERP_SYNC_TIMEOUT_MS" \
|
||||
ERP_MASTER_DATA_TIMEOUT_MS="$ERP_SYNC_TIMEOUT_MS" \
|
||||
ERP_SYNC_AUTH_TOKEN="" \
|
||||
node src/index.js >"$TMP_DIR/app.log" 2>&1 &
|
||||
@@ -259,16 +324,45 @@ start_app_server() {
|
||||
exit 1
|
||||
}
|
||||
|
||||
login_finance_mgr() {
|
||||
local login_body="$TMP_DIR/login.json"
|
||||
login_user() {
|
||||
local identifier="$1"
|
||||
local password="$2"
|
||||
local suffix="$3"
|
||||
local out_file="$TMP_DIR/login-${suffix}.json"
|
||||
local login_status
|
||||
login_status="$(curl -sS -o "$login_body" -w "%{http_code}" \
|
||||
-X POST "$BASE_URL/api/auth/login" \
|
||||
-H "content-type: application/json" \
|
||||
-H "x-device-fingerprint: ${DEVICE_FINGERPRINT}-finance" \
|
||||
-d "{\"identifier\":\"$FINANCE_MGR_IDENTIFIER\",\"password\":\"$FINANCE_MGR_PASSWORD\"}")"
|
||||
assert_status "$login_status" "200" "finance_mgr login"
|
||||
TOKEN="$(jq -er '.data.accessToken' "$login_body")"
|
||||
login_status="$(
|
||||
curl -sS -o "$out_file" -w "%{http_code}" \
|
||||
-X POST "$BASE_URL/api/auth/login" \
|
||||
-H "content-type: application/json" \
|
||||
-H "x-device-fingerprint: ${DEVICE_FINGERPRINT}-${suffix}" \
|
||||
-d "$(jq -nc --arg identifier "$identifier" --arg password "$password" '{identifier: $identifier, password: $password}')"
|
||||
)"
|
||||
assert_status "$login_status" "200" "login ${identifier}" "$out_file"
|
||||
jq -er '.data.accessToken' "$out_file"
|
||||
}
|
||||
|
||||
login_finance_mgr() {
|
||||
TOKEN="$(login_user "$FINANCE_MGR_IDENTIFIER" "$FINANCE_MGR_PASSWORD" finance)"
|
||||
}
|
||||
|
||||
api_json_auth() {
|
||||
local method="$1"
|
||||
local path="$2"
|
||||
local token="$3"
|
||||
local out_file="$4"
|
||||
local body="${5:-}"
|
||||
|
||||
if [[ -n "$body" ]]; then
|
||||
curl -sS -o "$out_file" -w "%{http_code}" \
|
||||
-X "$method" "$BASE_URL$path" \
|
||||
-H "authorization: Bearer $token" \
|
||||
-H "content-type: application/json" \
|
||||
-d "$body"
|
||||
else
|
||||
curl -sS -o "$out_file" -w "%{http_code}" \
|
||||
-X "$method" "$BASE_URL$path" \
|
||||
-H "authorization: Bearer $token"
|
||||
fi
|
||||
}
|
||||
|
||||
set_erp_flag() {
|
||||
@@ -460,6 +554,175 @@ const { createPrismaClient } = require('./src/prismaClient');
|
||||
NODE
|
||||
}
|
||||
|
||||
resolve_procurement_fixture_ids() {
|
||||
DATABASE_URL="$DATABASE_URL" node - <<'NODE'
|
||||
require('dotenv/config');
|
||||
const { createPrismaClient } = require('./src/prismaClient');
|
||||
const { resolveApplicableBudgetPoolByContext } = require('./src/services/budgetPool');
|
||||
|
||||
(async () => {
|
||||
const { prisma, pool } = createPrismaClient();
|
||||
await prisma.$connect();
|
||||
try {
|
||||
const employee = await prisma.employee.findUnique({
|
||||
where: { email: process.env.SEED_EMPLOYEE_EMAIL ?? '[email protected]' },
|
||||
select: { department_id: true, legal_entity_id: true },
|
||||
});
|
||||
const costCenter = await prisma.costCenter.findFirst({
|
||||
where: {
|
||||
enabled: true,
|
||||
archived_at: null,
|
||||
legal_entity_id: employee.legal_entity_id,
|
||||
},
|
||||
orderBy: { created_at: 'asc' },
|
||||
select: { id: true },
|
||||
});
|
||||
const supplier = await prisma.supplier.findFirst({
|
||||
where: {
|
||||
enabled: true,
|
||||
archived_at: null,
|
||||
OR: [{ legal_entity_id: employee.legal_entity_id }, { legal_entity_id: null }],
|
||||
},
|
||||
orderBy: { created_at: 'asc' },
|
||||
select: { id: true },
|
||||
});
|
||||
const documentCategory = await prisma.documentCategory.findFirst({
|
||||
where: {
|
||||
enabled: true,
|
||||
archived_at: null,
|
||||
entity_type: 'purchase_request',
|
||||
},
|
||||
orderBy: { created_at: 'asc' },
|
||||
select: { id: true },
|
||||
});
|
||||
const budgetPool = await resolveApplicableBudgetPoolByContext(prisma, {
|
||||
departmentId: employee.department_id,
|
||||
legalEntityId: employee.legal_entity_id,
|
||||
costCenterId: costCenter?.id ?? null,
|
||||
effectiveDate: new Date(),
|
||||
});
|
||||
|
||||
process.stdout.write(
|
||||
[
|
||||
employee.legal_entity_id,
|
||||
costCenter?.id ?? '',
|
||||
supplier?.id ?? '',
|
||||
documentCategory?.id ?? '',
|
||||
budgetPool?.id ?? '',
|
||||
].join('\n'),
|
||||
);
|
||||
} finally {
|
||||
await prisma.$disconnect();
|
||||
await pool.end();
|
||||
}
|
||||
})().catch((error) => {
|
||||
console.error(error);
|
||||
process.exit(1);
|
||||
});
|
||||
NODE
|
||||
}
|
||||
|
||||
query_outbox_by_key() {
|
||||
local event_type="$1"
|
||||
local dedupe_key="$2"
|
||||
DATABASE_URL="$DATABASE_URL" EVENT_TYPE="$event_type" DEDUPE_KEY="$dedupe_key" node <<'NODE'
|
||||
require('dotenv/config');
|
||||
const { createPrismaClient } = require('./src/prismaClient');
|
||||
|
||||
(async () => {
|
||||
const { prisma, pool } = createPrismaClient();
|
||||
await prisma.$connect();
|
||||
try {
|
||||
const row = await prisma.integrationOutbox.findUnique({
|
||||
where: {
|
||||
event_type_dedupe_key: {
|
||||
event_type: process.env.EVENT_TYPE,
|
||||
dedupe_key: process.env.DEDUPE_KEY,
|
||||
},
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
event_type: true,
|
||||
status: true,
|
||||
attempts: true,
|
||||
processed_at: true,
|
||||
next_retry_at: true,
|
||||
dead_letter_at: true,
|
||||
last_error: true,
|
||||
payload: true,
|
||||
},
|
||||
});
|
||||
process.stdout.write(JSON.stringify(row ? {
|
||||
id: row.id,
|
||||
eventType: row.event_type,
|
||||
status: row.status,
|
||||
attempts: row.attempts,
|
||||
processedAt: row.processed_at ? row.processed_at.toISOString() : null,
|
||||
nextRetryAt: row.next_retry_at ? row.next_retry_at.toISOString() : null,
|
||||
deadLetterAt: row.dead_letter_at ? row.dead_letter_at.toISOString() : null,
|
||||
lastError: row.last_error,
|
||||
payload: row.payload,
|
||||
} : null));
|
||||
} finally {
|
||||
await prisma.$disconnect();
|
||||
await pool.end();
|
||||
}
|
||||
})().catch((error) => {
|
||||
console.error(error);
|
||||
process.exit(1);
|
||||
});
|
||||
NODE
|
||||
}
|
||||
|
||||
query_binding_by_key() {
|
||||
local entity_type="$1"
|
||||
local local_id="$2"
|
||||
DATABASE_URL="$DATABASE_URL" ENTITY_TYPE="$entity_type" LOCAL_ID="$local_id" node <<'NODE'
|
||||
require('dotenv/config');
|
||||
const { createPrismaClient } = require('./src/prismaClient');
|
||||
|
||||
(async () => {
|
||||
const { prisma, pool } = createPrismaClient();
|
||||
await prisma.$connect();
|
||||
try {
|
||||
const row = await prisma.integrationBinding.findUnique({
|
||||
where: {
|
||||
provider_entity_type_local_id: {
|
||||
provider: 'erp',
|
||||
entity_type: process.env.ENTITY_TYPE,
|
||||
local_id: process.env.LOCAL_ID,
|
||||
},
|
||||
},
|
||||
select: {
|
||||
external_id: true,
|
||||
external_code: true,
|
||||
last_synced_at: true,
|
||||
},
|
||||
});
|
||||
process.stdout.write(JSON.stringify({
|
||||
externalId: row?.external_id ?? null,
|
||||
externalCode: row?.external_code ?? null,
|
||||
lastSyncedAt: row?.last_synced_at ? row.last_synced_at.toISOString() : null,
|
||||
}));
|
||||
} finally {
|
||||
await prisma.$disconnect();
|
||||
await pool.end();
|
||||
}
|
||||
})().catch((error) => {
|
||||
console.error(error);
|
||||
process.exit(1);
|
||||
});
|
||||
NODE
|
||||
}
|
||||
|
||||
assert_outbox_absent_by_key() {
|
||||
local event_type="$1"
|
||||
local dedupe_key="$2"
|
||||
local state_json
|
||||
state_json="$(query_outbox_by_key "$event_type" "$dedupe_key")"
|
||||
jq -e '. == null' <<<"$state_json" >/dev/null
|
||||
}
|
||||
|
||||
assert_master_data_seeded() {
|
||||
DATABASE_URL="$DATABASE_URL" LEGAL_ENTITY_CODE="$LEGAL_ENTITY_CODE" COST_CENTER_CODE="$COST_CENTER_CODE" SUPPLIER_CODE="$SUPPLIER_CODE" node <<'NODE'
|
||||
require('dotenv/config');
|
||||
@@ -497,16 +760,9 @@ NODE
|
||||
}
|
||||
|
||||
run_outbox_once() {
|
||||
local mode="$1"
|
||||
DATABASE_URL="$DATABASE_URL" \
|
||||
INTEGRATION_OUTBOX_BATCH_SIZE=500 \
|
||||
ERP_SYNC_ENABLED=true \
|
||||
ERP_SYNC_PROVIDER=http \
|
||||
ERP_JOURNAL_EXPORT_ENDPOINT="http://127.0.0.1:$MOCK_ERP_PORT/erp/journals/reimbursements/paid?mode=$mode" \
|
||||
ERP_SYNC_ENDPOINT="http://127.0.0.1:$MOCK_ERP_PORT/erp/reimbursements/paid?mode=$mode" \
|
||||
ERP_SYNC_TIMEOUT_MS="$ERP_SYNC_TIMEOUT_MS" \
|
||||
ERP_SYNC_AUTH_TOKEN="" \
|
||||
npm run --silent job:integration-outbox-once >"$TMP_DIR/outbox-once.log"
|
||||
local journal_mode="$1"
|
||||
local procurement_mode="${2:-$journal_mode}"
|
||||
DATABASE_URL="$DATABASE_URL" INTEGRATION_OUTBOX_BATCH_SIZE=500 ERP_SYNC_ENABLED=true ERP_SYNC_PROVIDER=http ERP_JOURNAL_EXPORT_ENDPOINT="http://127.0.0.1:$MOCK_ERP_PORT/erp/journals/export?mode=$journal_mode" ERP_PROCUREMENT_EXPORT_ENDPOINT="http://127.0.0.1:$MOCK_ERP_PORT/erp/procurement/export?mode=$procurement_mode" ERP_SYNC_ENDPOINT="http://127.0.0.1:$MOCK_ERP_PORT/erp/reimbursements/paid?mode=$journal_mode" ERP_SYNC_TIMEOUT_MS="$ERP_SYNC_TIMEOUT_MS" ERP_PROCUREMENT_TIMEOUT_MS="$ERP_SYNC_TIMEOUT_MS" ERP_SYNC_AUTH_TOKEN="" npm run --silent job:integration-outbox-once >"$TMP_DIR/outbox-once.log"
|
||||
}
|
||||
|
||||
assert_pull_mode() {
|
||||
@@ -553,6 +809,60 @@ api_post() {
|
||||
-d "$body"
|
||||
}
|
||||
|
||||
create_and_approve_purchase() {
|
||||
local employee_token="$1"
|
||||
local manager_token="$2"
|
||||
local title_suffix="$3"
|
||||
local tmp_prefix="$4"
|
||||
|
||||
local create_status
|
||||
create_status="$(api_json_auth POST "/api/purchase-requests" "$employee_token" "$TMP_DIR/${tmp_prefix}-create.json" '{}')"
|
||||
assert_status "$create_status" "200" "create purchase ${title_suffix}" "$TMP_DIR/${tmp_prefix}-create.json"
|
||||
local purchase_id
|
||||
purchase_id="$(jq -er '.data.purchaseRequest.id' "$TMP_DIR/${tmp_prefix}-create.json")"
|
||||
|
||||
local patch_body
|
||||
patch_body="$({
|
||||
jq -nc \
|
||||
--arg title "$title_suffix" \
|
||||
--arg le "$LEGAL_ENTITY_ID" \
|
||||
--arg cc "$COST_CENTER_ID" \
|
||||
--arg sp "$SUPPLIER_ID" \
|
||||
--arg dc "$DOCUMENT_CATEGORY_ID" \
|
||||
'{title:$title, legalEntityId:$le, costCenterId:$cc, supplierId:$sp, documentCategoryId:$dc, items:[{description:"Laptop", specification:"14 inch", quantity:"2.00", unitPrice:"440.00", isAssetCandidate:true}] }'
|
||||
})"
|
||||
local patch_status
|
||||
patch_status="$(api_json_auth PATCH "/api/purchase-requests/$purchase_id" "$employee_token" "$TMP_DIR/${tmp_prefix}-patch.json" "$patch_body")"
|
||||
assert_status "$patch_status" "200" "patch purchase ${title_suffix}" "$TMP_DIR/${tmp_prefix}-patch.json"
|
||||
|
||||
local submit_status
|
||||
submit_status="$(api_json_auth POST "/api/purchase-requests/$purchase_id/submit" "$employee_token" "$TMP_DIR/${tmp_prefix}-submit.json" '{}')"
|
||||
assert_status "$submit_status" "200" "submit purchase ${title_suffix}" "$TMP_DIR/${tmp_prefix}-submit.json"
|
||||
local task_id
|
||||
task_id="$(jq -er '.data.currentTaskId' "$TMP_DIR/${tmp_prefix}-submit.json")"
|
||||
|
||||
local approve_status
|
||||
approve_status="$(api_json_auth POST "/api/workflow/tasks/$task_id/approve" "$manager_token" "$TMP_DIR/${tmp_prefix}-approve.json" '{"comment":"approve procurement erp regression"}')"
|
||||
assert_status "$approve_status" "200" "approve purchase ${title_suffix}" "$TMP_DIR/${tmp_prefix}-approve.json"
|
||||
jq -e '.data.outcome == "approved" and .data.purchaseRequestStatus == "approved"' "$TMP_DIR/${tmp_prefix}-approve.json" >/dev/null
|
||||
|
||||
printf '%s\n%s' "$purchase_id" "$task_id"
|
||||
}
|
||||
|
||||
archive_purchase_order() {
|
||||
local finance_token="$1"
|
||||
local purchase_id="$2"
|
||||
local po_no="$3"
|
||||
local contract_no="$4"
|
||||
local tmp_prefix="$5"
|
||||
|
||||
local archive_status
|
||||
archive_status="$(api_json_auth POST "/api/purchase-requests/$purchase_id/archive-order" "$finance_token" "$TMP_DIR/${tmp_prefix}-archive.json" "$(jq -nc --arg po "$po_no" --arg contract "$contract_no" '{poNo:$po, contractNo:$contract, archivedFiles:[]}')")"
|
||||
assert_status "$archive_status" "200" "archive purchase ${purchase_id}" "$TMP_DIR/${tmp_prefix}-archive.json"
|
||||
jq -e --arg po "$po_no" --arg contract "$contract_no" '.data.archiveOrder.poNo == $po and .data.archiveOrder.contractNo == $contract' "$TMP_DIR/${tmp_prefix}-archive.json" >/dev/null
|
||||
jq -er '.data.archiveOrder.id' "$TMP_DIR/${tmp_prefix}-archive.json"
|
||||
}
|
||||
|
||||
assert_export_mode_semantics() {
|
||||
local mode="$1"
|
||||
local state_json="$2"
|
||||
@@ -692,7 +1002,95 @@ legacy_outbox_id="$(jq -er '.data.outboxId' "$legacy_body")"
|
||||
legacy_state="$(query_outbox_state "$legacy_outbox_id")"
|
||||
jq -e '.eventType == "erp.journal.export" and .status == "pending"' <<<"$legacy_state" >/dev/null
|
||||
|
||||
echo "[9/9] ERP env gate off blocks sync"
|
||||
echo "[9/13] Procurement approval/archive auto export + bindings"
|
||||
EMPLOYEE_TOKEN="$(login_user "$EMPLOYEE_IDENTIFIER" "$EMPLOYEE_PASSWORD" employee)"
|
||||
MANAGER_TOKEN="$(login_user "$MANAGER_IDENTIFIER" "$MANAGER_PASSWORD" manager)"
|
||||
FINANCE_MGR_TOKEN="$TOKEN"
|
||||
mapfile -t FIXTURE_IDS < <(resolve_procurement_fixture_ids)
|
||||
LEGAL_ENTITY_ID="${FIXTURE_IDS[0]}"
|
||||
COST_CENTER_ID="${FIXTURE_IDS[1]}"
|
||||
SUPPLIER_ID="${FIXTURE_IDS[2]}"
|
||||
DOCUMENT_CATEGORY_ID="${FIXTURE_IDS[3]}"
|
||||
BUDGET_POOL_ID="${FIXTURE_IDS[4]}"
|
||||
|
||||
mapfile -t PROCUREMENT_APPROVED < <(create_and_approve_purchase "$EMPLOYEE_TOKEN" "$MANAGER_TOKEN" "procurement erp success" "proc-success")
|
||||
PURCHASE_ID_APPROVED="${PROCUREMENT_APPROVED[0]}"
|
||||
COMMITMENT_DEDUPE="purchase_request:${PURCHASE_ID_APPROVED}:commitment"
|
||||
commitment_state="$(query_outbox_by_key 'erp.journal.export' "$COMMITMENT_DEDUPE")"
|
||||
jq -e '.status == "pending" and .payload.journalType == "purchase_request_commitment"' <<<"$commitment_state" >/dev/null
|
||||
run_outbox_once success success
|
||||
commitment_state_done="$(query_outbox_by_key 'erp.journal.export' "$COMMITMENT_DEDUPE")"
|
||||
jq -e '.status == "succeeded"' <<<"$commitment_state_done" >/dev/null
|
||||
commitment_binding="$(query_binding_by_key 'purchase_request_commitment_journal' "$PURCHASE_ID_APPROVED")"
|
||||
jq -e '.externalCode != null' <<<"$commitment_binding" >/dev/null
|
||||
|
||||
ARCHIVE_ID_APPROVED="$(archive_purchase_order "$FINANCE_MGR_TOKEN" "$PURCHASE_ID_APPROVED" 'PO-P19ERP2-001' 'CT-P19ERP2-001' 'proc-success')"
|
||||
ACCRUAL_DEDUPE="purchase_order_archive:${ARCHIVE_ID_APPROVED}:accrual"
|
||||
SUMMARY_DEDUPE="purchase_order_archive:${ARCHIVE_ID_APPROVED}:summary"
|
||||
accrual_state="$(query_outbox_by_key 'erp.journal.export' "$ACCRUAL_DEDUPE")"
|
||||
summary_state="$(query_outbox_by_key 'erp.procurement.export' "$SUMMARY_DEDUPE")"
|
||||
jq -e '.status == "pending" and .payload.journalType == "purchase_order_accrual"' <<<"$accrual_state" >/dev/null
|
||||
jq -e '.status == "pending" and .payload.exportType == "purchase_order_archive"' <<<"$summary_state" >/dev/null
|
||||
run_outbox_once success success
|
||||
accrual_state_done="$(query_outbox_by_key 'erp.journal.export' "$ACCRUAL_DEDUPE")"
|
||||
summary_state_done="$(query_outbox_by_key 'erp.procurement.export' "$SUMMARY_DEDUPE")"
|
||||
jq -e '.status == "succeeded"' <<<"$accrual_state_done" >/dev/null
|
||||
jq -e '.status == "succeeded"' <<<"$summary_state_done" >/dev/null
|
||||
accrual_binding="$(query_binding_by_key 'purchase_order_accrual_journal' "$ARCHIVE_ID_APPROVED")"
|
||||
po_binding="$(query_binding_by_key 'purchase_order_po' "$ARCHIVE_ID_APPROVED")"
|
||||
contract_binding="$(query_binding_by_key 'purchase_order_contract' "$ARCHIVE_ID_APPROVED")"
|
||||
jq -e '.externalCode != null' <<<"$accrual_binding" >/dev/null
|
||||
jq -e '.externalCode != null' <<<"$po_binding" >/dev/null
|
||||
jq -e '.externalCode != null' <<<"$contract_binding" >/dev/null
|
||||
|
||||
echo "[10/13] Archive update only resets summary"
|
||||
ARCHIVE_UPDATE_STATUS="$(api_json_auth POST "/api/purchase-requests/$PURCHASE_ID_APPROVED/archive-order" "$FINANCE_MGR_TOKEN" "$TMP_DIR/proc-success-archive-update.json" '{"poNo":"PO-P19ERP2-001","contractNo":"CT-P19ERP2-002","archivedFiles":[]}')"
|
||||
assert_status "$ARCHIVE_UPDATE_STATUS" "200" "archive update" "$TMP_DIR/proc-success-archive-update.json"
|
||||
accrual_state_after_update="$(query_outbox_by_key 'erp.journal.export' "$ACCRUAL_DEDUPE")"
|
||||
summary_state_after_update="$(query_outbox_by_key 'erp.procurement.export' "$SUMMARY_DEDUPE")"
|
||||
ACCRUAL_OUTBOX_ID="$(jq -er '.id' <<<"$accrual_state_done")"
|
||||
SUMMARY_OUTBOX_ID="$(jq -er '.id' <<<"$summary_state_done")"
|
||||
jq -e --arg id "$ACCRUAL_OUTBOX_ID" '.id == $id and .status == "succeeded"' <<<"$accrual_state_after_update" >/dev/null
|
||||
jq -e --arg id "$SUMMARY_OUTBOX_ID" '.id == $id and .status == "pending" and .payload.contractNo == "CT-P19ERP2-002"' <<<"$summary_state_after_update" >/dev/null
|
||||
run_outbox_once success success
|
||||
contract_binding_updated="$(query_binding_by_key 'purchase_order_contract' "$ARCHIVE_ID_APPROVED")"
|
||||
jq -e '.externalCode != null' <<<"$contract_binding_updated" >/dev/null
|
||||
|
||||
echo "[11/13] Force-off skips auto export and manual requeue backfills historical单据"
|
||||
set_erp_flag "force_off"
|
||||
mapfile -t PROCUREMENT_SKIPPED < <(create_and_approve_purchase "$EMPLOYEE_TOKEN" "$MANAGER_TOKEN" "procurement erp skipped" "proc-skipped")
|
||||
PURCHASE_ID_SKIPPED="${PROCUREMENT_SKIPPED[0]}"
|
||||
COMMITMENT_DEDUPE_SKIPPED="purchase_request:${PURCHASE_ID_SKIPPED}:commitment"
|
||||
assert_outbox_absent_by_key 'erp.journal.export' "$COMMITMENT_DEDUPE_SKIPPED"
|
||||
ARCHIVE_ID_SKIPPED="$(archive_purchase_order "$FINANCE_MGR_TOKEN" "$PURCHASE_ID_SKIPPED" 'PO-P19ERP2-101' 'CT-P19ERP2-101' 'proc-skipped')"
|
||||
ACCRUAL_DEDUPE_SKIPPED="purchase_order_archive:${ARCHIVE_ID_SKIPPED}:accrual"
|
||||
SUMMARY_DEDUPE_SKIPPED="purchase_order_archive:${ARCHIVE_ID_SKIPPED}:summary"
|
||||
assert_outbox_absent_by_key 'erp.journal.export' "$ACCRUAL_DEDUPE_SKIPPED"
|
||||
assert_outbox_absent_by_key 'erp.procurement.export' "$SUMMARY_DEDUPE_SKIPPED"
|
||||
set_erp_flag "force_on"
|
||||
PROC_REQUEUE_CODE="$(api_json_auth POST "/api/integrations/erp/procurement/purchase-requests/$PURCHASE_ID_SKIPPED/requeue?runNow=0" "$FINANCE_MGR_TOKEN" "$TMP_DIR/proc-requeue.json" '{"targets":["commitment_journal","accrual_journal","archive_summary"]}')"
|
||||
assert_status "$PROC_REQUEUE_CODE" "200" "procurement requeue" "$TMP_DIR/proc-requeue.json"
|
||||
jq -e '.data.items | length == 3' "$TMP_DIR/proc-requeue.json" >/dev/null
|
||||
run_outbox_once success success
|
||||
jq -e '.status == "succeeded"' <<<"$(query_outbox_by_key 'erp.journal.export' "$COMMITMENT_DEDUPE_SKIPPED")" >/dev/null
|
||||
jq -e '.status == "succeeded"' <<<"$(query_outbox_by_key 'erp.journal.export' "$ACCRUAL_DEDUPE_SKIPPED")" >/dev/null
|
||||
jq -e '.status == "succeeded"' <<<"$(query_outbox_by_key 'erp.procurement.export' "$SUMMARY_DEDUPE_SKIPPED")" >/dev/null
|
||||
|
||||
echo "[12/13] Archive summary dead-letter can requeue same outbox"
|
||||
PROC_SUMMARY_FAIL_STATUS="$(api_json_auth POST "/api/purchase-requests/$PURCHASE_ID_APPROVED/archive-order" "$FINANCE_MGR_TOKEN" "$TMP_DIR/proc-summary-fail-archive.json" '{"poNo":"PO-P19ERP2-001","contractNo":"CT-P19ERP2-003","archivedFiles":[]}')"
|
||||
assert_status "$PROC_SUMMARY_FAIL_STATUS" "200" "archive update for summary failure" "$TMP_DIR/proc-summary-fail-archive.json"
|
||||
run_outbox_once success client
|
||||
summary_dead_state="$(query_outbox_by_key 'erp.procurement.export' "$SUMMARY_DEDUPE")"
|
||||
jq -e '.status == "dead_letter" and .attempts == 1' <<<"$summary_dead_state" >/dev/null
|
||||
SUMMARY_DEAD_ID="$(jq -er '.id' <<<"$summary_dead_state")"
|
||||
PROC_SUMMARY_REQUEUE_CODE="$(api_json_auth POST "/api/integrations/erp/procurement/purchase-requests/$PURCHASE_ID_APPROVED/requeue?runNow=0" "$FINANCE_MGR_TOKEN" "$TMP_DIR/proc-summary-requeue.json" '{"targets":["archive_summary"]}')"
|
||||
assert_status "$PROC_SUMMARY_REQUEUE_CODE" "200" "procurement summary requeue" "$TMP_DIR/proc-summary-requeue.json"
|
||||
jq -e --arg id "$SUMMARY_DEAD_ID" '.data.items[0].outboxId == $id and .data.items[0].requeued == true' "$TMP_DIR/proc-summary-requeue.json" >/dev/null
|
||||
run_outbox_once success success
|
||||
summary_requeue_state="$(query_outbox_by_key 'erp.procurement.export' "$SUMMARY_DEDUPE")"
|
||||
jq -e --arg id "$SUMMARY_DEAD_ID" '.id == $id and .status == "succeeded"' <<<"$summary_requeue_state" >/dev/null
|
||||
|
||||
echo "[13/13] ERP env gate off blocks sync"
|
||||
if kill -0 "$APP_SERVER_PID" >/dev/null 2>&1; then
|
||||
kill "$APP_SERVER_PID" >/dev/null 2>&1 || true
|
||||
wait "$APP_SERVER_PID" >/dev/null 2>&1 || true
|
||||
@@ -705,8 +1103,10 @@ OCR_PROVIDER=mock \
|
||||
ERP_SYNC_ENABLED=false \
|
||||
ERP_SYNC_PROVIDER=http \
|
||||
ERP_MASTER_DATA_ENDPOINT="http://127.0.0.1:$MOCK_ERP_PORT/erp/master-data/pull?mode=success" \
|
||||
ERP_JOURNAL_EXPORT_ENDPOINT="http://127.0.0.1:$MOCK_ERP_PORT/erp/journals/reimbursements/paid?mode=success" \
|
||||
ERP_JOURNAL_EXPORT_ENDPOINT="http://127.0.0.1:$MOCK_ERP_PORT/erp/journals/export?mode=success" \
|
||||
ERP_PROCUREMENT_EXPORT_ENDPOINT="http://127.0.0.1:$MOCK_ERP_PORT/erp/procurement/export?mode=success" \
|
||||
ERP_SYNC_TIMEOUT_MS="$ERP_SYNC_TIMEOUT_MS" \
|
||||
ERP_PROCUREMENT_TIMEOUT_MS="$ERP_SYNC_TIMEOUT_MS" \
|
||||
ERP_MASTER_DATA_TIMEOUT_MS="$ERP_SYNC_TIMEOUT_MS" \
|
||||
ERP_SYNC_AUTH_TOKEN="" \
|
||||
node src/index.js >"$TMP_DIR/app-gate-off.log" 2>&1 &
|
||||
|
||||
在新工单中引用
屏蔽一个用户