add new api methods to product controller

This commit is contained in:
Denis Savosin
2024-09-30 12:41:29 +07:00
parent f12839a15f
commit 27595e08dc
11 changed files with 83 additions and 33 deletions

View File

@@ -1,8 +1,8 @@
package com.example.demo.controllers
import com.example.demo.models.Product
import com.example.demo.provider.ProductRepository
import com.example.demo.responses.ResponseStatus
import com.example.demo.services.ProductService
import org.hamcrest.Matchers.nullValue
import org.junit.jupiter.api.Test
import org.mockito.kotlin.doReturn
@@ -20,7 +20,7 @@ import java.util.*
@WebMvcTest(ProductController::class)
class ProductControllerTest(@Autowired val mockMvc: MockMvc) {
@MockBean
private lateinit var productRepository: ProductRepository
private lateinit var productService: ProductService
@Test
fun getProduct_success() {
@@ -34,9 +34,10 @@ class ProductControllerTest(@Autowired val mockMvc: MockMvc) {
price = 11130,
createdAt = now,
updatedAt = null,
deletedAt = null,
)
whenever(productRepository.findByGuid(
whenever(productService.findByGuid(
eq(guid),
)) doReturn product
@@ -54,7 +55,7 @@ class ProductControllerTest(@Autowired val mockMvc: MockMvc) {
fun getProduct_notFound() {
val guid = UUID.randomUUID()
whenever(productRepository.findByGuid(
whenever(productService.findByGuid(
eq(guid),
)) doReturn null

View File

@@ -81,9 +81,10 @@ class ShopControllerTest(@Autowired val mockMvc: MockMvc) {
guid = UUID.randomUUID(),
name = name,
description = null,
price = (price * 100).toInt(),
price = (price * 100).toLong(),
createdAt = OffsetDateTime.now(),
updatedAt = null,
deletedAt = null,
)
}
}