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);