Skip to content

Commit b460c3d

Browse files
test: add medical technology api tests
1 parent 116ec5a commit b460c3d

File tree

1 file changed

+97
-0
lines changed

1 file changed

+97
-0
lines changed

src/test/kotlin/infrastructure/api/MedicalTechnologyApiTest.kt

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,29 @@ package infrastructure.api
1010

1111
import application.presenter.api.model.MedicalTechnologyApiDto
1212
import application.presenter.api.model.MedicalTechnologyApiDtoType
13+
import application.presenter.api.model.MedicalTechnologyPatch
14+
import application.presenter.api.model.RoomApiDto
15+
import application.presenter.api.model.RoomApiDtoType
1316
import infrastructure.api.KtorTestingUtility.apiTestApplication
1417
import io.kotest.assertions.ktor.client.shouldHaveStatus
1518
import io.kotest.core.spec.style.StringSpec
19+
import io.kotest.matchers.shouldBe
1620
import io.kotest.matchers.shouldNotBe
21+
import io.ktor.client.request.delete
22+
import io.ktor.client.request.get
1723
import io.ktor.client.request.header
24+
import io.ktor.client.request.patch
1825
import io.ktor.client.request.post
1926
import io.ktor.client.request.setBody
27+
import io.ktor.client.statement.bodyAsText
2028
import io.ktor.http.ContentType
2129
import io.ktor.http.HttpHeaders
2230
import io.ktor.http.HttpStatusCode
2331
import io.ktor.server.testing.ApplicationTestBuilder
32+
import kotlinx.serialization.decodeFromString
2433
import kotlinx.serialization.encodeToString
2534
import kotlinx.serialization.json.Json
35+
import java.time.Instant
2636

2737
class MedicalTechnologyApiTest : StringSpec({
2838
val medicalTechnologyApiDto = MedicalTechnologyApiDto(
@@ -55,4 +65,91 @@ class MedicalTechnologyApiTest : StringSpec({
5565
response shouldHaveStatus HttpStatusCode.Conflict
5666
}
5767
}
68+
69+
"It should be possible to obtain an existing medical technology" {
70+
apiTestApplication {
71+
insertMedicalTechnology(medicalTechnologyApiDto)
72+
val response = client.get("/api/v1/medical-technologies/${medicalTechnologyApiDto.id}")
73+
response shouldHaveStatus HttpStatusCode.OK
74+
Json.decodeFromString<MedicalTechnologyApiDto>(response.bodyAsText()) shouldBe medicalTechnologyApiDto
75+
}
76+
}
77+
78+
"It should be possible to obtain historical data about a medical technology" {
79+
apiTestApplication {
80+
insertMedicalTechnology(medicalTechnologyApiDto)
81+
val response = client
82+
.get("/api/v1/medical-technologies/${medicalTechnologyApiDto.id}?dateTime=${Instant.now()}")
83+
response shouldHaveStatus HttpStatusCode.OK
84+
}
85+
}
86+
87+
"It should handle the get request on a non existing medical technology" {
88+
apiTestApplication {
89+
val response = client.get("/api/v1/medical-technologies/${medicalTechnologyApiDto.id}")
90+
response shouldHaveStatus HttpStatusCode.NotFound
91+
}
92+
}
93+
94+
"It should be possible to delete an existing medical technology" {
95+
apiTestApplication {
96+
insertMedicalTechnology(medicalTechnologyApiDto)
97+
val response = client.delete("/api/v1/medical-technologies/${medicalTechnologyApiDto.id}")
98+
response shouldHaveStatus HttpStatusCode.NoContent
99+
}
100+
}
101+
102+
"It should not be possible to delete a not-existent medical technology" {
103+
apiTestApplication {
104+
val response = client.delete("/api/v1/medical-technologies/${medicalTechnologyApiDto.id}")
105+
response shouldHaveStatus HttpStatusCode.NotFound
106+
}
107+
}
108+
109+
"It should be possible to update the mapping of a medical technology" {
110+
apiTestApplication {
111+
// create room
112+
client.post("/api/v1/rooms") {
113+
header(HttpHeaders.ContentType, ContentType.Application.Json.toString())
114+
setBody(
115+
Json.encodeToString(
116+
RoomApiDto(
117+
"r1",
118+
"name",
119+
"z1",
120+
RoomApiDtoType.OPERATING_ROOM
121+
)
122+
)
123+
)
124+
}
125+
// create medical technology
126+
insertMedicalTechnology(medicalTechnologyApiDto)
127+
val response = client.patch("/api/v1/medical-technologies/${medicalTechnologyApiDto.id}") {
128+
header(HttpHeaders.ContentType, ContentType.Application.Json.toString())
129+
setBody(Json.encodeToString(MedicalTechnologyPatch("r1")))
130+
}
131+
response shouldHaveStatus HttpStatusCode.NoContent
132+
}
133+
}
134+
135+
"It should not be possible to map a non existent medical technology to a non existent room" {
136+
apiTestApplication {
137+
val response = client.patch("/api/v1/medical-technologies/${medicalTechnologyApiDto.id}") {
138+
header(HttpHeaders.ContentType, ContentType.Application.Json.toString())
139+
setBody(Json.encodeToString(MedicalTechnologyPatch("r1")))
140+
}
141+
response shouldHaveStatus HttpStatusCode.NotFound
142+
}
143+
}
144+
145+
"It should not be possible to map an existent medical technology to a non existent room" {
146+
apiTestApplication {
147+
insertMedicalTechnology(medicalTechnologyApiDto)
148+
val response = client.patch("/api/v1/medical-technologies/${medicalTechnologyApiDto.id}") {
149+
header(HttpHeaders.ContentType, ContentType.Application.Json.toString())
150+
setBody(Json.encodeToString(MedicalTechnologyPatch("r1")))
151+
}
152+
response shouldHaveStatus HttpStatusCode.NotFound
153+
}
154+
}
58155
})

0 commit comments

Comments
 (0)