Skip to content

Commit a5af062

Browse files
committed
fix issues with integration test
1 parent a3df897 commit a5af062

5 files changed

Lines changed: 7 additions & 12 deletions

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ frontend/node_modules
99
!**/src/test/**/build/
1010
data/screenshots
1111
data/typesense-data
12-
data/uploads
12+
# Allow for this director to be created
13+
data/uploads/profile-pictures/*.png
1314

1415
### STS ###
1516
.apt_generated
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-- placeholder text. To prevent root from creating this via docker container.

server/src/main/java/dev/findfirst/users/controller/UserController.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,9 @@ public ResponseEntity<String> refreshToken(
173173

174174
@PostMapping("/profile-picture")
175175
public ResponseEntity<String> uploadProfilePicture(
176-
@Valid @RequestParam("file") @FileSize MultipartFile file) {
177-
log.debug("saving profile picture");
176+
@Valid @RequestParam("file") @FileSize MultipartFile file) throws NoUserFoundException {
177+
log.debug("Attempting to add user profile picture");
178+
User user = userService.getUserById(uContext.getUserId()).orElseThrow(NoUserFoundException::new);
178179

179180
// File type validation
180181
String contentType = file.getContentType();
@@ -184,13 +185,8 @@ public ResponseEntity<String> uploadProfilePicture(
184185
}
185186

186187
try {
187-
User user =
188-
userService.getUserById(uContext.getUserId()).orElseThrow(NoUserFoundException::new);
189188
userService.changeUserPhoto(user, file);
190-
191189
return ResponseEntity.ok("File uploaded successfully.");
192-
} catch (NoUserFoundException e) {
193-
return ResponseEntity.status(HttpStatus.NOT_FOUND).body("User not found.");
194190
} catch (Exception e) {
195191
log.debug(e.getMessage());
196192
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Failed to upload file.");

server/src/main/java/dev/findfirst/users/service/UserManagementService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public void changeUserPhoto(User user, MultipartFile file)
115115

116116
public void removeUserPhoto(User user) {
117117
String userPhoto = user.getUserPhoto();
118-
if (userPhoto != null) {
118+
if (userPhoto != null && !userPhoto.isBlank()) {
119119
log.debug("Existing User photo {}", userPhoto);
120120
File photoFile = new File(userPhoto);
121121
if (photoFile.exists()) {

server/src/test/java/dev/findfirst/users/controller/UserControllerTest.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,6 @@ void refreshToken() {
199199
}
200200

201201
@Test
202-
@Disabled("The test uses basicAuth currently basicAuth is broken and only JWT is supported on request")
203202
void testUserProfile_PhotoTooLarg() {
204203
byte[] largeContent = new byte[3 * 1024 * 1024]; // 2 MB Max
205204
// Use MultipartBodyBuilder to build the multipart request
@@ -214,7 +213,6 @@ void testUserProfile_PhotoTooLarg() {
214213
}
215214

216215
@Test
217-
@Disabled("The test uses basicAuth currently basicAuth is broken and only JWT is supported on request")
218216
void testGetUserProfilePicture_NotFound() {
219217

220218
byte[] largeContent = new byte[2 * 1024 * 1024]; // 2 MB Max
@@ -231,7 +229,6 @@ void testGetUserProfilePicture_NotFound() {
231229
}
232230

233231
@Test
234-
@Disabled("The test uses basicAuth currently basicAuth is broken and only JWT is supported on request")
235232
void testRemoveUserPhoto_Success() throws Exception {
236233
MultipartBodyBuilder bodyBuilder = new MultipartBodyBuilder();
237234
bodyBuilder.part("file", Files.readAllBytes(Path.of(testPicture + "/facebook.com.png")))

0 commit comments

Comments
 (0)