Skip to content

Commit 3854e77

Browse files
committed
Java: MultiDataSource 解决 APIAuto 帐号共用测试结果导致某些情况下错乱、兼容没有返回 code 的 response JSON、解决回车查不到测试记录等
1 parent 414140e commit 3854e77

File tree

3 files changed

+34
-19
lines changed

3 files changed

+34
-19
lines changed

APIJSON-Java-Server/APIJSONBoot-MultiDataSource/src/main/resources/static/api/apijson/JSONRequest.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,16 +188,24 @@ function toFormData(data) {
188188
return null
189189
}
190190
if (data instanceof Object == false || data instanceof Array) {
191-
alert('toFormData data instanceof Object == false || data instanceof Array ! >> return')
192-
return
191+
// alert('toFormData data instanceof Object == false || data instanceof Array ! >> return')
192+
throw new Error('data must be Object!')
193193
}
194194

195195
var first = true
196196
var ret = ''
197197
for (var key in data) {
198198
var val = data[key]
199-
if (typeof val != 'string') {
200-
val = JSON.stringify(val)
199+
if (val == null) {
200+
val = ''
201+
}
202+
else if (typeof val != 'string') {
203+
try {
204+
val = JSON.stringify(val)
205+
} catch (e) {
206+
console.log(e)
207+
val = new String(val)
208+
}
201209
}
202210
ret += (first ? '' : '&') + encodeURIComponent(key) + '=' + encodeURIComponent(val)
203211
first = false

APIJSON-Java-Server/APIJSONBoot-MultiDataSource/src/main/resources/static/api/apijson/JSONResponse.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ var JSONResponse = {
552552
// };
553553
// }
554554

555-
if (tCode == null) {
555+
if (tStatus == null) { // tCode == null) {
556556
if (rCode != JSONResponse.CODE_SUCCESS && rCode != 200) {
557557
return {
558558
code: JSONResponse.COMPARE_CODE_CHANGE, //未上传对比标准
@@ -602,7 +602,7 @@ var JSONResponse = {
602602
if (find != null) {
603603
return {
604604
code: JSONResponse.COMPARE_EQUAL_EXCEPTION,
605-
msg: '符合异常分支 ' + rCode + (StringUtil.isEmpty(rThrw) ? '' : ' ' + rThrw + ':') + ' ' + StringUtil.trim(find.msg),
605+
msg: '符合异常分支 ' + rCode + (StringUtil.isEmpty(rThrw) ? '' : ' ' + rThrw + ':') + ' ' + StringUtil.trim(find[JSONResponse.KEY_MSG]),
606606
path: folder == null ? '' : folder
607607
};
608608
}
@@ -1268,16 +1268,18 @@ var JSONResponse = {
12681268
standard = {};
12691269
}
12701270

1271-
var code = currentResponse.code;
1271+
var code = currentResponse[JSONResponse.KEY_CODE];
12721272
var thrw = currentResponse.throw;
1273-
var msg = currentResponse.msg;
1273+
var msg = currentResponse[JSONResponse.KEY_MSG];
12741274

12751275
var hasCode = standard.code != null;
12761276
var isCodeChange = noBizCode != true && standard.code != code;
12771277
var exceptions = standard.exceptions || [];
12781278

1279-
delete currentResponse.code; //code必须一致
1280-
delete currentResponse.throw; //throw必须一致
1279+
// delete currentResponse[JSONResponse.KEY_CODE]; //code必须一致
1280+
// delete currentResponse.throw; //throw必须一致
1281+
currentResponse[JSONResponse.KEY_CODE] = null; //code必须一致
1282+
currentResponse.throw = null; //throw必须一致
12811283

12821284
var find = false;
12831285
if (isCodeChange && hasCode) { // 走异常分支
@@ -1291,14 +1293,15 @@ var JSONResponse = {
12911293
}
12921294

12931295
if (find) {
1294-
delete currentResponse.msg;
1296+
// delete currentResponse[JSONResponse.KEY_MSG];
1297+
currentResponse[JSONResponse.KEY_MSG] = null;
12951298
}
12961299
}
12971300

12981301
var stddObj = isML ? (isCodeChange && hasCode ? standard : JSONResponse.updateStandard(standard, currentResponse)) : {};
12991302

13001303
// if (noBizCode != true) {
1301-
currentResponse.code = code;
1304+
currentResponse[JSONResponse.KEY_CODE] = code;
13021305
currentResponse.throw = thrw;
13031306
// }
13041307

@@ -1312,7 +1315,7 @@ var JSONResponse = {
13121315
stddObj.throw = thrw;
13131316
}
13141317
else { // 走异常分支
1315-
currentResponse.msg = msg;
1318+
currentResponse[JSONResponse.KEY_MSG] = msg;
13161319

13171320
if (find != true) {
13181321
exceptions.push({

APIJSON-Java-Server/APIJSONBoot-MultiDataSource/src/main/resources/static/api/js/main.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3374,7 +3374,7 @@ https://github.com/Tencent/APIJSON/issues
33743374
'documentId': isEditResponse ? did : undefined,
33753375
'randomId': 0,
33763376
'host': baseUrl,
3377-
// 'testAccountId': currentAccountId,
3377+
'testAccountId': currentAccountId,
33783378
'response': isEditResponse ? rawInputStr : rawRspStr,
33793379
'standard': isML || isEditResponse ? JSON.stringify(isEditResponse ? commentObj : stddObj) : undefined,
33803380
// 没必要,直接都在请求中说明,查看也方便 'detail': (isEditResponse ? App.getExtraComment() : null) || ((App.currentRemoteItem || {}).TestRecord || {}).detail,
@@ -5375,7 +5375,7 @@ https://github.com/Tencent/APIJSON/issues
53755375
'documentId@': '/Document/id',
53765376
'userId': userId,
53775377
'host': StringUtil.isEmpty(baseUrl, true) ? null : baseUrl,
5378-
// 'testAccountId': this.getCurrentAccountId(),
5378+
'testAccountId': this.getCurrentAccountId(),
53795379
'randomId': 0,
53805380
// 'reportId': reportId <= 0 ? null : reportId,
53815381
// 'invalid': reportId == null ? 0 : null,
@@ -5858,7 +5858,7 @@ https://github.com/Tencent/APIJSON/issues
58585858
'documentId@': '/Document/id',
58595859
'userId': userId,
58605860
'host': StringUtil.isEmpty(baseUrl, true) ? null : baseUrl,
5861-
// 'testAccountId': this.getCurrentAccountId(),
5861+
'testAccountId': this.getCurrentAccountId(),
58625862
'randomId': 0,
58635863
'reportId': reportId <= 0 ? null : reportId,
58645864
'invalid': reportId == null ? 0 : null,
@@ -6113,6 +6113,7 @@ https://github.com/Tencent/APIJSON/issues
61136113
const cri = this.currentRemoteItem || {}
61146114
const chain = cri.Chain || {}
61156115
const cId = chain.id || 0
6116+
const currentAccountId = this.getCurrentAccountId();
61166117

61176118
var req = {
61186119
'[]': {
@@ -6127,7 +6128,7 @@ https://github.com/Tencent/APIJSON/issues
61276128
},
61286129
'TestRecord': {
61296130
'randomId@': '/Random/id',
6130-
// 'testAccountId': this.getCurrentAccountId(),
6131+
'testAccountId': currentAccountId,
61316132
'host': StringUtil.isEmpty(baseUrl, true) ? null : baseUrl,
61326133
'@order': 'date-'
61336134
},
@@ -6143,7 +6144,7 @@ https://github.com/Tencent/APIJSON/issues
61436144
},
61446145
'TestRecord': {
61456146
'randomId@': '/Random/id',
6146-
// 'testAccountId': this.getCurrentAccountId(),
6147+
'testAccountId': currentAccountId,
61476148
'host': StringUtil.isEmpty(baseUrl, true) ? null : baseUrl,
61486149
'@order': 'date-'
61496150
}
@@ -8440,6 +8441,9 @@ Content-Type: ` + contentType) + (StringUtil.isEmpty(headerStr, true) ? '' : hea
84408441

84418442
if (isEnter) { // enter
84428443
if (isFilter) {
8444+
if (['chainGroup', 'caseGroup', 'testCase', 'random', 'randomSub'].indexOf(type) >= 0) {
8445+
this.reportId = 0;
8446+
}
84438447
this.onFilterChange(type)
84448448
return
84458449
}
@@ -10961,7 +10965,7 @@ Content-Type: ` + contentType) + (StringUtil.isEmpty(headerStr, true) ? '' : hea
1096110965
}
1096210966

1096310967
// value RANDOM_DB
10964-
const value = line2.substring(index + ': '.length);
10968+
const value = StringUtil.trim(line2.substring(index + ': '.length));
1096510969

1096610970
var invoke = function (val, which, p_k, pathKeys, key, lastKeyInPath) {
1096710971
try {

0 commit comments

Comments
 (0)