test(web): added search controller test #38

Merged
devitq merged 1 commits from test/film-controller-search-test into develop 2026-05-03 19:29:04 +00:00
@@ -0,0 +1,77 @@
package com.project.movienight.adapters.web
import com.project.movienight.application.ports.input.CreateFilmUseCase
import com.project.movienight.application.ports.input.DeleteFilmUseCase
import com.project.movienight.application.ports.input.EditFilmUseCase
import com.project.movienight.application.ports.input.GetAllFilmsUseCase
import com.project.movienight.application.ports.input.GetFilmByIdUseCase
import com.project.movienight.application.ports.input.SearchFilmByTitleUseCase
import com.project.movienight.domain.model.Film
import io.mockk.every
import io.mockk.mockk
import io.mockk.verify
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.springframework.test.web.servlet.MockMvc
import org.springframework.test.web.servlet.get
import org.springframework.test.web.servlet.setup.MockMvcBuilders
import java.util.UUID
class FilmControllerSearchTest {
private lateinit var mockMvc: MockMvc
private lateinit var searchFilmByTitleUseCase: SearchFilmByTitleUseCase
@BeforeEach
fun setup() {
searchFilmByTitleUseCase = mockk()
val controller =
FilmController(
createFilmUseCase = mockk<CreateFilmUseCase>(),
editFilmUseCase = mockk<EditFilmUseCase>(),
deleteFilmUseCase = mockk<DeleteFilmUseCase>(),
getFilmByIdUseCase = mockk<GetFilmByIdUseCase>(),
getAllFilmsUseCase = mockk<GetAllFilmsUseCase>(),
searchFilmByTitleUseCase = searchFilmByTitleUseCase,
)
mockMvc = MockMvcBuilders.standaloneSetup(controller).build()
}
@Test
fun `search returns film when title exists`() {
val title = "Inception"
val film = Film(id = UUID.randomUUID(), title = title, description = "A dream heist")
every { searchFilmByTitleUseCase.searchByTitle(title) } returns film
mockMvc
.get("/api/films/search") {
param("title", title)
}.andExpect {
status { isOk() }
jsonPath("$.id") { value(film.id.toString()) }
jsonPath("$.title") { value(title) }
jsonPath("$.description") { value("A dream heist") }
}
verify(exactly = 1) { searchFilmByTitleUseCase.searchByTitle(title) }
}
@Test
fun `search returns empty body when title is missing`() {
copilot-pull-request-reviewer[bot] commented 2026-05-03 19:29:14 +00:00 (Migrated from github.com)
Review

The test name says "title is missing", but the request still includes a title query param; the scenario is actually "no film found for the given title". Renaming the test (and any related wording) would make the intent clearer and avoid confusion with the separate case where the title request parameter is omitted (which should result in a 400).

The test name says "title is missing", but the request still includes a `title` query param; the scenario is actually "no film found for the given title". Renaming the test (and any related wording) would make the intent clearer and avoid confusion with the separate case where the `title` request parameter is omitted (which should result in a 400).
val title = "Unknown Title"
every { searchFilmByTitleUseCase.searchByTitle(title) } returns null
mockMvc
.get("/api/films/search") {
param("title", title)
}.andExpect {
copilot-pull-request-reviewer[bot] commented 2026-05-03 19:29:14 +00:00 (Migrated from github.com)
Review

The controller method requires a title query parameter (@RequestParam title: String). Consider adding a test that calls /api/films/search without the title param and asserts a 400 Bad Request response, so request validation behavior is explicitly covered.

The controller method requires a `title` query parameter (`@RequestParam title: String`). Consider adding a test that calls `/api/films/search` without the `title` param and asserts a 400 Bad Request response, so request validation behavior is explicitly covered.
status { isOk() }
content { string("") }
}
verify(exactly = 1) { searchFilmByTitleUseCase.searchByTitle(title) }
}
}