From b9d06ead2ae732b3102d9916923782d631d3df49 Mon Sep 17 00:00:00 2001 From: Havlli Date: Sat, 25 Apr 2026 23:41:18 +0200 Subject: [PATCH 1/3] Fix user role repository test isolation --- .../EventPilot/entity/user/UserRoleRepositoryIT.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/test/java/com/github/havlli/EventPilot/entity/user/UserRoleRepositoryIT.java b/src/test/java/com/github/havlli/EventPilot/entity/user/UserRoleRepositoryIT.java index f001770..0cf115a 100644 --- a/src/test/java/com/github/havlli/EventPilot/entity/user/UserRoleRepositoryIT.java +++ b/src/test/java/com/github/havlli/EventPilot/entity/user/UserRoleRepositoryIT.java @@ -10,6 +10,7 @@ import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; import org.springframework.context.ApplicationContext; import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.jdbc.Sql; import java.util.Optional; @@ -18,6 +19,14 @@ @DataJpaTest @AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE) @DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD) +@Sql(statements = { + "DELETE FROM user_role", + "DELETE FROM users", + "DELETE FROM role", + "INSERT INTO role(name) VALUES('USER')", + "INSERT INTO role(name) VALUES('MODERATOR')", + "INSERT INTO role(name) VALUES('ADMIN')" +}) class UserRoleRepositoryIT extends TestDatabaseContainer { public static final Logger LOG = LoggerFactory.getLogger(UserRoleRepositoryIT.class); From 815d594c94224a79e35c9d32b3c702d9dbd16510 Mon Sep 17 00:00:00 2001 From: Havlli Date: Sat, 25 Apr 2026 23:51:38 +0200 Subject: [PATCH 2/3] Reset integration test database state --- .../havlli/EventPilot/TestDatabaseContainer.java | 7 +++++++ .../EventPilot/entity/user/UserRoleRepositoryIT.java | 9 --------- src/test/resources/cleanup.sql | 11 ++++++++--- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/test/java/com/github/havlli/EventPilot/TestDatabaseContainer.java b/src/test/java/com/github/havlli/EventPilot/TestDatabaseContainer.java index 2d69475..3d2b6e2 100644 --- a/src/test/java/com/github/havlli/EventPilot/TestDatabaseContainer.java +++ b/src/test/java/com/github/havlli/EventPilot/TestDatabaseContainer.java @@ -4,6 +4,7 @@ import com.redis.testcontainers.RedisContainer; import org.flywaydb.core.Flyway; import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.context.annotation.Import; @@ -38,6 +39,7 @@ static void beforeAll() throws SQLException, IOException { postgresSQLContainer.getUsername(), postgresSQLContainer.getPassword() ).load(); + flyway.migrate(); logContainerInfo(); } @@ -120,6 +122,11 @@ protected void clearAllData() throws SQLException, IOException { executeSQLFile(CLEANUP_SQL); } + @BeforeEach + void resetDatabaseState() throws SQLException, IOException { + clearAllData(); + } + protected static void populateDummyData() throws SQLException, IOException { executeSQLFile(DATA_SQL); diff --git a/src/test/java/com/github/havlli/EventPilot/entity/user/UserRoleRepositoryIT.java b/src/test/java/com/github/havlli/EventPilot/entity/user/UserRoleRepositoryIT.java index 0cf115a..f001770 100644 --- a/src/test/java/com/github/havlli/EventPilot/entity/user/UserRoleRepositoryIT.java +++ b/src/test/java/com/github/havlli/EventPilot/entity/user/UserRoleRepositoryIT.java @@ -10,7 +10,6 @@ import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; import org.springframework.context.ApplicationContext; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.jdbc.Sql; import java.util.Optional; @@ -19,14 +18,6 @@ @DataJpaTest @AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE) @DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD) -@Sql(statements = { - "DELETE FROM user_role", - "DELETE FROM users", - "DELETE FROM role", - "INSERT INTO role(name) VALUES('USER')", - "INSERT INTO role(name) VALUES('MODERATOR')", - "INSERT INTO role(name) VALUES('ADMIN')" -}) class UserRoleRepositoryIT extends TestDatabaseContainer { public static final Logger LOG = LoggerFactory.getLogger(UserRoleRepositoryIT.class); diff --git a/src/test/resources/cleanup.sql b/src/test/resources/cleanup.sql index 840f166..bf62edd 100644 --- a/src/test/resources/cleanup.sql +++ b/src/test/resources/cleanup.sql @@ -1,3 +1,8 @@ -DELETE FROM participant; -DELETE FROM event; -DELETE FROM guild; +TRUNCATE TABLE participant, event, guild, embed_type, user_role, users, role RESTART IDENTITY CASCADE; + +INSERT INTO embed_type (name, structure) +VALUES ('default', '{"-1":"Absence","-2":"Late","1":"Tank","-3":"Tentative","2":"Melee","3":"Ranged","4":"Healer","5":"Support"}'); + +INSERT INTO role(name) VALUES('USER'); +INSERT INTO role(name) VALUES('MODERATOR'); +INSERT INTO role(name) VALUES('ADMIN'); From 3d0615b67135a9c7415a5787885e2ceed82a46d5 Mon Sep 17 00:00:00 2001 From: Havlli Date: Sun, 26 Apr 2026 00:37:41 +0200 Subject: [PATCH 3/3] Allow small Codecov project coverage drift --- .github/codecov.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/codecov.yml b/.github/codecov.yml index 3fd5a2a..e31ea88 100644 --- a/.github/codecov.yml +++ b/.github/codecov.yml @@ -2,6 +2,11 @@ coverage: precision: 1 round: up range: "70...100" + status: + project: + default: + target: auto + threshold: 1% parsers: jacoco: - partials_as_hits: true \ No newline at end of file + partials_as_hits: true