docs/test(P18B-5,P18B-6): 收口资产盘点矩阵文档与回归
这个提交包含在:
+167
-77
@@ -7,6 +7,8 @@ EMPLOYEE_IDENTIFIER="${EMPLOYEE_IDENTIFIER:[email protected]}"
|
||||
EMPLOYEE_PASSWORD="${EMPLOYEE_PASSWORD:-EmployeePassword1234}"
|
||||
FINANCE_MGR_IDENTIFIER="${FINANCE_MGR_IDENTIFIER:-finance_mgr@hyinda.com}"
|
||||
FINANCE_MGR_PASSWORD="${FINANCE_MGR_PASSWORD:-FinanceMgrPassword1234}"
|
||||
ADMINISTRATION_IDENTIFIER="${ADMINISTRATION_IDENTIFIER:-administration@hyinda.com}"
|
||||
ADMINISTRATION_PASSWORD="${ADMINISTRATION_PASSWORD:-AdministrationPassword1234}"
|
||||
|
||||
if ! command -v curl >/dev/null 2>&1; then
|
||||
echo "[ERROR] curl not found" >&2
|
||||
@@ -110,6 +112,14 @@ const { createPrismaClient } = require('./src/prismaClient');
|
||||
where: { email: process.env.SEED_EMPLOYEE_EMAIL ?? '[email protected]' },
|
||||
select: { id: true, legal_entity_id: true },
|
||||
});
|
||||
const financeMgr = await prisma.employee.findUnique({
|
||||
where: { email: process.env.SEED_FINANCE_MGR_EMAIL ?? '[email protected]' },
|
||||
select: { id: true },
|
||||
});
|
||||
const administration = await prisma.employee.findUnique({
|
||||
where: { email: process.env.SEED_ADMINISTRATION_EMAIL ?? '[email protected]' },
|
||||
select: { id: true },
|
||||
});
|
||||
const costCenter = await prisma.costCenter.findFirst({
|
||||
where: {
|
||||
legal_entity_id: employee.legal_entity_id,
|
||||
@@ -119,24 +129,6 @@ const { createPrismaClient } = require('./src/prismaClient');
|
||||
orderBy: { created_at: 'asc' },
|
||||
select: { id: true },
|
||||
});
|
||||
const documentCategory = await prisma.documentCategory.findFirst({
|
||||
where: {
|
||||
entity_type: 'asset_card',
|
||||
enabled: true,
|
||||
archived_at: null,
|
||||
code: 'ASSET_CARD_DEFAULT',
|
||||
},
|
||||
orderBy: { created_at: 'asc' },
|
||||
select: { id: true },
|
||||
}) ?? await prisma.documentCategory.findFirst({
|
||||
where: {
|
||||
entity_type: 'asset_card',
|
||||
enabled: true,
|
||||
archived_at: null,
|
||||
},
|
||||
orderBy: { created_at: 'asc' },
|
||||
select: { id: true },
|
||||
});
|
||||
const approvedPurchase = await prisma.purchaseRequest.findFirst({
|
||||
where: { status: 'approved' },
|
||||
orderBy: { updated_at: 'desc' },
|
||||
@@ -145,9 +137,10 @@ const { createPrismaClient } = require('./src/prismaClient');
|
||||
|
||||
process.stdout.write([
|
||||
employee.id,
|
||||
financeMgr.id,
|
||||
administration.id,
|
||||
employee.legal_entity_id ?? '',
|
||||
costCenter?.id ?? '',
|
||||
documentCategory?.id ?? '',
|
||||
approvedPurchase?.id ?? '',
|
||||
].join('\n'));
|
||||
} finally {
|
||||
@@ -164,11 +157,11 @@ NODE
|
||||
assert_asset_state() {
|
||||
local asset_id="$1"
|
||||
local category_id="$2"
|
||||
local employee_id="$3"
|
||||
local purchase_request_id="$4"
|
||||
local finance_mgr_id="$3"
|
||||
local inventory_check_id="$4"
|
||||
|
||||
DATABASE_URL="$DATABASE_URL" node - "$asset_id" "$category_id" "$employee_id" "$purchase_request_id" <<'NODE'
|
||||
const [assetId, categoryId, employeeId, purchaseRequestId] = process.argv.slice(2);
|
||||
DATABASE_URL="$DATABASE_URL" node - "$asset_id" "$category_id" "$finance_mgr_id" "$inventory_check_id" <<'NODE'
|
||||
const [assetId, categoryId, financeMgrId, inventoryCheckId] = process.argv.slice(2);
|
||||
const { createPrismaClient } = require('./src/prismaClient');
|
||||
|
||||
(async () => {
|
||||
@@ -177,7 +170,7 @@ const { createPrismaClient } = require('./src/prismaClient');
|
||||
try {
|
||||
const category = await prisma.assetCategory.findUnique({
|
||||
where: { id: categoryId },
|
||||
select: { name: true, document_category: { select: { code: true } } },
|
||||
select: { name: true },
|
||||
});
|
||||
const asset = await prisma.assetCard.findUnique({
|
||||
where: { id: assetId },
|
||||
@@ -185,30 +178,88 @@ const { createPrismaClient } = require('./src/prismaClient');
|
||||
asset_no: true,
|
||||
status: true,
|
||||
assignee_employee_id: true,
|
||||
purchase_request_id: true,
|
||||
location: true,
|
||||
},
|
||||
});
|
||||
const assignments = await prisma.assetAssignment.findMany({
|
||||
where: { asset_id: assetId },
|
||||
orderBy: { assigned_at: 'asc' },
|
||||
select: { employee_id: true, returned_at: true },
|
||||
});
|
||||
const transfers = await prisma.assetTransfer.findMany({
|
||||
where: { asset_id: assetId },
|
||||
select: { to_employee_id: true, to_location: true },
|
||||
});
|
||||
const inventoryCheck = await prisma.inventoryCheck.findUnique({
|
||||
where: { id: inventoryCheckId },
|
||||
select: {
|
||||
status: true,
|
||||
items: {
|
||||
select: { asset_id: true, result: true },
|
||||
},
|
||||
},
|
||||
});
|
||||
const auditActions = await prisma.auditLog.findMany({
|
||||
where: {
|
||||
target_id: { in: [assetId, inventoryCheckId] },
|
||||
action: {
|
||||
in: [
|
||||
'ASSET_ASSIGNED',
|
||||
'ASSET_RETURNED',
|
||||
'ASSET_TRANSFERRED',
|
||||
'INVENTORY_CHECK_CREATED',
|
||||
'INVENTORY_CHECK_STARTED',
|
||||
'INVENTORY_ITEM_RECORDED',
|
||||
'INVENTORY_CHECK_COMPLETED',
|
||||
],
|
||||
},
|
||||
},
|
||||
select: { action: true },
|
||||
});
|
||||
|
||||
if (!category || category.name !== '回归资产分类-已更新' || category.document_category?.code !== 'ASSET_CARD_DEFAULT') {
|
||||
const openAssignments = assignments.filter((item) => item.returned_at == null);
|
||||
const actionSet = new Set(auditActions.map((item) => item.action));
|
||||
|
||||
if (!category || category.name !== '回归资产分类-已更新') {
|
||||
console.error('[ERROR] asset category state mismatch', category);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
if (!asset || !asset.asset_no.startsWith('ZC-') || asset.status !== 'in_use' || asset.assignee_employee_id !== employeeId) {
|
||||
if (!asset || !asset.asset_no.startsWith('ZC-') || asset.status !== 'in_use' || asset.assignee_employee_id !== financeMgrId || asset.location !== '深圳办公室 B-02') {
|
||||
console.error('[ERROR] asset card state mismatch', asset);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
if (purchaseRequestId && asset.purchase_request_id !== purchaseRequestId) {
|
||||
console.error('[ERROR] asset purchase source mismatch', asset);
|
||||
if (assignments.length < 3 || openAssignments.length !== 1 || openAssignments[0].employee_id !== financeMgrId) {
|
||||
console.error('[ERROR] asset assignments state mismatch', assignments);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
if (asset.location !== '深圳办公室 A-01') {
|
||||
console.error('[ERROR] asset location mismatch', asset);
|
||||
if (!transfers.length || transfers[0].to_employee_id !== financeMgrId || transfers[0].to_location !== '深圳办公室 B-02') {
|
||||
console.error('[ERROR] asset transfer state mismatch', transfers);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
if (!inventoryCheck || inventoryCheck.status !== 'completed' || inventoryCheck.items.length !== 1 || inventoryCheck.items[0].asset_id !== assetId || inventoryCheck.items[0].result !== 'matched') {
|
||||
console.error('[ERROR] inventory check state mismatch', inventoryCheck);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const requiredActions = [
|
||||
'ASSET_ASSIGNED',
|
||||
'ASSET_RETURNED',
|
||||
'ASSET_TRANSFERRED',
|
||||
'INVENTORY_CHECK_CREATED',
|
||||
'INVENTORY_CHECK_STARTED',
|
||||
'INVENTORY_ITEM_RECORDED',
|
||||
'INVENTORY_CHECK_COMPLETED',
|
||||
];
|
||||
for (const action of requiredActions) {
|
||||
if (!actionSet.has(action)) {
|
||||
console.error('[ERROR] missing audit action', action, auditActions);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
await prisma.$disconnect();
|
||||
await pool.end();
|
||||
@@ -220,64 +271,103 @@ const { createPrismaClient } = require('./src/prismaClient');
|
||||
NODE
|
||||
}
|
||||
|
||||
echo "[1/8] login finance manager and employee"
|
||||
FINANCE_MGR_TOKEN="$(login_user "$FINANCE_MGR_IDENTIFIER" "$FINANCE_MGR_PASSWORD" "$TMP_DIR/finance-mgr-login.json")"
|
||||
echo "[1/10] login employee finance manager and administration"
|
||||
EMPLOYEE_TOKEN="$(login_user "$EMPLOYEE_IDENTIFIER" "$EMPLOYEE_PASSWORD" "$TMP_DIR/employee-login.json")"
|
||||
|
||||
FINANCE_MGR_TOKEN="$(login_user "$FINANCE_MGR_IDENTIFIER" "$FINANCE_MGR_PASSWORD" "$TMP_DIR/finance-mgr-login.json")"
|
||||
ADMINISTRATION_TOKEN="$(login_user "$ADMINISTRATION_IDENTIFIER" "$ADMINISTRATION_PASSWORD" "$TMP_DIR/administration-login.json")"
|
||||
mapfile -t FIXTURE_IDS < <(resolve_fixture_ids)
|
||||
EMPLOYEE_ID="${FIXTURE_IDS[0]}"
|
||||
LEGAL_ENTITY_ID="${FIXTURE_IDS[1]}"
|
||||
COST_CENTER_ID="${FIXTURE_IDS[2]}"
|
||||
DOCUMENT_CATEGORY_ID="${FIXTURE_IDS[3]}"
|
||||
APPROVED_PURCHASE_ID="${FIXTURE_IDS[4]}"
|
||||
FINANCE_MGR_ID="${FIXTURE_IDS[1]}"
|
||||
ADMINISTRATION_ID="${FIXTURE_IDS[2]}"
|
||||
LEGAL_ENTITY_ID="${FIXTURE_IDS[3]}"
|
||||
COST_CENTER_ID="${FIXTURE_IDS[4]}"
|
||||
APPROVED_PURCHASE_ID="${FIXTURE_IDS[5]}"
|
||||
|
||||
if [[ -z "$LEGAL_ENTITY_ID" || -z "$COST_CENTER_ID" || -z "$DOCUMENT_CATEGORY_ID" ]]; then
|
||||
echo "[ERROR] missing asset fixtures" >&2
|
||||
exit 1
|
||||
fi
|
||||
echo "[2/10] finance manager create and update asset category"
|
||||
CATEGORY_CREATE_BODY="$TMP_DIR/category-create.json"
|
||||
CATEGORY_CREATE_STATUS="$(api_json_auth POST "$BASE_URL/api/asset-categories" "$FINANCE_MGR_TOKEN" "$CATEGORY_CREATE_BODY" '{"code":"REG_ASSET_CAT_'"$(date +%s)'"'","name":"回归资产分类","enabled":true}')"
|
||||
assert_status "$CATEGORY_CREATE_STATUS" "200" "create asset category" "$CATEGORY_CREATE_BODY"
|
||||
CATEGORY_ID="$(jq -er '.data.assetCategory.id' "$CATEGORY_CREATE_BODY")"
|
||||
CATEGORY_PATCH_BODY="$TMP_DIR/category-patch.json"
|
||||
CATEGORY_PATCH_STATUS="$(api_json_auth PATCH "$BASE_URL/api/asset-categories/$CATEGORY_ID" "$FINANCE_MGR_TOKEN" "$CATEGORY_PATCH_BODY" '{"name":"回归资产分类-已更新"}')"
|
||||
assert_status "$CATEGORY_PATCH_STATUS" "200" "patch asset category" "$CATEGORY_PATCH_BODY"
|
||||
|
||||
echo "[2/8] create asset category"
|
||||
CATEGORY_CODE="ASSET_REG_$(date +%s)"
|
||||
CREATE_CATEGORY_BODY="$(jq -nc --arg code "$CATEGORY_CODE" --arg dc "$DOCUMENT_CATEGORY_ID" '{code:$code,name:"回归资产分类",documentCategoryId:$dc,enabled:true}')"
|
||||
create_category_status="$(api_json_auth POST "$BASE_URL/api/asset-categories" "$FINANCE_MGR_TOKEN" "$TMP_DIR/create-category.json" "$CREATE_CATEGORY_BODY")"
|
||||
assert_status "$create_category_status" "200" "create asset category" "$TMP_DIR/create-category.json"
|
||||
CATEGORY_ID="$(jq -er '.data.assetCategory.id' "$TMP_DIR/create-category.json")"
|
||||
assert_jq "$TMP_DIR/create-category.json" '.data.assetCategory.documentCategory.code == "ASSET_CARD_DEFAULT"' "asset category document category"
|
||||
echo "[3/10] finance manager creates asset card"
|
||||
ASSET_CREATE_PAYLOAD="$(jq -n \
|
||||
--arg name "回归资产卡片 $(date +%s)" \
|
||||
--arg categoryId "$CATEGORY_ID" \
|
||||
--arg legalEntityId "$LEGAL_ENTITY_ID" \
|
||||
--arg costCenterId "$COST_CENTER_ID" \
|
||||
--arg purchaseRequestId "$APPROVED_PURCHASE_ID" \
|
||||
'{name:$name, categoryId:$categoryId, legalEntityId:$legalEntityId, costCenterId:$costCenterId, purchaseRequestId:($purchaseRequestId|select(length>0)), location:"深圳办公室 A-01", status:"in_stock"}')"
|
||||
ASSET_CREATE_BODY="$TMP_DIR/asset-create.json"
|
||||
ASSET_CREATE_STATUS="$(api_json_auth POST "$BASE_URL/api/assets" "$FINANCE_MGR_TOKEN" "$ASSET_CREATE_BODY" "$ASSET_CREATE_PAYLOAD")"
|
||||
assert_status "$ASSET_CREATE_STATUS" "200" "create asset card" "$ASSET_CREATE_BODY"
|
||||
ASSET_ID="$(jq -er '.data.asset.id' "$ASSET_CREATE_BODY")"
|
||||
|
||||
echo "[3/8] update asset category"
|
||||
PATCH_CATEGORY_BODY='{"name":"回归资产分类-已更新","enabled":true}'
|
||||
patch_category_status="$(api_json_auth PATCH "$BASE_URL/api/asset-categories/$CATEGORY_ID" "$FINANCE_MGR_TOKEN" "$TMP_DIR/patch-category.json" "$PATCH_CATEGORY_BODY")"
|
||||
assert_status "$patch_category_status" "200" "patch asset category" "$TMP_DIR/patch-category.json"
|
||||
assert_jq "$TMP_DIR/patch-category.json" '.data.assetCategory.name == "回归资产分类-已更新"' "patched asset category name"
|
||||
|
||||
echo "[4/8] create asset card with approved purchase source"
|
||||
CREATE_ASSET_BODY="$(jq -nc --arg name "回归资产卡片" --arg categoryId "$CATEGORY_ID" --arg legalEntityId "$LEGAL_ENTITY_ID" --arg costCenterId "$COST_CENTER_ID" --arg purchaseRequestId "$APPROVED_PURCHASE_ID" --arg assigneeEmployeeId "$EMPLOYEE_ID" '{name:$name,categoryId:$categoryId,legalEntityId:$legalEntityId,costCenterId:$costCenterId,purchaseRequestId:($purchaseRequestId|select(length>0)),status:"in_stock",assigneeEmployeeId:$assigneeEmployeeId}')"
|
||||
create_asset_status="$(api_json_auth POST "$BASE_URL/api/assets" "$FINANCE_MGR_TOKEN" "$TMP_DIR/create-asset.json" "$CREATE_ASSET_BODY")"
|
||||
assert_status "$create_asset_status" "200" "create asset" "$TMP_DIR/create-asset.json"
|
||||
ASSET_ID="$(jq -er '.data.asset.id' "$TMP_DIR/create-asset.json")"
|
||||
assert_jq "$TMP_DIR/create-asset.json" '.data.asset.assetNo | test("^ZC-")' "asset no generated"
|
||||
assert_jq "$TMP_DIR/create-asset.json" '.data.asset.assignee.employeeNo == "EMP001" or .data.asset.assignee.name == "Employee"' "asset assignee set"
|
||||
echo "[4/10] direct assignee patch blocked to enforce controlled transfer"
|
||||
ASSET_PATCH_BODY="$TMP_DIR/asset-patch-invalid.json"
|
||||
ASSET_PATCH_STATUS="$(api_json_auth PATCH "$BASE_URL/api/assets/$ASSET_ID" "$FINANCE_MGR_TOKEN" "$ASSET_PATCH_BODY" '{"assigneeEmployeeId":"'"$EMPLOYEE_ID"'"}')"
|
||||
assert_status "$ASSET_PATCH_STATUS" "400" "patch asset assignee invalid" "$ASSET_PATCH_BODY"
|
||||
assert_jq "$ASSET_PATCH_BODY" '.error.code == "VALID_001"' "patch asset assignee invalid code"
|
||||
|
||||
echo "[5/8] employee can only see own assigned asset"
|
||||
list_own_status="$(api_json_auth GET "$BASE_URL/api/assets?mine=1" "$EMPLOYEE_TOKEN" "$TMP_DIR/list-own.json")"
|
||||
assert_status "$list_own_status" "200" "employee list own assets" "$TMP_DIR/list-own.json"
|
||||
assert_jq "$TMP_DIR/list-own.json" ".data.mine == true and (.data.items | map(.id) | index(\"$ASSET_ID\") != null)" "employee owns asset"
|
||||
echo "[5/10] administration assign asset to employee"
|
||||
ASSET_ASSIGN_BODY="$TMP_DIR/asset-assign.json"
|
||||
ASSET_ASSIGN_STATUS="$(api_json_auth POST "$BASE_URL/api/assets/$ASSET_ID/assign" "$ADMINISTRATION_TOKEN" "$ASSET_ASSIGN_BODY" '{"employeeId":"'"$EMPLOYEE_ID"'","note":"首次领用"}')"
|
||||
assert_status "$ASSET_ASSIGN_STATUS" "200" "assign asset" "$ASSET_ASSIGN_BODY"
|
||||
assert_jq "$ASSET_ASSIGN_BODY" '.data.assigneeEmployeeId == "'"$EMPLOYEE_ID"'"' "assign asset assignee"
|
||||
|
||||
echo "[6/8] finance manager updates asset status and location"
|
||||
PATCH_ASSET_BODY='{"status":"in_use","location":"深圳办公室 A-01"}'
|
||||
patch_asset_status="$(api_json_auth PATCH "$BASE_URL/api/assets/$ASSET_ID" "$FINANCE_MGR_TOKEN" "$TMP_DIR/patch-asset.json" "$PATCH_ASSET_BODY")"
|
||||
assert_status "$patch_asset_status" "200" "patch asset" "$TMP_DIR/patch-asset.json"
|
||||
assert_jq "$TMP_DIR/patch-asset.json" '.data.asset.status == "in_use" and .data.asset.location == "深圳办公室 A-01"' "asset status/location updated"
|
||||
echo "[6/10] employee only sees own asset and cannot transfer"
|
||||
EMPLOYEE_ASSETS_BODY="$TMP_DIR/employee-assets.json"
|
||||
EMPLOYEE_ASSETS_STATUS="$(api_json_auth GET "$BASE_URL/api/assets?mine=0" "$EMPLOYEE_TOKEN" "$EMPLOYEE_ASSETS_BODY")"
|
||||
assert_status "$EMPLOYEE_ASSETS_STATUS" "200" "employee assets mine forced" "$EMPLOYEE_ASSETS_BODY"
|
||||
assert_jq "$EMPLOYEE_ASSETS_BODY" '.data.mine == true' "employee mine forced"
|
||||
assert_jq "$EMPLOYEE_ASSETS_BODY" '.data.items[] | select(.id == "'"$ASSET_ID"'") | .assigneeEmployeeId == "'"$EMPLOYEE_ID"'"' "employee sees owned asset"
|
||||
EMPLOYEE_TRANSFER_BODY="$TMP_DIR/employee-transfer.json"
|
||||
EMPLOYEE_TRANSFER_STATUS="$(api_json_auth POST "$BASE_URL/api/assets/$ASSET_ID/transfer" "$EMPLOYEE_TOKEN" "$EMPLOYEE_TRANSFER_BODY" '{"toLocation":"深圳办公室 B-01"}')"
|
||||
assert_status "$EMPLOYEE_TRANSFER_STATUS" "403" "employee transfer forbidden" "$EMPLOYEE_TRANSFER_BODY"
|
||||
assert_jq "$EMPLOYEE_TRANSFER_BODY" '.error.code == "PERM_001"' "employee transfer forbidden code"
|
||||
|
||||
echo "[7/8] purchase source is immutable after create"
|
||||
INVALID_PATCH_BODY="$(jq -nc --arg purchaseRequestId "$APPROVED_PURCHASE_ID" '{purchaseRequestId:$purchaseRequestId}')"
|
||||
invalid_patch_status="$(api_json_auth PATCH "$BASE_URL/api/assets/$ASSET_ID" "$FINANCE_MGR_TOKEN" "$TMP_DIR/invalid-patch.json" "$INVALID_PATCH_BODY")"
|
||||
assert_status "$invalid_patch_status" "400" "patch asset purchase source forbidden" "$TMP_DIR/invalid-patch.json"
|
||||
assert_jq "$TMP_DIR/invalid-patch.json" '.error.code == "VALID_001"' "invalid purchase source patch code"
|
||||
echo "[7/10] administration return then assign asset again"
|
||||
ASSET_RETURN_BODY="$TMP_DIR/asset-return.json"
|
||||
ASSET_RETURN_STATUS="$(api_json_auth POST "$BASE_URL/api/assets/$ASSET_ID/return" "$ADMINISTRATION_TOKEN" "$ASSET_RETURN_BODY" '{"note":"归还入库"}')"
|
||||
assert_status "$ASSET_RETURN_STATUS" "200" "return asset" "$ASSET_RETURN_BODY"
|
||||
assert_jq "$ASSET_RETURN_BODY" '.data.assigneeEmployeeId == null' "return clears assignee"
|
||||
ASSET_REASSIGN_BODY="$TMP_DIR/asset-reassign.json"
|
||||
ASSET_REASSIGN_STATUS="$(api_json_auth POST "$BASE_URL/api/assets/$ASSET_ID/assign" "$ADMINISTRATION_TOKEN" "$ASSET_REASSIGN_BODY" '{"employeeId":"'"$EMPLOYEE_ID"'","note":"再次领用"}')"
|
||||
assert_status "$ASSET_REASSIGN_STATUS" "200" "reassign asset" "$ASSET_REASSIGN_BODY"
|
||||
|
||||
echo "[8/8] verify category and asset db state"
|
||||
assert_asset_state "$ASSET_ID" "$CATEGORY_ID" "$EMPLOYEE_ID" "$APPROVED_PURCHASE_ID"
|
||||
echo "[8/10] administration transfers asset to finance manager and new location"
|
||||
ASSET_TRANSFER_BODY="$TMP_DIR/asset-transfer.json"
|
||||
ASSET_TRANSFER_STATUS="$(api_json_auth POST "$BASE_URL/api/assets/$ASSET_ID/transfer" "$ADMINISTRATION_TOKEN" "$ASSET_TRANSFER_BODY" '{"toEmployeeId":"'"$FINANCE_MGR_ID"'","toLocation":"深圳办公室 B-02","note":"部门间调拨"}')"
|
||||
assert_status "$ASSET_TRANSFER_STATUS" "200" "transfer asset" "$ASSET_TRANSFER_BODY"
|
||||
assert_jq "$ASSET_TRANSFER_BODY" '.data.assigneeEmployeeId == "'"$FINANCE_MGR_ID"'"' "transfer asset assignee"
|
||||
assert_jq "$ASSET_TRANSFER_BODY" '.data.location == "深圳办公室 B-02"' "transfer asset location"
|
||||
|
||||
echo "[9/10] finance manager creates completes inventory check; employee forbidden"
|
||||
INVENTORY_CREATE_BODY="$TMP_DIR/inventory-create.json"
|
||||
INVENTORY_CREATE_STATUS="$(api_json_auth POST "$BASE_URL/api/inventory-checks" "$FINANCE_MGR_TOKEN" "$INVENTORY_CREATE_BODY" '{"scopeType":"cost_center","scopeRefId":"'"$COST_CENTER_ID"'"}')"
|
||||
assert_status "$INVENTORY_CREATE_STATUS" "200" "create inventory check" "$INVENTORY_CREATE_BODY"
|
||||
INVENTORY_CHECK_ID="$(jq -er '.data.inventoryCheck.id' "$INVENTORY_CREATE_BODY")"
|
||||
INVENTORY_START_BODY="$TMP_DIR/inventory-start.json"
|
||||
INVENTORY_START_STATUS="$(api_json_auth POST "$BASE_URL/api/inventory-checks/$INVENTORY_CHECK_ID/start" "$FINANCE_MGR_TOKEN" "$INVENTORY_START_BODY")"
|
||||
assert_status "$INVENTORY_START_STATUS" "200" "start inventory check" "$INVENTORY_START_BODY"
|
||||
INVENTORY_ITEM_BODY="$TMP_DIR/inventory-item.json"
|
||||
INVENTORY_ITEM_STATUS="$(api_json_auth POST "$BASE_URL/api/inventory-checks/$INVENTORY_CHECK_ID/items" "$FINANCE_MGR_TOKEN" "$INVENTORY_ITEM_BODY" '{"items":[{"assetId":"'"$ASSET_ID"'","result":"matched","note":"盘点一致"}]}')"
|
||||
assert_status "$INVENTORY_ITEM_STATUS" "200" "record inventory item" "$INVENTORY_ITEM_BODY"
|
||||
INVENTORY_COMPLETE_BODY="$TMP_DIR/inventory-complete.json"
|
||||
INVENTORY_COMPLETE_STATUS="$(api_json_auth POST "$BASE_URL/api/inventory-checks/$INVENTORY_CHECK_ID/complete" "$FINANCE_MGR_TOKEN" "$INVENTORY_COMPLETE_BODY")"
|
||||
assert_status "$INVENTORY_COMPLETE_STATUS" "200" "complete inventory check" "$INVENTORY_COMPLETE_BODY"
|
||||
EMPLOYEE_INVENTORY_BODY="$TMP_DIR/employee-inventory.json"
|
||||
EMPLOYEE_INVENTORY_STATUS="$(api_json_auth GET "$BASE_URL/api/inventory-checks" "$EMPLOYEE_TOKEN" "$EMPLOYEE_INVENTORY_BODY")"
|
||||
assert_status "$EMPLOYEE_INVENTORY_STATUS" "403" "employee inventory forbidden" "$EMPLOYEE_INVENTORY_BODY"
|
||||
assert_jq "$EMPLOYEE_INVENTORY_BODY" '.error.code == "PERM_001"' "employee inventory forbidden code"
|
||||
|
||||
echo "[10/10] verify asset movement inventory db state and audit logs"
|
||||
assert_asset_state "$ASSET_ID" "$CATEGORY_ID" "$FINANCE_MGR_ID" "$INVENTORY_CHECK_ID"
|
||||
|
||||
echo "[OK] Asset regression passed"
|
||||
echo "- assetCategoryId: $CATEGORY_ID"
|
||||
echo "- assetId: $ASSET_ID"
|
||||
echo "- inventoryCheckId: $INVENTORY_CHECK_ID"
|
||||
|
||||
在新工单中引用
屏蔽一个用户