feat(接口测试): 导入场景请求时场景子步骤复制文件

This commit is contained in:
baiqi 2024-12-09 18:02:00 +08:00 committed by Craftsman
parent 3f476afcdc
commit 06cd4cc317
5 changed files with 63 additions and 27 deletions

View File

@ -1218,14 +1218,17 @@
if (res.protocol === 'HTTP') {
if ((props.step?.copyFromStepId || props.step?.refType === ScenarioStepRefType.COPY) && props.step?.isNew) {
//
const fileIds = parseRequestBodyFiles(res.request.body, [], [], []).uploadFileIds;
if (fileIds.length > 0) {
copyStepFileIdsMap.value = await scenarioCopyStepFiles({
copyFromStepId: props.step?.copyFromStepId,
resourceId: props.step?.resourceId,
stepType: props.step?.stepType,
refType: props.step?.refType,
isTempFile: false, // true
fileIds: parseRequestBodyFiles(res.request.body, [], [], []).uploadFileIds,
fileIds,
});
}
parseRequestBodyFiles(res.request.body, [], [], [], copyStepFileIdsMap.value);
} else {
parseRequestBodyResult = parseRequestBodyFiles(res.request.body, [], [], [], copyStepFileIdsMap.value); // id

View File

@ -269,7 +269,12 @@
import { getPluginScript, getProtocolList } from '@/api/modules/api-test/common';
import { getCaseDetail } from '@/api/modules/api-test/management';
import { getTransferOptions, stepTransferFile, uploadTempFile } from '@/api/modules/api-test/scenario';
import {
getTransferOptions,
scenarioCopyStepFiles,
stepTransferFile,
uploadTempFile,
} from '@/api/modules/api-test/scenario';
import { useAppStore } from '@/store';
import { characterLimit } from '@/utils';
import { scrollIntoView } from '@/utils/dom';
@ -400,6 +405,7 @@
errorMessageInfo: {},
};
const requestVModel = ref<RequestParam>(defaultApiParams);
const copyStepFileIdsMap = ref<Record<string, any>>({});
const _stepType = computed(() => {
if (activeStep.value) {
return getStepType(activeStep.value);
@ -799,7 +805,8 @@
requestVModel.value.body,
undefined,
props.fileParams?.uploadFileIds || requestVModel.value.uploadFileIds, // case requestVModel
props.fileParams?.linkFileIds || requestVModel.value.linkFileIds // case requestVModel
props.fileParams?.linkFileIds || requestVModel.value.linkFileIds, // case requestVModel
copyStepFileIdsMap.value
);
}
requestParams = {
@ -989,7 +996,26 @@
const res = await getCaseDetail(activeStep.value?.resourceId || '');
let parseRequestBodyResult;
if (res.protocol === 'HTTP') {
parseRequestBodyResult = parseRequestBodyFiles(res.request.body); // id
if (
(activeStep.value?.copyFromStepId || activeStep.value?.refType === ScenarioStepRefType.COPY) &&
activeStep.value?.isNew
) {
//
const fileIds = parseRequestBodyFiles(res.request.body, [], [], []).uploadFileIds;
if (fileIds.length > 0) {
copyStepFileIdsMap.value = await scenarioCopyStepFiles({
copyFromStepId: activeStep.value?.copyFromStepId,
resourceId: activeStep.value?.resourceId,
stepType: activeStep.value?.stepType,
refType: activeStep.value?.refType,
isTempFile: false, // true
fileIds,
});
}
parseRequestBodyFiles(res.request.body, [], [], [], copyStepFileIdsMap.value);
} else {
parseRequestBodyResult = parseRequestBodyFiles(res.request.body, [], [], [], copyStepFileIdsMap.value); // id
}
}
requestVModel.value = {
responseActiveTab: ResponseComposition.BODY,

View File

@ -289,6 +289,7 @@
originProjectId: node.projectId,
id: node.isQuoteScenarioStep ? node.id : id, // id id
uniqueId: id,
isNew: true,
};
});
} else {

View File

@ -943,14 +943,17 @@
if (node.config.protocol === 'HTTP' && (stepDetail as RequestParam)?.body) {
if (node.copyFromStepId || node.refType === ScenarioStepRefType.COPY) {
//
const fileIds = parseRequestBodyFiles((stepDetail as RequestParam).body, [], [], []).uploadFileIds;
if (fileIds.length > 0) {
newFileRes = await scenarioCopyStepFiles({
copyFromStepId,
resourceId: node.resourceId,
stepType: node.stepType,
refType: node.refType,
isTempFile: !!stepDetail, // true
fileIds: parseRequestBodyFiles((stepDetail as RequestParam).body, [], [], []).uploadFileIds,
fileIds,
});
}
parseRequestBodyFiles((stepDetail as RequestParam).body, [], [], [], newFileRes);
} else {
parseRequestBodyResult = parseRequestBodyFiles((stepDetail as RequestParam).body, [], [], [], newFileRes); // id

View File

@ -68,14 +68,17 @@ export default function useStepOperation({
if (step.config.protocol === 'HTTP' && res.body) {
if ((step.copyFromStepId || step.refType === ScenarioStepRefType.COPY) && step.isNew) {
// 复制的步骤需要复制文件
const fileIds = parseRequestBodyFiles((res as RequestParam).body, [], [], []).uploadFileIds;
if (fileIds.length > 0) {
newFileRes = await scenarioCopyStepFiles({
copyFromStepId: step.copyFromStepId,
resourceId: step.resourceId,
stepType: step.stepType,
refType: step.refType,
isTempFile: false, // 复制未保存的步骤时 true
fileIds: parseRequestBodyFiles((res as RequestParam).body, [], [], []).uploadFileIds,
fileIds,
});
}
parseRequestBodyFiles(res.body, [], [], [], newFileRes);
} else {
parseRequestBodyResult = parseRequestBodyFiles(res.body, [], [], [], newFileRes); // 解析请求体中的文件,将详情中的文件 id 集合收集,更新时以判断文件是否删除以及是否新上传的文件