Files
hlaeja-device-registry/src/test/kotlin/ltd/hlaeja/controller/NodeControllerTest.kt
Swordsteel 53db4408e2 update get type(s) for pagination and filter
- update TypesEndpoint for all new endpoints
- update application to use properties for sql script
- update types controller
  - update types.http for all types of types calls
  - update test mocking for service
  - update getTypes to use filter, page, and show in TypesController
  - add validation dependency
- update unit test for uuid assertion from test library in
  - remove UUIDAssert.kt
  - update IdentityControllerTest
  - update MappingKtTest
  - update NodeControllerTest
  - update TypeControllerTest
  - update TypesControllerTest
  - add test library dependency
- update getTypes to handle filter limit and offset in TypeService
- update TypeRepository
  - add findAllContaining with filter, limit and offset
  - add findAll with limit and offset
- update type database with specific name key
- split Type and Types
2025-03-11 06:02:16 +01:00

51 lines
1.6 KiB
Kotlin

package ltd.hlaeja.controller
import io.mockk.coEvery
import io.mockk.coVerify
import io.mockk.mockk
import java.util.UUID
import kotlinx.coroutines.test.runTest
import ltd.hlaeja.entity.NodeEntity
import ltd.hlaeja.library.deviceRegistry.Node
import ltd.hlaeja.service.NodeService
import ltd.hlaeja.test.isEqualToUuid
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
class NodeControllerTest {
val service: NodeService = mockk()
lateinit var controller: NodeController
@BeforeEach
fun setUp() {
controller = NodeController(service)
}
@Test
fun `add device - success`() = runTest {
// given
val request: Node.Request = Node.Request(
UUID.fromString("00000000-0000-0000-0000-000000000001"),
UUID.fromString("00000000-0000-0000-0000-000000000002"),
"test",
)
coEvery { service.addNode(any()) } answers { call ->
(call.invocation.args[0] as NodeEntity).copy(id = UUID.fromString("00000000-0000-0000-0000-000000000003"))
}
// when
val response = controller.addNode(request)
// then
coVerify(exactly = 1) { service.addNode(any()) }
assertThat(response.id).isEqualToUuid("00000000-0000-0000-0000-000000000003")
assertThat(response.client).isEqualToUuid("00000000-0000-0000-0000-000000000001")
assertThat(response.device).isEqualToUuid("00000000-0000-0000-0000-000000000002")
assertThat(response.name).isEqualTo("test")
}
}