merge: sync develop into feat/spring-tests
Agent-Logs-Url: https://github.com/devitq/movienight-backend/sessions/42b7a686-07a7-41f5-baf7-737b968e12cf Co-authored-by: devitq <118541411+devitq@users.noreply.github.com>
This commit is contained in:
co-authored by
devitq
parent
e91ebb7bd0
commit
47ff6d80bf
@@ -92,12 +92,14 @@ class FilmLibraryController(
|
|||||||
fun removeFilm(
|
fun removeFilm(
|
||||||
@PathVariable userId: UUID,
|
@PathVariable userId: UUID,
|
||||||
@PathVariable filmId: UUID,
|
@PathVariable filmId: UUID,
|
||||||
) = removeFilmFromLibraryUseCase.removeFilm(
|
) {
|
||||||
|
removeFilmFromLibraryUseCase.removeFilm(
|
||||||
RemoveFilmFromLibraryCommand(
|
RemoveFilmFromLibraryCommand(
|
||||||
userId = userId,
|
userId = userId,
|
||||||
filmId = filmId,
|
filmId = filmId,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
}
|
||||||
|
|
||||||
@GetMapping("/available-films")
|
@GetMapping("/available-films")
|
||||||
fun getAvailableFilms(
|
fun getAvailableFilms(
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
CREATE TABLE IF NOT EXISTS public.users (
|
CREATE TABLE IF NOT EXISTS public.users (
|
||||||
id UUID PRIMARY KEY,
|
id UUID PRIMARY KEY,
|
||||||
name VARCHAR(255) NOT NULL,
|
name VARCHAR(255) NOT NULL,
|
||||||
email VARCHAR(320) NOT NULL UNIQUE
|
email VARCHAR(320) NOT NULL UNIQUE,
|
||||||
|
provider VARCHAR(64),
|
||||||
|
provider_id VARCHAR(255),
|
||||||
|
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS public.films (
|
CREATE TABLE IF NOT EXISTS public.films (
|
||||||
|
|||||||
+11
-10
@@ -9,10 +9,10 @@ import kotlin.test.assertEquals
|
|||||||
import kotlin.test.assertNull
|
import kotlin.test.assertNull
|
||||||
|
|
||||||
class UserEntityMappingTest {
|
class UserEntityMappingTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `toDomain maps UserEntity correctly`() {
|
fun `toDomain maps UserEntity correctly`() {
|
||||||
val entity = UserEntity(
|
val entity =
|
||||||
|
UserEntity(
|
||||||
id = UUID.randomUUID(),
|
id = UUID.randomUUID(),
|
||||||
name = "John Pork",
|
name = "John Pork",
|
||||||
email = "john@email.com",
|
email = "john@email.com",
|
||||||
@@ -30,11 +30,12 @@ class UserEntityMappingTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `toEntity maps User with OAuth provider`() {
|
fun `toEntity maps User with OAuth provider`() {
|
||||||
val user = User(
|
val user =
|
||||||
|
User(
|
||||||
id = UUID.randomUUID(),
|
id = UUID.randomUUID(),
|
||||||
name = "Jane",
|
name = "Jane",
|
||||||
email = "jane@mail.com",
|
email = "jane@mail.com",
|
||||||
library = null
|
library = null,
|
||||||
)
|
)
|
||||||
|
|
||||||
val entity = user.toEntity(AuthProvider.YANDEX, "yandex456")
|
val entity = user.toEntity(AuthProvider.YANDEX, "yandex456")
|
||||||
@@ -48,11 +49,12 @@ class UserEntityMappingTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `toEntity maps User without OAuth provider`() {
|
fun `toEntity maps User without OAuth provider`() {
|
||||||
val user = User(
|
val user =
|
||||||
|
User(
|
||||||
id = UUID.randomUUID(),
|
id = UUID.randomUUID(),
|
||||||
name = "Bob",
|
name = "Bob",
|
||||||
email = "bob@mail.com",
|
email = "bob@mail.com",
|
||||||
library = null
|
library = null,
|
||||||
)
|
)
|
||||||
|
|
||||||
val entity = user.toEntity()
|
val entity = user.toEntity()
|
||||||
@@ -63,11 +65,12 @@ class UserEntityMappingTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `mapping is reversible for basic fields`() {
|
fun `mapping is reversible for basic fields`() {
|
||||||
val original = User(
|
val original =
|
||||||
|
User(
|
||||||
id = UUID.randomUUID(),
|
id = UUID.randomUUID(),
|
||||||
name = "Alice",
|
name = "Alice",
|
||||||
email = "alice@email.com",
|
email = "alice@email.com",
|
||||||
library = null
|
library = null,
|
||||||
)
|
)
|
||||||
|
|
||||||
val mapped = original.toEntity().toDomain()
|
val mapped = original.toEntity().toDomain()
|
||||||
@@ -76,6 +79,4 @@ class UserEntityMappingTest {
|
|||||||
assertEquals(original.name, mapped.name)
|
assertEquals(original.name, mapped.name)
|
||||||
assertEquals(original.email, mapped.email)
|
assertEquals(original.email, mapped.email)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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`() {
|
||||||
|
val title = "Unknown Title"
|
||||||
|
|
||||||
|
every { searchFilmByTitleUseCase.searchByTitle(title) } returns null
|
||||||
|
|
||||||
|
mockMvc
|
||||||
|
.get("/api/films/search") {
|
||||||
|
param("title", title)
|
||||||
|
}.andExpect {
|
||||||
|
status { isOk() }
|
||||||
|
content { string("") }
|
||||||
|
}
|
||||||
|
|
||||||
|
verify(exactly = 1) { searchFilmByTitleUseCase.searchByTitle(title) }
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user