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

View File

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

View File

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

View File

@ -193,33 +193,13 @@ export const caseStatusOptions = [
{ label: 'apiTestManagement.done', value: RequestCaseStatus.DONE }, { label: 'apiTestManagement.done', value: RequestCaseStatus.DONE },
]; ];
// 断言 参数表格默认行的值 // 断言xpath默认行的值
export const defaultAssertParamsItem: ResponseAssertionItem = { export const xpathAssertParamsItem: ResponseAssertionItem = {
expression: '', expression: '',
condition: RequestAssertionCondition.EQUALS,
expectedValue: '', expectedValue: '',
enable: true, enable: true,
extractType: RequestExtractExpressionEnum.X_PATH, extractType: RequestExtractExpressionEnum.X_PATH,
}; valid: true,
// 断言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,
}; };
// @desc 断言的字段xpath和上边的defaultExtractParamItem不匹配所以添加此类型为了保存参数过滤正确 // @desc 断言的字段xpath和上边的defaultExtractParamItem不匹配所以添加此类型为了保存参数过滤正确
export const assertDefaultParamsItem: ResponseAssertionItem = { export const assertDefaultParamsItem: ResponseAssertionItem = {
@ -261,6 +241,20 @@ export const responseAssertionTypeMap: Record<string, string> = {
[FullResponseAssertionType.SCRIPT]: 'apiTestManagement.script', [FullResponseAssertionType.SCRIPT]: 'apiTestManagement.script',
[FullResponseAssertionType.VARIABLE]: 'apiTestManagement.variable', [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 = [ export const extractTypeOptions = [
// 全局参数,暂时不上 // 全局参数,暂时不上

View File

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

View File

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