refactor(接口测试): 优化场景加载环境的传参方式

--bug=1026626 --user=王孝刚 [接口测试]GitHub#24694场景加载环境报错,无法调试 (特殊数据)
https://www.tapd.cn/55049933/s/1377574
This commit is contained in:
wxg0103 2023-05-31 16:37:07 +08:00 committed by fit2-zhao
parent 562b0a00c3
commit 327ce53516
3 changed files with 8 additions and 5 deletions

View File

@ -191,8 +191,8 @@ public class ApiScenarioController {
}
@PostMapping("/scenario-env")
public ScenarioEnv getScenarioDefinition(@RequestBody ApiScenarioEnvRequest request) {
return apiAutomationService.getApiScenarioEnv(request.getDefinition());
public ScenarioEnv getScenarioDefinition(@RequestBody byte[] request) {
return apiAutomationService.getApiScenarioEnv(request);
}
@GetMapping("/env-project-ids/{id}")

View File

@ -2111,7 +2111,8 @@ public class ApiScenarioService {
return follows.stream().map(ApiScenarioFollow::getFollowId).distinct().collect(Collectors.toList());
}
public ScenarioEnv getApiScenarioEnv(String definition) {
public ScenarioEnv getApiScenarioEnv(byte[] request) {
String definition = new String(request, StandardCharsets.UTF_8);
return apiScenarioEnvService.getApiScenarioEnv(definition);
}
@ -2161,7 +2162,7 @@ public class ApiScenarioService {
List<String> strings = new LinkedList<>();
apiScenarios.forEach(item -> {
if (StringUtils.isNotEmpty(item.getScenarioDefinition())) {
ScenarioEnv env = getApiScenarioEnv(item.getScenarioDefinition());
ScenarioEnv env = apiScenarioEnvService.getApiScenarioEnv(item.getScenarioDefinition());
if (!strings.contains(item.getProjectId())) {
strings.add(item.getProjectId());
}

View File

@ -1963,7 +1963,9 @@ export default {
},
getEnv(definition) {
return new Promise((resolve) => {
getApiScenarioEnv({ definition: definition }).then((res) => {
const encoder = new TextEncoder();
const bytes = encoder.encode(definition, 'utf-8');
getApiScenarioEnv({ definition: bytes }).then((res) => {
if (res.data) {
this.projectIds = new Set(res.data.projectIds);
this.projectIds.add(this.projectId);