Skip to content

Commit

Permalink
Happy-test
Browse files Browse the repository at this point in the history
  • Loading branch information
anotheroneofthese committed Aug 20, 2024
1 parent d0fd600 commit 25c1c91
Showing 1 changed file with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package no.nb.mlt.wls.order.controller

import com.ninjasquad.springmockk.MockkBean
import io.mockk.coEvery
import io.mockk.junit5.MockKExtension
import kotlinx.coroutines.reactor.awaitSingle
import kotlinx.coroutines.runBlocking
Expand All @@ -18,6 +19,7 @@ import no.nb.mlt.wls.order.payloads.toOrder
import no.nb.mlt.wls.order.repository.OrderRepository
import no.nb.mlt.wls.order.service.OrderService
import no.nb.mlt.wls.order.service.SynqOrderService
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.TestInstance
Expand All @@ -28,8 +30,12 @@ import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWeb
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT
import org.springframework.data.mongodb.repository.config.EnableMongoRepositories
import org.springframework.http.MediaType
import org.springframework.http.ResponseEntity
import org.springframework.security.test.context.support.WithMockUser
import org.springframework.security.test.web.reactive.server.SecurityMockServerConfigurers.csrf
import org.springframework.test.web.reactive.server.WebTestClient
import java.net.URI

@EnableTestcontainers
@TestInstance(PER_CLASS)
Expand Down Expand Up @@ -61,6 +67,25 @@ class OrderControllerTest(
@WithMockUser
fun `createOrder with valid payload creates order`() =
runTest {
coEvery {
synqOrderService.createOrder(any())
} returns ResponseEntity.created(URI.create("")).build()

webTestClient
.mutateWith(csrf())
.post()
.uri("/batch/create")
.accept(MediaType.APPLICATION_JSON)
.bodyValue(testOrderPayload)
.exchange()
.expectStatus().isCreated

val order = repository.findByHostNameAndHostOrderId(testOrderPayload.hostName, testOrderPayload.hostOrderId).awaitSingle()

assertThat(order)
.isNotNull
.extracting("callbackUrl", "status")
.containsExactly("callbackUrl", "Not started")
}

@Test
Expand Down

0 comments on commit 25c1c91

Please sign in to comment.