From 6df67fa91c5201b0d086721d1a6e5f80986726f9 Mon Sep 17 00:00:00 2001
From: Tim <135014430+nagisa77@users.noreply.github.com>
Date: Mon, 30 Jun 2025 20:59:28 +0800
Subject: [PATCH] Add integration tests for nested comments and reactions
---
pom.xml | 5 +
.../ComplexFlowIntegrationTest.java | 115 ++++++++++++++++++
src/test/resources/application.properties | 10 ++
3 files changed, 130 insertions(+)
create mode 100644 src/test/java/com/openisle/integration/ComplexFlowIntegrationTest.java
create mode 100644 src/test/resources/application.properties
diff --git a/pom.xml b/pom.xml
index d5de2d04f..1c31f0b94 100644
--- a/pom.xml
+++ b/pom.xml
@@ -39,6 +39,11 @@
mysql-connector-j
runtime
+
+ com.h2database
+ h2
+ test
+
io.jsonwebtoken
jjwt-api
diff --git a/src/test/java/com/openisle/integration/ComplexFlowIntegrationTest.java b/src/test/java/com/openisle/integration/ComplexFlowIntegrationTest.java
new file mode 100644
index 000000000..525d19e2f
--- /dev/null
+++ b/src/test/java/com/openisle/integration/ComplexFlowIntegrationTest.java
@@ -0,0 +1,115 @@
+package com.openisle.integration;
+
+import com.openisle.model.User;
+import com.openisle.repository.UserRepository;
+import com.openisle.service.EmailService;
+import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.boot.test.mock.mockito.MockBean;
+import org.springframework.boot.test.web.client.TestRestTemplate;
+import org.springframework.http.*;
+
+import java.util.List;
+import java.util.Map;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
+class ComplexFlowIntegrationTest {
+
+ @Autowired
+ private TestRestTemplate rest;
+
+ @Autowired
+ private UserRepository users;
+
+ @MockBean
+ private EmailService emailService;
+
+ private String registerAndLogin(String username, String email) {
+ HttpHeaders h = new HttpHeaders();
+ h.setContentType(MediaType.APPLICATION_JSON);
+ rest.postForEntity("/api/auth/register", new HttpEntity<>(
+ Map.of("username", username, "email", email, "password", "pass"), h), Map.class);
+ User u = users.findByUsername(username).orElseThrow();
+ rest.postForEntity("/api/auth/verify", new HttpEntity<>(
+ Map.of("username", username, "code", u.getVerificationCode()), h), Map.class);
+ ResponseEntity