Skip to content

Commit

Permalink
Merge pull request #21 from outfoxx/task/test-unit-result-response
Browse files Browse the repository at this point in the history
Add unit test for `Unit` result responses
  • Loading branch information
kdubb authored Dec 2, 2022
2 parents af8ddef + 41c06fb commit daceaba
Showing 1 changed file with 35 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,16 @@ abstract class GeneratedAPITests {
acceptTypes = listOf(JSON),
)

suspend fun testVoidResultResponse(): ResultResponse<Unit> =
requestFactory.resultResponse(
method = Method.Get,
pathTemplate = "/test",
)

}

@Test
fun `generated styel API result method`() {
fun `generated style API result method`() {

val testResult = API.TestResult("Test", 10)

Expand All @@ -93,7 +99,7 @@ abstract class GeneratedAPITests {
}

@Test
fun `generated styel API result response method`() {
fun `generated style API result response method`() {

val testResult = API.TestResult("Test", 10)

Expand All @@ -109,14 +115,38 @@ abstract class GeneratedAPITests {

val api = API(createRequestFactory(URITemplate(server.url("/").toString())))

val result = runBlocking { api.testResultResponse() }
val resultResponse = runBlocking { api.testResultResponse() }

assertThat(result.result, equalTo(testResult))
assertThat(resultResponse.result, equalTo(testResult))
assertThat(
result.headers.map { it.first.lowercase() to it.second.lowercase() },
resultResponse.headers.map { it.first.lowercase() to it.second.lowercase() },
hasItems(ContentType to JSON.value, ContentLength to "29")
)
}
}

@Test
fun `generated style API unit result response method`() {

val server = MockWebServer()
server.enqueue(
MockResponse()
.addHeader(ContentLength, "0")
.setResponseCode(204)
)
server.start()
server.use {

val api = API(createRequestFactory(URITemplate(server.url("/").toString())))

val responseResult = runBlocking { api.testVoidResultResponse() }

assertThat(responseResult.result, equalTo(Unit))
assertThat(
responseResult.headers.map { it.first.lowercase() to it.second.lowercase() },
hasItems(ContentLength to "0")
)
}
}

}

0 comments on commit daceaba

Please sign in to comment.