feat(接口测试): 接口保留最后一次测试结果并回显

--story=1010697 --user=赵勇 接口TEST保留最近一次测试记录 https://www.tapd.cn/55049933/s/1320069
This commit is contained in:
fit2-zhao 2022-12-27 17:58:31 +08:00 committed by fit2-zhao
parent 02641e86c0
commit 5018215989
13 changed files with 40 additions and 229 deletions

View File

@ -24,11 +24,8 @@ public interface ExtApiDefinitionExecResultMapper {
ApiDefinitionExecResultWithBLOBs selectMaxResultByResourceIdAndType(String resourceId, String type);
long countByProjectIDAndCreateInThisWeek(@Param("projectId") String projectId, @Param("version") String version, @Param("firstDayTimestamp") long firstDayTimestamp, @Param("lastDayTimestamp") long lastDayTimestamp);
long countByTestCaseIDInProject(String projectId);
List<ExecutedCaseInfoResult> findFailureCaseInTestPlanByProjectIDAndExecuteTimeAndLimitNumber(@Param("projectId") String projectId, @Param("versionId") String version, @Param("selectFunctionCase") boolean selectFunctionCase, @Param("startTimestamp") long startTimestamp, @Param("limitNumber") int limitNumber);
String selectExecResult(String resourceId);
@ -37,8 +34,6 @@ public interface ExtApiDefinitionExecResultMapper {
List<ApiDefinitionExecResult> selectStatusByIdList(@Param("ids") Collection<String> values);
List<ApiDefinitionExecResult> selectApiResultByProjectId(String projectId);
void update(@Param("ids") List<String> ids);
@InsertProvider(type = ExtApiDefinitionExecResultProvider.class, method = "insertListSql")

View File

@ -33,22 +33,6 @@
AND create_time BETWEEN #{firstDayTimestamp} AND #{lastDayTimestamp}
</select>
<select id="countByTestCaseIDInProject" resultType="java.lang.Long">
SELECT count(id) AS countNumber
FROM api_case_execution_info
WHERE source_id IN (
SELECT testCase.id
FROM api_test_case testCase
WHERE testCase.project_id = #{projectId}
)
OR source_id IN (SELECT id
FROM test_plan_api_case
WHERE api_case_id IN (
SELECT testCase.id
FROM api_test_case testCase
WHERE testCase.project_id = #{projectId}))
</select>
<select id="selectDistinctStatusByReportId" resultType="java.lang.String">
SELECT DISTINCT status
FROM api_definition_exec_result
@ -181,19 +165,6 @@
</foreach>
</select>
<select id="selectApiResultByProjectId" resultType="io.metersphere.base.domain.ApiDefinitionExecResult">
select *
from api_definition_exec_result t
left join `user` t1 ON t.user_id = t1.id
left join test_resource_pool t2 on t.actuator = t2.id
left join api_definition t3 on t.resource_id = t3.id
left join api_test_case t4 on t4.id = t.resource_id
left join test_plan_api_case t5 on t.resource_id = t5.id
left join test_plan t6 on t5.test_plan_id = t6.id
where to_days(FROM_UNIXTIME(t.create_time / 1000)) = to_days(now())
and (t3.project_id = #{projectId} OR t4.project_id = #{projectId} OR t6.project_id = #{projectId})
and t.`status` in ('RUNNING', 'PENDING')
</select>
<select id="selectForPlanReport" resultType="io.metersphere.dto.PlanReportCaseDTO">
select status from api_definition_exec_result
where id in

View File

@ -1,11 +1,9 @@
package io.metersphere.controller.definition;
import io.metersphere.service.definition.ApiDefinitionExecResultService;
import io.metersphere.base.domain.ApiDefinitionExecResultWithBLOBs;
import io.metersphere.dto.PlanReportCaseDTO;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import io.metersphere.service.definition.ApiDefinitionExecResultService;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
@ -27,4 +25,9 @@ public class ApiDefinitionExecResultController {
public Map<String, String> selectReportResultByReportIds(@RequestBody List<String> apiReportIds) {
return apiDefinitionExecResultService.selectReportResultByReportIds(apiReportIds);
}
@GetMapping("/last-result/{resourceId}")
public ApiDefinitionExecResultWithBLOBs selectLastResult(@PathVariable String resourceId) {
return apiDefinitionExecResultService.getLastResult(resourceId);
}
}

View File

@ -477,4 +477,8 @@ public class ApiDefinitionExecResultService {
public void updateByExampleSelective(ApiDefinitionExecResultWithBLOBs resultWithBLOBs, ApiDefinitionExecResultExample resultExample) {
apiDefinitionExecResultMapper.updateByExampleSelective(resultWithBLOBs, resultExample);
}
public ApiDefinitionExecResultWithBLOBs getLastResult(String testId) {
return extApiDefinitionExecResultMapper.selectMaxResultByResourceId(testId);
}
}

View File

@ -9,3 +9,18 @@ export function getApiReportDetail(id) {
let url = '/api/definition/report/get/' + id;
return get(url);
}
export function getLastResult(id) {
return get(`/api/definition/exec/result/last-result/${id}`);
}
export function getLastResultDetail(id, _this) {
if (id) {
getLastResult(id).then((response) => {
if (response.data && response.data.content) {
let data = JSON.parse(response.data.content);
_this.responseData = data;
}
});
}
}

View File

@ -67,7 +67,6 @@
</template>
<script>
import { getApiReportDetail } from '@/api/definition-report';
import MsResponseResult from '../response/ResponseResult';
import MsRequestMetric from '../response/RequestMetric';
import { getUUID } from 'metersphere-frontend/src/utils';
@ -120,7 +119,6 @@ export default {
options: [],
responseData: { type: 'TCP', responseResult: {}, subRequestResults: [] },
loading: false,
debugResultId: '',
runData: [],
headers: [],
reportId: '',
@ -130,33 +128,7 @@ export default {
};
},
created() {
if (this.testCase) {
if (this.testCase.id) {
//
getApiReportDetail(this.testCase.id).then((response) => {
if (response.data) {
let data = JSON.parse(response.data.content);
this.responseData = data;
}
});
}
this.request = this.testCase.request;
if (this.request) {
this.debugForm.method = this.request.method;
if (this.request.url) {
this.debugForm.url = this.request.url;
} else {
this.debugForm.url = this.request.path;
}
}
} else {
this.request = createComponent('DubboSampler');
}
},
watch: {
debugResultId() {
this.getResult();
},
this.request = createComponent('DubboSampler');
},
methods: {
handleCommand(e) {

View File

@ -90,7 +90,6 @@
</template>
<script>
import { getApiReportDetail } from '@/api/definition-report';
import MsApiRequestForm from '../request/http/ApiHttpRequestForm';
import MsResponseResult from '../response/ResponseResult';
import MsRequestMetric from '../response/RequestMetric';
@ -109,7 +108,7 @@ import { mergeRequestDocumentData } from '@/business/definition/api-definition';
import { execStop } from '@/api/scenario';
export default {
name: 'ApiConfig',
name: 'DebugHttpPage',
components: {
MsRequestResultTail,
MsResponseResult,
@ -125,14 +124,6 @@ export default {
scenario: Boolean,
},
data() {
let validateURL = (rule, value, callback) => {
try {
new URL(this.debugForm.url);
callback();
} catch (e) {
callback(this.$t('api_test.request.url_invalid'));
}
};
return {
rules: {
method: [
@ -149,16 +140,12 @@ export default {
message: this.$t('commons.input_limit', [1, 500]),
trigger: 'blur',
},
/*
{validator: validateURL, trigger: 'blur'}
*/
],
},
debugForm: { method: REQ_METHOD[0].id, environmentId: '' },
options: [],
responseData: { type: 'HTTP', responseResult: {}, subRequestResults: [] },
loading: false,
debugResultId: '',
runData: [],
reportId: '',
reqOptions: REQ_METHOD,
@ -168,33 +155,7 @@ export default {
};
},
created() {
if (this.testCase) {
if (this.testCase.id) {
//
getApiReportDetail(this.testCase.id).then((response) => {
if (response.data) {
let data = JSON.parse(response.data.content);
this.responseData = data;
}
});
}
this.request = this.testCase.request;
if (this.request) {
this.debugForm.method = this.request.method;
if (this.request.url) {
this.debugForm.url = this.request.url;
} else {
this.debugForm.url = this.request.path;
}
}
} else {
this.createHttp();
}
},
watch: {
debugResultId() {
this.getResult();
},
this.createHttp();
},
methods: {
hasPermission,

View File

@ -68,7 +68,6 @@
</template>
<script>
import { getApiReportDetail } from '@/api/definition-report';
import MsResponseResult from '../response/ResponseResult';
import MsRequestMetric from '../response/RequestMetric';
import { getUUID } from 'metersphere-frontend/src/utils';
@ -123,7 +122,6 @@ export default {
options: [],
responseData: { type: 'JDBC', responseResult: {}, subRequestResults: [] },
loading: false,
debugResultId: '',
runData: [],
headers: [],
reportId: '',
@ -133,37 +131,11 @@ export default {
};
},
created() {
if (this.testCase) {
if (this.testCase.id) {
//
getApiReportDetail(this.testCase.id).then((response) => {
if (response.data) {
let data = JSON.parse(response.data.content);
this.responseData = data;
}
});
}
this.request = this.testCase.request;
if (this.request) {
this.debugForm.method = this.request.method;
if (this.request.url) {
this.debugForm.url = this.request.url;
} else {
this.debugForm.url = this.request.path;
}
}
} else {
this.request = createComponent('JDBCSampler');
}
this.request = createComponent('JDBCSampler');
if (!this.request.environmentId) {
this.request.environmentId = store.useEnvironment;
}
},
watch: {
debugResultId() {
this.getResult();
},
},
methods: {
handleCommand(e) {
mergeRequestDocumentData(this.request);

View File

@ -125,7 +125,6 @@ export default {
options: [],
responseData: { type: 'TCP', responseResult: {}, subRequestResults: [] },
loading: false,
debugResultId: '',
runData: [],
headers: [],
reportId: '',
@ -135,33 +134,7 @@ export default {
};
},
created() {
if (this.testCase) {
if (this.testCase.id) {
//
getApiReportDetail(this.testCase.id).then((response) => {
if (response.data) {
let data = JSON.parse(response.data.content);
this.responseData = data;
}
});
}
this.request = this.testCase.request;
if (this.request) {
this.debugForm.method = this.request.method;
if (this.request.url) {
this.debugForm.url = this.request.url;
} else {
this.debugForm.url = this.request.path;
}
}
} else {
this.request = createComponent('TCPSampler');
}
},
watch: {
debugResultId() {
this.getResult();
},
this.request = createComponent('TCPSampler');
},
methods: {
handleCommand(e) {

View File

@ -65,7 +65,7 @@
<script>
import { updateDefinition } from '@/api/definition';
import { getApiReportDetail } from '@/api/definition-report';
import { getLastResultDetail } from '@/api/definition-report';
import { versionEnableByProjectId } from '@/api/xpack';
import { getUUID } from 'metersphere-frontend/src/utils';
import { hasLicense } from 'metersphere-frontend/src/utils/permission';
@ -310,16 +310,6 @@ export default {
environmentConfigClose() {
this.getEnvironments();
},
getResult() {
if (this.api.id) {
getApiReportDetail(this.api.id).then((response) => {
if (response.data) {
let data = JSON.parse(response.data.content);
this.responseData = data;
}
});
}
},
stop() {
execStop(this.reportId).then(() => {
this.runLoading = false;
@ -345,22 +335,13 @@ export default {
this.currentRequest = this.api.request;
this.runLoading = false;
this.getEnvironments();
this.getResult();
getLastResultDetail(this.api.id, this);
this.checkVersionEnable();
},
};
</script>
<style scoped>
.ms-htt-width {
width: 350px;
}
.environment-button {
margin-left: 20px;
padding: 7px;
}
:deep(.el-drawer) {
overflow: auto;
}

View File

@ -107,7 +107,7 @@
<script>
import { getMockEnvironment, updateDefinition } from '@/api/definition';
import { getApiReportDetail } from '@/api/definition-report';
import { getLastResultDetail } from '@/api/definition-report';
import { versionEnableByProjectId } from '@/api/xpack';
import MsApiRequestForm from '../request/http/ApiHttpRequestForm';
import { hasLicense, hasPermission } from 'metersphere-frontend/src/utils/permission';
@ -414,16 +414,6 @@ export default {
refresh() {
this.$emit('refresh');
},
getResult() {
if (this.api.id) {
getApiReportDetail(this.api.id).then((response) => {
if (response.data) {
let data = JSON.parse(response.data.content);
this.responseData = data;
}
});
}
},
stop() {
execStop(this.reportId).then(() => {
this.runLoading = false;
@ -450,6 +440,7 @@ export default {
if (!this.api.environmentId && store.useEnvironment) {
this.api.environmentId = store.useEnvironment;
}
getLastResultDetail(this.api.id, this);
this.runLoading = false;
this.checkVersionEnable();
},

View File

@ -64,7 +64,7 @@
<script>
import { updateDefinition } from '@/api/definition';
import { getApiReportDetail } from '@/api/definition-report';
import { getLastResultDetail } from '@/api/definition-report';
import { versionEnableByProjectId } from '@/api/xpack';
import { hasLicense } from 'metersphere-frontend/src/utils/permission';
import { getUUID } from 'metersphere-frontend/src/utils';
@ -310,16 +310,6 @@ export default {
environmentConfigClose() {
this.getEnvironments();
},
getResult() {
if (this.api.id) {
getApiReportDetail(this.api.id).then((response) => {
if (response.data) {
let data = JSON.parse(response.data.content);
this.responseData = data;
}
});
}
},
stop() {
execStop(this.reportId).then(() => {
this.runLoading = false;
@ -351,7 +341,7 @@ export default {
}
this.runLoading = false;
this.getEnvironments();
this.getResult();
getLastResultDetail(this.api.id, this);
this.checkVersionEnable();
},
};

View File

@ -75,7 +75,7 @@
<script>
import { getMockEnvironment, updateDefinition } from '@/api/definition';
import { getApiReportDetail } from '@/api/definition-report';
import { getLastResultDetail } from '@/api/definition-report';
import { versionEnableByProjectId } from '@/api/xpack';
import MsApiRequestForm from '../request/http/ApiHttpRequestForm';
import { hasLicense } from 'metersphere-frontend/src/utils/permission';
@ -316,14 +316,6 @@ export default {
this.api.request = this.currentRequest;
}
},
getResult() {
getApiReportDetail(this.api.id).then((response) => {
if (response.data) {
let data = JSON.parse(response.data.content);
this.responseData = data;
}
});
},
stop() {
execStop(this.reportId).then(() => {
this.runLoading = false;
@ -350,7 +342,7 @@ export default {
}
this.currentRequest = this.api.request;
this.runLoading = false;
this.getResult();
getLastResultDetail(this.api.id, this);
if (this.api.environmentId) {
this.api.request.useEnvironment = this.api.environmentId;
}
@ -364,15 +356,6 @@ export default {
</script>
<style scoped>
.ms-htt-width {
width: 350px;
}
.environment-button {
margin-left: 20px;
padding: 7px;
}
:deep(.el-drawer) {
overflow: auto;
}