fix(断言): 断言多余配置清除

This commit is contained in:
baiqi 2024-08-20 14:13:24 +08:00 committed by Craftsman
parent 6056cb76d5
commit 1faebb0b2c
6 changed files with 39 additions and 57 deletions

View File

@ -19,7 +19,7 @@
:scroll="{ minWidth: '100%' }"
:default-param-item="jsonPathDefaultParamItem"
@change="(data:any[],isInit?: boolean) => handleChange(data, ResponseBodyAssertionType.JSON_PATH,isInit)"
@more-action-select="(e,r)=> handleExtractParamMoreActionSelect(e,r as ExpressionConfig)"
@more-action-select="(e, r) => handleExtractParamMoreActionSelect(e, r)"
>
<template #expression="{ record, rowIndex }">
<a-popover
@ -123,9 +123,9 @@
:selectable="true"
:columns="xPathColumns"
:scroll="{ minWidth: '100%' }"
:default-param-item="defaultAssertParamsItem"
:default-param-item="xpathAssertParamsItem"
@change="(data:any[],isInit?: boolean) => handleChange(data, ResponseBodyAssertionType.XPATH,isInit)"
@more-action-select="(e,r)=> handleExtractParamMoreActionSelect(e,r as ExpressionConfig)"
@more-action-select="(e, r) => handleExtractParamMoreActionSelect(e, r)"
>
<template #expression="{ record, rowIndex }">
<a-popover
@ -271,7 +271,7 @@
:scroll="{ minWidth: '100%' }"
:default-param-item="regexDefaultParamItem"
@change="(data) => handleChange(data, ResponseBodyAssertionType.REGEX)"
@more-action-select="(e,r)=> handleExtractParamMoreActionSelect(e,r as ExpressionConfig)"
@more-action-select="(e, r) => handleExtractParamMoreActionSelect(e, r)"
>
<template #expression="{ record, rowIndex }">
<a-popover
@ -378,10 +378,9 @@
import { RequestExtractExpressionEnum, ResponseBodyAssertionType } from '@/enums/apiEnum';
import {
defaultAssertParamsItem,
defaultExtractParamItem,
jsonPathDefaultParamItem,
regexDefaultParamItem,
xpathAssertParamsItem,
} from '@/views/api-test/components/config';
const { t } = useI18n();
@ -432,7 +431,7 @@
// const disabledExpressionSuffix = ref(false);
export type ExpressionConfig = (RegexExtract | JSONPathExtract | XPathExtract) & Record<string, any>;
const activeRecord = ref({ ...defaultExtractParamItem }); //
const activeRecord = ref<any>({ ...xpathAssertParamsItem, id: '' }); //
const responseRadios = [
{ label: 'ms.assertion.jsonPath', value: ResponseBodyAssertionType.JSON_PATH },
@ -817,7 +816,7 @@
/**
* 处理提取参数表格更多操作
*/
function handleExtractParamMoreActionSelect(event: ActionsItem, record: ExpressionConfig) {
function handleExtractParamMoreActionSelect(event: ActionsItem, record: Record<string, any>) {
activeRecord.value = { ...record };
if (event.eventTag === 'copy') {
copyItem(record);
@ -826,7 +825,7 @@
}
}
function showFastExtraction(record: ExpressionConfig) {
function showFastExtraction(record: Record<string, any>) {
if (props.disabled || !props.response) return;
activeRecord.value = { ...record };
fastExtractionVisible.value = true;

View File

@ -314,7 +314,6 @@
regexAssertion: {
assertions: [],
},
bodyAssertionDataByType: {},
});
break;
//

View File

@ -185,6 +185,7 @@ export interface ResponseAssertionItem {
expression: string;
enable?: boolean;
extractType?: RequestExtractExpressionEnum;
valid?: boolean;
}
// 断言-JSONPath断言子项
export type ResponseJSONPathAssertionItem = ResponseAssertionItem;
@ -257,21 +258,21 @@ export interface ExpressionCommonConfig {
enable: boolean; // 是否启用
expression: string;
extractType: ExpressionType; // 表达式类型
variableName: string;
variableType: RequestExtractEnvType;
resultMatchingRule: RequestExtractResultMatchingRule; // 结果匹配规则
resultMatchingRuleNum: number; // 匹配第几条结果
variableName?: string;
variableType?: RequestExtractEnvType;
resultMatchingRule?: RequestExtractResultMatchingRule; // 结果匹配规则
resultMatchingRuleNum?: number; // 匹配第几条结果
}
// 正则提取配置
export interface RegexExtract extends ExpressionCommonConfig {
expressionMatchingRule: RequestExtractExpressionRuleType; // 正则表达式匹配规则
extractScope: RequestExtractScope; // 正则提取范围
expressionMatchingRule?: RequestExtractExpressionRuleType; // 正则表达式匹配规则
extractScope?: RequestExtractScope; // 正则提取范围
}
// JSONPath提取配置
export type JSONPathExtract = ExpressionCommonConfig;
// XPath提取配置
export interface XPathExtract extends ExpressionCommonConfig {
responseFormat: ResponseBodyXPathAssertionFormat; // 响应格式
responseFormat?: ResponseBodyXPathAssertionFormat; // 响应格式
}
// 执行请求-前后置操作-参数提取处理器
export interface ExtractProcessor extends ExecuteConditionProcessorCommon {

View File

@ -193,33 +193,13 @@ export const caseStatusOptions = [
{ label: 'apiTestManagement.done', value: RequestCaseStatus.DONE },
];
// 断言 参数表格默认行的值
export const defaultAssertParamsItem: ResponseAssertionItem = {
// 断言xpath默认行的值
export const xpathAssertParamsItem: ResponseAssertionItem = {
expression: '',
condition: RequestAssertionCondition.EQUALS,
expectedValue: '',
enable: true,
extractType: RequestExtractExpressionEnum.X_PATH,
};
// 断言xpath & reg
export const defaultAssertXpathParamsItem: ResponseAssertionItem = {
expression: '',
enable: true,
};
// 断言 xpath
export const defaultExtractParamItem: ExpressionConfig = {
enable: true,
variableName: '',
variableType: RequestExtractEnvType.TEMPORARY,
extractScope: RequestExtractScope.BODY,
expression: '',
extractType: RequestExtractExpressionEnum.JSON_PATH,
expressionMatchingRule: RequestExtractExpressionRuleType.EXPRESSION,
resultMatchingRule: RequestExtractResultMatchingRule.RANDOM,
resultMatchingRuleNum: 1,
responseFormat: ResponseBodyXPathAssertionFormat.XML,
moreSettingPopoverVisible: false,
valid: true,
};
// @desc 断言的字段xpath和上边的defaultExtractParamItem不匹配所以添加此类型为了保存参数过滤正确
export const assertDefaultParamsItem: ResponseAssertionItem = {
@ -261,6 +241,20 @@ export const responseAssertionTypeMap: Record<string, string> = {
[FullResponseAssertionType.SCRIPT]: 'apiTestManagement.script',
[FullResponseAssertionType.VARIABLE]: 'apiTestManagement.variable',
};
// 提取参数
export const defaultExtractParamItem: ExpressionConfig = {
enable: true,
variableName: '',
variableType: RequestExtractEnvType.TEMPORARY,
extractScope: RequestExtractScope.BODY,
expression: '',
extractType: RequestExtractExpressionEnum.JSON_PATH,
expressionMatchingRule: RequestExtractExpressionRuleType.EXPRESSION,
resultMatchingRule: RequestExtractResultMatchingRule.RANDOM,
resultMatchingRuleNum: 1,
responseFormat: ResponseBodyXPathAssertionFormat.XML,
moreSettingPopoverVisible: false,
};
// 提取类型选项
export const extractTypeOptions = [
// 全局参数,暂时不上

View File

@ -172,10 +172,12 @@
import type { JSONPathExtract, RegexExtract, XPathExtract } from '@/models/apiTest/common';
import { RequestExtractExpressionEnum, RequestExtractExpressionRuleType } from '@/enums/apiEnum';
export type ExtractParamConfig = (RegexExtract | JSONPathExtract | XPathExtract) & Record<string, any>;
const props = withDefaults(
defineProps<{
visible: boolean;
config: (RegexExtract | JSONPathExtract | XPathExtract) & Record<string, any>;
config: ExtractParamConfig;
response?: string; //
isShowMoreSetting?: boolean; //
}>(),
@ -185,11 +187,7 @@
);
const emit = defineEmits<{
(e: 'update:visible', value: boolean): void;
(
e: 'apply',
config: (RegexExtract | JSONPathExtract | XPathExtract) & Record<string, any>,
matchResult: any[] | string
): void;
(e: 'apply', config: ExtractParamConfig, matchResult: any[] | string): void;
}>();
const { t } = useI18n();

View File

@ -10,14 +10,13 @@ import type { MockBody } from '@/models/apiTest/mock';
import { RequestConditionProcessor, RequestParamsType } from '@/enums/apiEnum';
import {
assertDefaultParamsItem,
defaultAssertParamsItem,
defaultBodyParamsItem,
defaultHeaderParamsItem,
defaultKeyValueParamItem,
defaultRequestParamsItem,
jsonPathDefaultParamItem,
regexDefaultParamItem,
xpathAssertParamsItem,
} from './config';
import type { RequestParam } from './requestComposition/index.vue';
@ -253,14 +252,6 @@ export function filterAssertions(assertionConfig: ExecuteAssertionConfig, isExec
}
return {
...assertItem,
bodyAssertionDataByType: {
...assertItem.bodyAssertionDataByType,
assertions: filterKeyValParams(
assertItem?.bodyAssertionDataByType?.assertions || [],
defaultAssertParamsItem,
isExecute
).validParams,
},
regexAssertion: {
...assertItem?.regexAssertion,
assertions: filterKeyValParams(assertItem?.regexAssertion?.assertions || [], regexDefaultParamItem, isExecute)
@ -268,7 +259,7 @@ export function filterAssertions(assertionConfig: ExecuteAssertionConfig, isExec
},
xpathAssertion: {
...assertItem.xpathAssertion,
assertions: filterKeyValParams(assertItem?.xpathAssertion?.assertions || [], assertDefaultParamsItem, isExecute)
assertions: filterKeyValParams(assertItem?.xpathAssertion?.assertions || [], xpathAssertParamsItem, isExecute)
.validParams,
},
jsonPathAssertion: {