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

This commit is contained in:
chenjianxing 2021-01-18 11:12:28 +08:00
parent b024c5da54
commit c53687d37d
4 changed files with 58 additions and 72 deletions

View File

@ -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==='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==='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> <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>
<template v-slot:button> <template v-slot:button>
@ -56,9 +60,6 @@
{{$t('commons.save')}} {{$t('commons.save')}}
</el-button> </el-button>
<ms-run :debug="false" :reportId="reportId" :run-data="runData"
@runRefresh="runRefresh" ref="runTest"/>
</api-base-component> </api-base-component>
</template> </template>

View File

@ -1,5 +1,5 @@
<template> <template>
<div></div> <span></span>
</template> </template>
<script> <script>
import {getUUID, getBodyUploadFiles} from "@/common/js/utils"; import {getUUID, getBodyUploadFiles} from "@/common/js/utils";

View File

@ -92,7 +92,7 @@
</template> </template>
<script> <script>
import {getCurrentProjectID, getUUID} from "../../../../../../common/js/utils"; import {_getBodyUploadFiles, getCurrentProjectID, getUUID} from "../../../../../../common/js/utils";
import {PRIORITY, RESULT_MAP} from "../../model/JsonData"; import {PRIORITY, RESULT_MAP} from "../../model/JsonData";
import MsTag from "../../../../common/components/MsTag"; import MsTag from "../../../../common/components/MsTag";
import MsTipButton from "../../../../common/components/MsTipButton"; import MsTipButton from "../../../../common/components/MsTipButton";
@ -223,6 +223,7 @@
if (this.validate(tmp)) { if (this.validate(tmp)) {
return; return;
} }
tmp.request.body = row.request.body;
let bodyFiles = this.getBodyUploadFiles(tmp); let bodyFiles = this.getBodyUploadFiles(tmp);
tmp.projectId = getCurrentProjectID(); tmp.projectId = getCurrentProjectID();
tmp.active = true; tmp.active = true;
@ -278,37 +279,7 @@
getBodyUploadFiles(row) { getBodyUploadFiles(row) {
let bodyUploadFiles = []; let bodyUploadFiles = [];
row.bodyUploadIds = []; row.bodyUploadIds = [];
let request = row.request; _getBodyUploadFiles(row.request, bodyUploadFiles, row);
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);
}
});
}
});
}
}
return bodyUploadFiles; return bodyUploadFiles;
}, },
} }

View File

@ -303,42 +303,56 @@ export function getBodyUploadFiles(obj, runData) {
let bodyUploadFiles = []; let bodyUploadFiles = [];
obj.bodyUploadIds = []; obj.bodyUploadIds = [];
if (runData) { if (runData) {
runData.forEach(request => { if (runData instanceof Array) {
if (request.body) { runData.forEach(request => {
request.body.kvs.forEach(param => { _getBodyUploadFiles(request, bodyUploadFiles, obj);
if (param.files) { });
param.files.forEach(item => { } else {
if (item.file) { _getBodyUploadFiles(runData, bodyUploadFiles, obj);
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);
}
});
}
});
}
}
});
} }
return bodyUploadFiles; 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 (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);
}
});
}
});
}
}
}