From 8e6126e0ade75a20b4ac3ccad3ca54035934e9db Mon Sep 17 00:00:00 2001 From: tim Date: Tue, 1 Jul 2025 10:01:49 +0800 Subject: [PATCH] feat: update test --- .../ComplexFlowIntegrationTest.java | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/test/java/com/openisle/integration/ComplexFlowIntegrationTest.java b/src/test/java/com/openisle/integration/ComplexFlowIntegrationTest.java index b0888dd3b..a1016f393 100644 --- a/src/test/java/com/openisle/integration/ComplexFlowIntegrationTest.java +++ b/src/test/java/com/openisle/integration/ComplexFlowIntegrationTest.java @@ -11,6 +11,7 @@ import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.http.*; +import java.lang.reflect.Array; import java.util.List; import java.util.Map; @@ -102,9 +103,22 @@ class ComplexFlowIntegrationTest { String t2 = registerAndLogin("dave", "d@example.com"); String adminToken = registerAndLoginAsAdmin("admin2", "admin2@example.com"); - ResponseEntity catResp = postJson("/api/categories", - Map.of("name", "general"), adminToken); - Long catId = ((Number)catResp.getBody().get("id")).longValue(); + List> categories = (List>) rest.getForObject("/api/categories", List.class); + Long catId = null; + if (categories != null) { + for (Map cat : categories) { + if ("general".equals(cat.get("name"))) { + catId = ((Number)cat.get("id")).longValue(); + break; + } + } + } + + if (catId == null) { + ResponseEntity catResp = postJson("/api/categories", + Map.of("name", "general"), adminToken); + catId = ((Number)catResp.getBody().get("id")).longValue(); + } ResponseEntity postResp = postJson("/api/posts", Map.of("title", "React", "content", "Test", "categoryId", catId), t1);