提交 c53687d3 编写于 作者: C chenjianxing

fix: 接口测试文件上传失败

上级 b024c5da
......@@ -24,6 +24,10 @@
<el-tag size="mini" style="margin-left: 20px" v-if="request.referenced==='Deleted'" type="danger">{{$t('api_test.automation.reference_deleted')}}</el-tag>
<el-tag size="mini" style="margin-left: 20px" v-if="request.referenced==='Copy'">{{ $t('commons.copy') }}</el-tag>
<el-tag size="mini" style="margin-left: 20px" v-if="request.referenced ==='REF'">{{ $t('api_test.scenario.reference') }}</el-tag>
<ms-run :debug="false" :reportId="reportId" :run-data="runData"
@runRefresh="runRefresh" ref="runTest"/>
</template>
<template v-slot:button>
......@@ -56,9 +60,6 @@
{{$t('commons.save')}}
</el-button>
<ms-run :debug="false" :reportId="reportId" :run-data="runData"
@runRefresh="runRefresh" ref="runTest"/>
</api-base-component>
</template>
......
<template>
<div></div>
<span></span>
</template>
<script>
import {getUUID, getBodyUploadFiles} from "@/common/js/utils";
......
......@@ -92,7 +92,7 @@
</template>
<script>
import {getCurrentProjectID, getUUID} from "../../../../../../common/js/utils";
import {_getBodyUploadFiles, getCurrentProjectID, getUUID} from "../../../../../../common/js/utils";
import {PRIORITY, RESULT_MAP} from "../../model/JsonData";
import MsTag from "../../../../common/components/MsTag";
import MsTipButton from "../../../../common/components/MsTipButton";
......@@ -223,6 +223,7 @@
if (this.validate(tmp)) {
return;
}
tmp.request.body = row.request.body;
let bodyFiles = this.getBodyUploadFiles(tmp);
tmp.projectId = getCurrentProjectID();
tmp.active = true;
......@@ -278,37 +279,7 @@
getBodyUploadFiles(row) {
let bodyUploadFiles = [];
row.bodyUploadIds = [];
let request = row.request;
if (request.body && request.body.kvs) {
request.body.kvs.forEach(param => {
if (param.files) {
param.files.forEach(item => {
if (item.file) {
let fileId = getUUID().substring(0, 8);
item.name = item.file.name;
item.id = fileId;
row.bodyUploadIds.push(fileId);
bodyUploadFiles.push(item.file);
}
});
}
});
if (request.body.binary) {
request.body.binary.forEach(param => {
if (param.files) {
param.files.forEach(item => {
if (item.file) {
let fileId = getUUID().substring(0, 8);
item.name = item.file.name;
item.id = fileId;
row.bodyUploadIds.push(fileId);
bodyUploadFiles.push(item.file);
}
});
}
});
}
}
_getBodyUploadFiles(row.request, bodyUploadFiles, row);
return bodyUploadFiles;
},
}
......
......@@ -303,42 +303,56 @@ export function getBodyUploadFiles(obj, runData) {
let bodyUploadFiles = [];
obj.bodyUploadIds = [];
if (runData) {
runData.forEach(request => {
if (request.body) {
request.body.kvs.forEach(param => {
if (param.files) {
param.files.forEach(item => {
if (item.file) {
if (!item.id) {
let fileId = getUUID().substring(0, 12);
item.name = item.file.name;
item.id = fileId;
}
obj.bodyUploadIds.push(item.id);
bodyUploadFiles.push(item.file);
}
});
if (runData instanceof Array) {
runData.forEach(request => {
_getBodyUploadFiles(request, bodyUploadFiles, obj);
});
} else {
_getBodyUploadFiles(runData, bodyUploadFiles, obj);
}
}
return bodyUploadFiles;
}
export function _getBodyUploadFiles(request, bodyUploadFiles, obj) {
let body = null;
if (request.hashTree && request.hashTree.length > 0 && request.hashTree[0].body) {
body = request.hashTree[0].body;
} else if (request.body) {
body = request.body;
}
if (body) {
body.kvs.forEach(param => {
if (param.files) {
param.files.forEach(item => {
if (item.file) {
if (!item.id) {
let fileId = getUUID().substring(0, 12);
item.name = item.file.name;
item.id = fileId;
}
obj.bodyUploadIds.push(item.id);
bodyUploadFiles.push(item.file);
}
});
if (request.body.binary) {
request.body.binary.forEach(param => {
if (param.files) {
param.files.forEach(item => {
if (item.file) {
if (!item.id) {
let fileId = getUUID().substring(0, 12);
item.name = item.file.name;
item.id = fileId;
}
obj.bodyUploadIds.push(item.id);
bodyUploadFiles.push(item.file);
}
});
}
});
if (body.binary) {
body.binary.forEach(param => {
if (param.files) {
param.files.forEach(item => {
if (item.file) {
if (!item.id) {
let fileId = getUUID().substring(0, 12);
item.name = item.file.name;
item.id = fileId;
}
obj.bodyUploadIds.push(item.id);
bodyUploadFiles.push(item.file);
}
});
}
}
});
});
}
}
return bodyUploadFiles;
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册