fix: address copilot review issues - explicit imports, trailing commas, 404 for not-found search, tests for available-films endpoint

Agent-Logs-Url: https://github.com/devitq/movienight-backend/sessions/60cd9b1b-e3e1-46a1-bfd9-04a75bd0d569

Co-authored-by: devitq <118541411+devitq@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-05-03 12:02:31 +00:00
committed by GitHub
co-authored by devitq
parent f563c3e7cf
commit b7a246e0b4
6 changed files with 317 additions and 174 deletions
@@ -20,7 +20,6 @@ import org.springframework.transaction.annotation.Transactional
@AutoConfigureMockMvc
@Transactional
class UserControllerTest {
@Autowired
private lateinit var mockMvc: MockMvc
@@ -29,17 +28,18 @@ class UserControllerTest {
@Test
fun `create user should return 201 CREATED`() {
val request = CreateUserRequest(
name = "John Doe",
email = "john@example.com",
)
val request =
CreateUserRequest(
name = "John Doe",
email = "john@example.com",
)
mockMvc.perform(
post("/api/users")
.contentType(MediaType.APPLICATION_JSON)
.content(objectMapper.writeValueAsString(request)),
)
.andExpect(status().isCreated)
mockMvc
.perform(
post("/api/users")
.contentType(MediaType.APPLICATION_JSON)
.content(objectMapper.writeValueAsString(request)),
).andExpect(status().isCreated)
.andExpect(jsonPath("$.name").value("John Doe"))
.andExpect(jsonPath("$.email").value("john@example.com"))
.andExpect(jsonPath("$.id").exists())
@@ -47,54 +47,62 @@ class UserControllerTest {
@Test
fun `edit user should return updated user`() {
val createRequest = CreateUserRequest(
name = "Old Name",
email = "edit@example.com",
)
val createRequest =
CreateUserRequest(
name = "Old Name",
email = "edit@example.com",
)
val response = mockMvc.perform(
post("/api/users")
.contentType(MediaType.APPLICATION_JSON)
.content(objectMapper.writeValueAsString(createRequest)),
).andReturn()
val response =
mockMvc
.perform(
post("/api/users")
.contentType(MediaType.APPLICATION_JSON)
.content(objectMapper.writeValueAsString(createRequest)),
).andReturn()
val userId = objectMapper.readTree(response.response.contentAsString).get("id").asText()
val editRequest = EditUserRequest(name = "New Name")
mockMvc.perform(
patch("/api/users/$userId")
.contentType(MediaType.APPLICATION_JSON)
.content(objectMapper.writeValueAsString(editRequest)),
)
.andExpect(status().isOk)
mockMvc
.perform(
patch("/api/users/$userId")
.contentType(MediaType.APPLICATION_JSON)
.content(objectMapper.writeValueAsString(editRequest)),
).andExpect(status().isOk)
.andExpect(jsonPath("$.name").value("New Name"))
.andExpect(jsonPath("$.email").value("edit@example.com"))
}
@Test
fun `delete user should return 204 NO CONTENT`() {
val request = CreateUserRequest(
name = "User To Delete",
email = "delete@example.com",
)
val request =
CreateUserRequest(
name = "User To Delete",
email = "delete@example.com",
)
val response = mockMvc.perform(
post("/api/users")
.contentType(MediaType.APPLICATION_JSON)
.content(objectMapper.writeValueAsString(request)),
).andReturn()
val response =
mockMvc
.perform(
post("/api/users")
.contentType(MediaType.APPLICATION_JSON)
.content(objectMapper.writeValueAsString(request)),
).andReturn()
val userId = objectMapper.readTree(response.response.contentAsString).get("id").asText()
mockMvc.perform(delete("/api/users/$userId"))
mockMvc
.perform(delete("/api/users/$userId"))
.andExpect(status().isNoContent())
}
@Test
fun `delete non-existent user should return 404`() {
val nonExistentId = "123e4567-e89b-12d3-a456-426614174000"
mockMvc.perform(delete("/api/users/$nonExistentId"))
mockMvc
.perform(delete("/api/users/$nonExistentId"))
.andExpect(status().isNotFound())
}
}