feat(接口测试): 请求参数的参数名称唯一的校验(前置,后置)

This commit is contained in:
teukkk 2024-04-15 19:11:26 +08:00 committed by Craftsman
parent 9a1fc5a1f5
commit 27016d1014
6 changed files with 55 additions and 10 deletions

View File

@ -305,6 +305,7 @@ export type ExecuteConditionProcessor = Partial<
export interface ExecuteConditionConfig {
enableGlobal?: boolean; // 是否启用全局前/后置 默认为 true
processors: ExecuteConditionProcessor[];
activeItemId?: number;
}
// 执行请求-断言配置子项
export type ExecuteAssertionItem = ResponseAssertionCommon &

View File

@ -727,6 +727,7 @@ if (!result){
title: 'apiTestDebug.paramName',
dataIndex: 'key',
slotName: 'key',
needValidRepeat: true,
},
{
title: 'apiTestDebug.extractValueByColumn',
@ -767,6 +768,7 @@ if (!result){
title: 'apiTestDebug.paramName',
dataIndex: 'variableName',
slotName: 'key',
needValidRepeat: true,
width: 150,
},
{

View File

@ -22,7 +22,7 @@
<conditionList
v-model:list="data"
:disabled="props.disabled"
:active-id="activeItem.id"
:active-id="activeItemId"
:show-associated-scene="props.showAssociatedScene"
:show-pre-post-request="props.showPrePostRequest"
@active-change="handleListActiveChange"
@ -87,6 +87,7 @@
required: true,
});
const activeItem = ref<ExecuteConditionProcessor>(data.value[0]);
const activeItemId = computed(() => activeItem.value?.id);
function handleListActiveChange(item: ExecuteConditionProcessor) {
activeItem.value = item;
@ -109,8 +110,8 @@
* 删除列表项
*/
function deleteListItem(id: string | number) {
data.value = data.value.filter((precondition) => precondition.id !== activeItem.value.id);
if (activeItem.value.id === id) {
data.value = data.value.filter((precondition) => precondition.id !== activeItemId.value);
if (activeItemId.value === id) {
[activeItem.value] = data.value;
}
emit('change');
@ -244,6 +245,10 @@
[activeItem.value] = data.value;
}
});
defineExpose({
activeItemId,
});
</script>
<style lang="less" scoped></style>

View File

@ -1361,6 +1361,12 @@
}
}
function setChildErrorMessage(key: number | string, listItem: TabErrorMessage) {
if (requestVModel.value.errorMessageInfo) {
requestVModel.value.errorMessageInfo[requestVModel.value.activeTab][key] = cloneDeep(listItem);
}
}
function changeTabErrorMessageList(tabKey: string, formErrorMessageList: string[]) {
if (!requestVModel.value.errorMessageInfo) return;
const label = contentTabList.value.find((item) => item.value === tabKey)?.label ?? '';
@ -1369,11 +1375,13 @@
label,
messageList: formErrorMessageList,
};
// TODO: sql sql
initErrorMessageInfoItem(requestVModel.value.activeTab);
if (requestVModel.value.activeTab === RequestComposition.BODY) {
initErrorMessageInfoItem(RequestComposition.BODY);
requestVModel.value.errorMessageInfo[RequestComposition.BODY][requestVModel.value.body.bodyType] =
cloneDeep(listItem);
setChildErrorMessage(requestVModel.value.body.bodyType, listItem);
} else if (requestVModel.value.activeTab === RequestComposition.POST_CONDITION) {
setChildErrorMessage(requestVModel.value.children[0].postProcessorConfig.activeItemId as number, listItem);
} else if (requestVModel.value.activeTab === RequestComposition.PRECONDITION) {
setChildErrorMessage(requestVModel.value.children[0].preProcessorConfig.activeItemId as number, listItem);
} else {
requestVModel.value.errorMessageInfo[requestVModel.value.activeTab] = cloneDeep(listItem);
}
@ -1389,10 +1397,21 @@
if (!requestVModel.value.errorMessageInfo) return;
const flattenedMessages: { label: string; messageList: string[] }[] = [];
const { errorMessageInfo } = requestVModel.value;
Object.values(errorMessageInfo).forEach((item) => {
const label = item.label || (Object.values(item)[0] && Object.values(item)[0].label);
Object.entries(errorMessageInfo).forEach(([key, item]) => {
const label = item.label || Object.values(item)[0]?.label;
//
if ([RequestComposition.POST_CONDITION as string, RequestComposition.PRECONDITION as string].includes(key)) {
const processorIds = requestVModel.value.children[0][
key === RequestComposition.POST_CONDITION ? 'postProcessorConfig' : 'preProcessorConfig'
].processors.map((processorItem) => String(processorItem.id));
Object.entries(item).forEach(([childKey, childItem]) => {
if (!processorIds.includes(childKey)) {
childItem.messageList = [];
}
});
}
const messageList: string[] =
item.messageList || [...new Set(Object.values(item).flatMap((bodyType) => bodyType.messageList))] || [];
item.messageList || [...new Set(Object.values(item).flatMap((child) => child.messageList))] || [];
if (messageList.length) {
flattenedMessages.push({ label, messageList: [...new Set(messageList)] });
}

View File

@ -1,5 +1,6 @@
<template>
<condition
ref="conditionRef"
v-model:list="innerConfig.processors"
:condition-types="conditionTypes"
add-text="apiTestDebug.postCondition"
@ -71,6 +72,14 @@
}
return [RequestConditionProcessor.SCRIPT];
});
const conditionRef = ref<InstanceType<typeof condition>>();
watch(
() => conditionRef.value?.activeItemId,
(val) => {
innerConfig.value.activeItemId = val;
}
);
</script>
<style lang="less" scoped></style>

View File

@ -1,5 +1,6 @@
<template>
<condition
ref="conditionRef"
v-model:list="innerConfig.processors"
:disabled="props.disabled"
:condition-types="conditionTypes"
@ -62,6 +63,14 @@
//
return [RequestConditionProcessor.SCRIPT, RequestConditionProcessor.TIME_WAITING];
});
const conditionRef = ref<InstanceType<typeof condition>>();
watch(
() => conditionRef.value?.activeItemId,
(val) => {
innerConfig.value.activeItemId = val;
}
);
</script>
<style lang="less" scoped></style>