feat(接口测试): 接口&用例复制文件

This commit is contained in:
baiqi 2024-12-10 10:41:10 +08:00 committed by Craftsman
parent 91321faa07
commit 0457508be6
5 changed files with 80 additions and 26 deletions

View File

@ -22,6 +22,7 @@ import {
BatchUpdateDefinitionUrl,
CaseBatchExportLogUrl,
CaseExportLogUrl,
CaseFileCopyUrl,
CasePageUrl,
CaseStatisticsUrl,
caseTableBatchSyncUrl,
@ -32,6 +33,7 @@ import {
CopyMockUrl,
DebugCaseUrl,
DebugDefinitionUrl,
DefinitionFileCopyUrl,
DefinitionMockPageUrl,
DefinitionPageUrl,
DefinitionReferenceUrl,
@ -144,6 +146,7 @@ import {
CheckScheduleParams,
CheckSharePsdType,
CreateImportApiDefinitionScheduleParams,
type DefinitionFileCopyParams,
DefinitionHistoryItem,
DefinitionHistoryPageParams,
DefinitionReferencePageParams,
@ -364,25 +367,10 @@ export function convertJsonSchemaToJson(data: JsonSchema) {
export function jsonSchemaAutoGenerate(data: JsonSchema) {
return MSR.post({ url: JsonSchemaAutoGenerateUrl, data });
}
// 接口定义-用例接口对比-清除本次变更
export function clearThisChange(id: string) {
return MSR.get({ url: `${clearThisChangeUrl}/${id}` });
}
// 接口定义-用例接口对比-忽略每次变更
export function ignoreEveryTimeChange(id: string, ignore: boolean) {
return MSR.get({ url: `${ignoreEveryTimeApiChangeUrl}/${id}`, params: { ignore } });
}
// 接口测试-接口管理-接口用例-批量同步编辑
export function caseTableBatchSync(data: TableQueryParams) {
return MSR.post({ url: caseTableBatchSyncUrl, data });
}
// 接口测试-接口用例-定义对比用例
export function diffDataRequest(id: string) {
return MSR.get({ url: `${diffDataUrl}/${id}` });
}
// 接口测试-接口用例-定义对比用例-同步-获取同步后的用例详情
export function getSyncedCaseDetail(data: diffSyncParams) {
return MSR.post({ url: getSyncedCaseDetailUrl, data });
// 接口定义-文件复制
export function definitionFileCopy(data: DefinitionFileCopyParams) {
return MSR.post({ url: DefinitionFileCopyUrl, data });
}
/**
@ -566,6 +554,36 @@ export function runCase(data: ExecuteRequestParams) {
return MSR.post({ url: RunCaseUrl, data });
}
// 接口定义-用例接口对比-清除本次变更
export function clearThisChange(id: string) {
return MSR.get({ url: `${clearThisChangeUrl}/${id}` });
}
// 接口定义-用例接口对比-忽略每次变更
export function ignoreEveryTimeChange(id: string, ignore: boolean) {
return MSR.get({ url: `${ignoreEveryTimeApiChangeUrl}/${id}`, params: { ignore } });
}
// 接口测试-接口管理-接口用例-批量同步编辑
export function caseTableBatchSync(data: TableQueryParams) {
return MSR.post({ url: caseTableBatchSyncUrl, data });
}
// 接口测试-接口用例-定义对比用例
export function diffDataRequest(id: string) {
return MSR.get({ url: `${diffDataUrl}/${id}` });
}
// 接口测试-接口用例-定义对比用例-同步-获取同步后的用例详情
export function getSyncedCaseDetail(data: diffSyncParams) {
return MSR.post({ url: getSyncedCaseDetailUrl, data });
}
// 接口用例-文件复制
export function caseFileCopy(data: DefinitionFileCopyParams) {
return MSR.post({ url: CaseFileCopyUrl, data });
}
/**
*
*/

View File

@ -40,11 +40,7 @@ export const RecoverOperationHistoryUrl = '/api/definition/operation-history/rec
export const DefinitionReferenceUrl = '/api/definition/get-reference'; // 获取接口引用关系
export const ConvertJsonSchemaToJsonUrl = '/api/definition/json-schema/preview'; // 将json-schema转换为 json 数据
export const JsonSchemaAutoGenerateUrl = '/api/definition/json-schema/auto-generate'; // 将json-schema转换为 json 数据
export const clearThisChangeUrl = '/api/case/api-change/clear'; // 接口定义-变更对比-清除本次变更
export const caseTableBatchSyncUrl = '/api/case/batch/api-change/sync'; // 接口测试-接口管理-接口用例-批量同步
export const ignoreEveryTimeApiChangeUrl = '/api/case/api-change/ignore'; // 接口测试-接口用例-忽略每次接口变更
export const diffDataUrl = '/api/case/api/compare'; // 接口测试-接口用例-定义对比用例
export const getSyncedCaseDetailUrl = '/api/case/api-change/sync'; // 接口测试-接口用例-定义对比用例-同步-获取同步后的用例详情
export const DefinitionFileCopyUrl = '/api/definition/file/copy'; // 接口文件复制
/**
* Mock
@ -101,6 +97,12 @@ export const CaseExportLogUrl = '/api/report/case/export'; // 接口用例导出
export const CaseBatchExportLogUrl = '/api/report/case/batch-export'; // 接口用例批量导出报告日志记录
export const GetCaseBatchExportParamsUrl = '/api/report/case/batch-param'; // 接口用例批量导出报告id集合
export const CaseStatisticsUrl = '/api/case/statistics'; // 用例执行率统计
export const getSyncedCaseDetailUrl = '/api/case/api-change/sync'; // 接口测试-接口用例-定义对比用例-同步-获取同步后的用例详情
export const clearThisChangeUrl = '/api/case/api-change/clear'; // 接口定义-变更对比-清除本次变更
export const caseTableBatchSyncUrl = '/api/case/batch/api-change/sync'; // 接口测试-接口管理-接口用例-批量同步
export const ignoreEveryTimeApiChangeUrl = '/api/case/api-change/ignore'; // 接口测试-接口用例-忽略每次接口变更
export const diffDataUrl = '/api/case/api/compare'; // 接口测试-接口用例-定义对比用例
export const CaseFileCopyUrl = '/api/case/file/copy'; // 接口用例文件复制
/**
*

View File

@ -288,6 +288,12 @@ export interface DefinitionReferencePageParams extends TableQueryParams {
resourceId: string;
}
// 定义-复制文件参数
export interface DefinitionFileCopyParams {
resourceId: string;
fileIds: string[];
}
// 回收站-恢复接口定义参数
export interface ApiDefinitionDeleteParams {
id: string;

View File

@ -123,6 +123,7 @@
import {
addDefinition,
debugDefinition,
definitionFileCopy,
deleteDefinition,
getDefinitionDetail,
getTransferOptions,
@ -376,7 +377,16 @@
}
let parseRequestBodyResult;
if (res.protocol === 'HTTP') {
parseRequestBodyResult = parseRequestBodyFiles(res.request.body, res.response); // id
//
let copyFilesMap: Record<string, any> = {};
const fileIds = parseRequestBodyFiles(res.request.body, [], [], []).uploadFileIds;
if (fileIds.length > 0) {
copyFilesMap = await definitionFileCopy({
resourceId: typeof apiInfo === 'string' ? apiInfo : apiInfo.id,
fileIds,
});
}
parseRequestBodyResult = parseRequestBodyFiles(res.request.body, [], [], [], copyFilesMap); // id
}
let { request } = res;
if (isDebugMock) {

View File

@ -116,6 +116,7 @@
import { localExecuteApiDebug } from '@/api/modules/api-test/common';
import {
addCase,
caseFileCopy,
debugCase,
getDefinitionDetail,
getTransferOptionsCase,
@ -134,6 +135,7 @@
import { RequestCaseStatus, RequestMethods } from '@/enums/apiEnum';
import { casePriorityOptions, defaultResponse } from '@/views/api-test/components/config';
import { parseRequestBodyFiles } from '@/views/api-test/components/utils';
const props = defineProps<{
apiDetail?: RequestParam | ApiDefinitionDetail;
@ -236,9 +238,25 @@
: apiDetailInfo.value),
children: apiDetailInfo.value.children ?? apiDetailInfo.value.request.children,
};
let parseRequestBodyResult;
//
if (isCopy) {
detailForm.value = cloneDeep(record as RequestParam);
if (record?.protocol === 'HTTP') {
//
let copyFilesMap: Record<string, any> = {};
const fileIds = parseRequestBodyFiles(record.request.body, [], [], []).uploadFileIds;
if (fileIds.length > 0) {
copyFilesMap = await caseFileCopy({
resourceId: record.id as string,
fileIds,
});
}
parseRequestBodyResult = parseRequestBodyFiles(record.request.body, [], [], [], copyFilesMap); // id
detailForm.value = {
...cloneDeep(record as RequestParam),
...parseRequestBodyResult,
};
}
detailForm.value.name = `copy_${record?.name}`;
detailForm.value.isCopy = true;
environmentId.value = record?.environmentId ?? environmentId.value;