From 83c7659b88e65234c6847b27e249a47e33e1c906 Mon Sep 17 00:00:00 2001 From: Tim <135014430+nagisa77@users.noreply.github.com> Date: Tue, 1 Jul 2025 13:20:15 +0800 Subject: [PATCH] fix integration test to include auth for admin endpoint --- .../openisle/integration/PublishModeIntegrationTest.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/test/java/com/openisle/integration/PublishModeIntegrationTest.java b/src/test/java/com/openisle/integration/PublishModeIntegrationTest.java index 34319a13f..270b4dde2 100644 --- a/src/test/java/com/openisle/integration/PublishModeIntegrationTest.java +++ b/src/test/java/com/openisle/integration/PublishModeIntegrationTest.java @@ -58,6 +58,12 @@ class PublishModeIntegrationTest { return rest.exchange(url, HttpMethod.POST, new HttpEntity<>(body, h), Map.class); } + private ResponseEntity get(String url, Class type, String token) { + HttpHeaders h = new HttpHeaders(); + if (token != null) h.setBearerAuth(token); + return rest.exchange(url, HttpMethod.GET, new HttpEntity<>(h), type); + } + @Test void postRequiresApproval() { String userToken = registerAndLogin("eve", "e@example.com"); @@ -74,7 +80,7 @@ class PublishModeIntegrationTest { List list = rest.getForObject("/api/posts", List.class); assertTrue(list.isEmpty(), "Post should not be listed before approval"); - List> pending = (List>) rest.getForObject("/api/admin/posts/pending", List.class); + List> pending = get("/api/admin/posts/pending", List.class, adminToken).getBody(); assertEquals(1, pending.size()); assertEquals(postId.intValue(), ((Number)pending.get(0).get("id")).intValue());