Skip to content

Commit

Permalink
Fix ProductsAPITest
Browse files Browse the repository at this point in the history
  • Loading branch information
g123k committed Aug 6, 2024
1 parent 8163308 commit d712ba8
Showing 1 changed file with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ import openfoodfacts.github.scrachx.openfood.models.entities.SendProduct
import openfoodfacts.github.scrachx.openfood.network.ProductsAPITest.SearchSubject.Companion.assertThat
import openfoodfacts.github.scrachx.openfood.network.services.ProductsAPI
import openfoodfacts.github.scrachx.openfood.utils.getUserAgent
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows
import retrofit2.Retrofit
import retrofit2.converter.jackson.JacksonConverterFactory
import retrofit2.create
Expand Down Expand Up @@ -111,10 +113,11 @@ class ProductsAPITest {
assertThat(search).hasFoundProducts()
}

@ExperimentalCoroutinesApi
@Test
fun `products by city paris not found`() = runBlocking {
val response = prodClient.getProductsByCity("paris")
assertThat(response).hasFoundNoProducts()
val exception = assertThrows<Exception> { prodClient.getProductsByCity("paris") }
Assertions.assertEquals("HTTP 404", exception.message?.trim())
}

@ExperimentalCoroutinesApi
Expand All @@ -127,7 +130,7 @@ class ProductsAPITest {

@Test
fun `product not found`() = runBlocking {
val barcode = "457457457"
val barcode = "457457457457"
val state = prodClient.getProductByBarcode(
barcode,
"code",
Expand Down Expand Up @@ -195,8 +198,8 @@ class ProductsAPITest {
fun setupClient() {
val httpClientWithAuth = OkHttpClient.Builder()
.addInterceptor(HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
.connectTimeout(Duration.ZERO)
.readTimeout(Duration.ZERO)
.connectTimeout(Duration.ofSeconds(30))
.readTimeout(Duration.ofSeconds(30))
.addInterceptor {
val origReq = it.request()
it.proceed(
Expand Down

0 comments on commit d712ba8

Please sign in to comment.