Skip to content

Commit 207ee20

Browse files
test: add post test on medical technology api
1 parent f90ae93 commit 207ee20

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright (c) 2023. Smart Operating Block
3+
*
4+
* Use of this source code is governed by an MIT-style
5+
* license that can be found in the LICENSE file or at
6+
* https://opensource.org/licenses/MIT.
7+
*/
8+
9+
package infrastructure.api
10+
11+
import application.presenter.api.model.MedicalTechnologyApiDto
12+
import application.presenter.api.model.MedicalTechnologyApiDtoType
13+
import infrastructure.api.KtorTestingUtility.apiTestApplication
14+
import io.kotest.assertions.ktor.client.shouldHaveStatus
15+
import io.kotest.core.spec.style.StringSpec
16+
import io.kotest.matchers.shouldNotBe
17+
import io.ktor.client.request.header
18+
import io.ktor.client.request.post
19+
import io.ktor.client.request.setBody
20+
import io.ktor.http.ContentType
21+
import io.ktor.http.HttpHeaders
22+
import io.ktor.http.HttpStatusCode
23+
import io.ktor.server.testing.ApplicationTestBuilder
24+
import kotlinx.serialization.encodeToString
25+
import kotlinx.serialization.json.Json
26+
27+
class MedicalTechnologyApiTest : StringSpec({
28+
val medicalTechnologyApiDto = MedicalTechnologyApiDto(
29+
id = "mt-1",
30+
name = "name",
31+
description = "description",
32+
type = MedicalTechnologyApiDtoType.ENDOSCOPE,
33+
inUse = true,
34+
roomId = "r-1"
35+
)
36+
37+
suspend fun ApplicationTestBuilder.insertMedicalTechnology(medicalTechnology: MedicalTechnologyApiDto) =
38+
client.post("/api/v1/medical-technologies") {
39+
header(HttpHeaders.ContentType, ContentType.Application.Json.toString())
40+
setBody(Json.encodeToString(medicalTechnology))
41+
}
42+
43+
"I should be able to request the creation of a medical technology" {
44+
apiTestApplication {
45+
val response = insertMedicalTechnology(medicalTechnologyApiDto)
46+
response shouldHaveStatus HttpStatusCode.Created
47+
response.headers[HttpHeaders.Location] shouldNotBe null
48+
}
49+
}
50+
51+
"Add an existent medical technology then the service should result in a conflict status code" {
52+
apiTestApplication {
53+
insertMedicalTechnology(medicalTechnologyApiDto)
54+
val response = insertMedicalTechnology(medicalTechnologyApiDto)
55+
response shouldHaveStatus HttpStatusCode.Conflict
56+
}
57+
}
58+
})

0 commit comments

Comments
 (0)