Skip to content

Commit 679170c

Browse files
committed
fix: delete DemoUserProfile before user in TestDataController
The deleteTestUser endpoint was failing with FK constraint violation because demo_user_profile rows weren't cleaned up before deleting the user_account. This caused all Playwright tests that create users to fail during cleanup.
1 parent 2116abd commit 679170c

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

src/main/java/com/digitalsanctuary/spring/demo/test/api/TestDataController.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import org.springframework.web.bind.annotation.RequestMapping;
1818
import org.springframework.web.bind.annotation.RequestParam;
1919
import org.springframework.web.bind.annotation.RestController;
20+
import com.digitalsanctuary.spring.demo.user.profile.DemoUserProfileRepository;
2021
import com.digitalsanctuary.spring.user.persistence.model.PasswordResetToken;
2122
import com.digitalsanctuary.spring.user.persistence.model.Role;
2223
import com.digitalsanctuary.spring.user.persistence.model.User;
@@ -47,6 +48,7 @@ public class TestDataController {
4748
private final PasswordResetTokenRepository passwordResetTokenRepository;
4849
private final RoleRepository roleRepository;
4950
private final PasswordEncoder passwordEncoder;
51+
private final DemoUserProfileRepository demoUserProfileRepository;
5052

5153
/**
5254
* Check if a user exists by email.
@@ -228,9 +230,9 @@ public ResponseEntity<Map<String, Object>> deleteTestUser(@RequestParam String e
228230
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(response);
229231
}
230232

231-
// Delete related tokens first to avoid foreign key constraints
232-
// Note: Event registrations and other related entities are not deleted.
233-
// If the user has event registrations, this may fail with foreign key constraint violation.
233+
// Delete related entities first to avoid foreign key constraints
234+
demoUserProfileRepository.findById(user.getId()).ifPresent(demoUserProfileRepository::delete);
235+
234236
VerificationToken verificationToken = verificationTokenRepository.findByUser(user);
235237
if (verificationToken != null) {
236238
verificationTokenRepository.delete(verificationToken);

0 commit comments

Comments
 (0)