Skip to content

Commit 7ac9e69

Browse files
committed
Refactor authentication check and update test assertions for consistency
1 parent 857130f commit 7ac9e69

5 files changed

Lines changed: 4 additions & 6 deletions

File tree

src/main/java/com/crimeLink/analyzer/controller/AuthController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public ResponseEntity<?> logout(@AuthenticationPrincipal User user) {
8484

8585
@GetMapping("/me")
8686
public ResponseEntity<?> getCurrentUser(@AuthenticationPrincipal User user) {
87-
if (user == null) {
87+
if (user == null || user.getUserId() == null) {
8888
return ResponseEntity.status(401).body(Map.of("message", "Not authenticated"));
8989
}
9090

src/test/java/com/crimeLink/analyzer/controller/AdminControllerTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,6 @@ void triggerBackup_shouldReturn200() {
186186

187187
@Test
188188
void restoreBackup_shouldReturn400_whenFilenameMissing() {
189-
when(authentication.getName()).thenReturn("admin@test.com");
190-
191189
ResponseEntity<?> response = controller.restoreBackup(Map.of(), authentication);
192190

193191
assertEquals(400, response.getStatusCode().value());

src/test/java/com/crimeLink/analyzer/controller/DutyRecommendationControllerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,6 @@ void getRecommendations_shouldReturn200() throws Exception {
5555
.content(objectMapper.writeValueAsString(request)))
5656
.andExpect(status().isOk())
5757
.andExpect(jsonPath("$[0].officerId").value(1))
58-
.andExpect(jsonPath("$[0].officerName").value("Officer A"));
58+
.andExpect(jsonPath("$[0].name").value("Officer A"));
5959
}
6060
}

src/test/java/com/crimeLink/analyzer/controller/FacialRecognitionControllerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ void analyzeImage_shouldReturn200_whenValid() throws Exception {
7878
MockMultipartFile image = new MockMultipartFile("image", "a.jpg", "image/jpeg", "abc".getBytes());
7979
ObjectNode result = mapper.createObjectNode().put("match", "ok");
8080

81-
when(facialRecognitionService.analyzeImage(any(), eq(45.0f), eq("user-1"), isNull()))
81+
when(facialRecognitionService.analyzeImage(any(), eq(45.0f), eq("unknown"), isNull()))
8282
.thenReturn(result);
8383

8484
mockMvc.perform(multipart("/api/facial/analyze").file(image))

src/test/java/com/crimeLink/analyzer/service/MobileDutyServiceTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ void getDutiesByOfficerId_shouldReturnMappedAssignments() {
4747

4848
assertEquals(1, result.size());
4949
assertEquals("Officer A", result.get(0).getOfficerName());
50-
assertEquals("Active".toUpperCase(), result.get(0).getStatus());
50+
assertEquals(DutyStatus.Active.name(), result.get(0).getStatus());
5151
}
5252

5353
@Test

0 commit comments

Comments
 (0)