Skip to content
This repository was archived by the owner on Mar 20, 2025. It is now read-only.

Commit 9df6c5e

Browse files
authored
feat: get top の実装 (#114)
1 parent 600197e commit 9df6c5e

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed

src/main/kotlin/dev/sunabak0/akiyadego/presentation/ApplicationController.kt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package dev.sunabak0.akiyadego.presentation
22

33
import dev.sunabak0.akiyadego.openapi.generated.controller.DefaultApi
4+
import dev.sunabak0.akiyadego.openapi.generated.model.Post
5+
import dev.sunabak0.akiyadego.openapi.generated.model.PostResponse
46
import org.springframework.http.HttpStatus
57
import org.springframework.http.ResponseEntity
68
import org.springframework.web.bind.annotation.RestController
@@ -14,4 +16,24 @@ class ApplicationController : DefaultApi {
1416
override fun rootGet(): ResponseEntity<Unit> {
1517
return ResponseEntity(Unit, HttpStatus.OK)
1618
}
19+
20+
override fun allPost(): ResponseEntity<PostResponse> {
21+
return ResponseEntity(
22+
PostResponse(
23+
posts = listOf(
24+
Post(
25+
id = 1,
26+
imagePath = "",
27+
title = "",
28+
category = "",
29+
prefecture = "",
30+
description = "",
31+
userId = "",
32+
createdAt = ""
33+
),
34+
)
35+
),
36+
HttpStatus.OK
37+
)
38+
}
1739
}

src/test/kotlin/dev/sunabak0/akiyadego/api/integration/ApplicationTest.kt

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import org.assertj.core.api.Assertions.assertThat
44
import org.junit.jupiter.api.DisplayName
55
import org.junit.jupiter.api.Test
66
import org.junit.jupiter.api.TestInstance
7+
import org.skyscreamer.jsonassert.JSONAssert
8+
import org.skyscreamer.jsonassert.JSONCompareMode
79
import org.springframework.beans.factory.annotation.Autowired
810
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc
911
import org.springframework.boot.test.context.SpringBootTest
@@ -34,10 +36,58 @@ class ApplicationTest(@Autowired val mockMvc: MockMvc) {
3436

3537
/**
3638
* then:
39+
* - ステータスコードを比較
40+
* - レスポンスボディを比較
3741
*/
3842
val expectedStatus = HttpStatus.OK.value()
3943
val expectedResponseBody = "{}"
4044
assertThat(actualStatus).isEqualTo(expectedStatus)
4145
assertThat(actualResponseBody).isEqualTo(expectedResponseBody)
4246
}
47+
48+
@Test
49+
@DisplayName("GET /top のテスト")
50+
fun allPostTest() {
51+
/**
52+
* given:
53+
*/
54+
55+
/**
56+
* when:
57+
*/
58+
val response = mockMvc.get("/top") {
59+
contentType = MediaType.APPLICATION_JSON
60+
}.andReturn().response
61+
val actualStatus = response.status
62+
val actualResponseBody = response.contentAsString
63+
64+
/**
65+
* then:
66+
* - ステータスコードを比較
67+
* - レスポンスボディを比較
68+
*/
69+
val expectedStatus = HttpStatus.OK.value()
70+
val expectedResponseBody = """
71+
{
72+
"posts":[
73+
{
74+
"id":1,
75+
"imagePath":"",
76+
"title":"",
77+
"category":"",
78+
"prefecture":"",
79+
"description":"",
80+
"userId":"",
81+
"createdAt":""
82+
}
83+
],
84+
}
85+
""".trimIndent()
86+
assertThat(actualStatus).isEqualTo(expectedStatus)
87+
JSONAssert.assertEquals(
88+
expectedResponseBody,
89+
actualResponseBody,
90+
JSONCompareMode.NON_EXTENSIBLE
91+
)
92+
}
4393
}

0 commit comments

Comments
 (0)