mirror of
https://github.com/usbharu/Hideout.git
synced 2026-09-29 16:31:30 +00:00
test: apps apiのテストを追加
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
package mastodon.apps
|
||||
|
||||
import dev.usbharu.hideout.SpringApplication
|
||||
import dev.usbharu.hideout.core.infrastructure.springframework.oauth2.RegisteredClient
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.jetbrains.exposed.sql.select
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc
|
||||
import org.springframework.boot.test.context.SpringBootTest
|
||||
import org.springframework.http.MediaType
|
||||
import org.springframework.security.test.context.support.WithAnonymousUser
|
||||
import org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers
|
||||
import org.springframework.test.web.servlet.MockMvc
|
||||
import org.springframework.test.web.servlet.post
|
||||
import org.springframework.test.web.servlet.setup.DefaultMockMvcBuilder
|
||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders
|
||||
import org.springframework.transaction.annotation.Transactional
|
||||
import org.springframework.web.context.WebApplicationContext
|
||||
|
||||
@SpringBootTest(classes = [SpringApplication::class])
|
||||
@AutoConfigureMockMvc
|
||||
@Transactional
|
||||
class AppTest {
|
||||
|
||||
@Autowired
|
||||
private lateinit var context: WebApplicationContext
|
||||
|
||||
private lateinit var mockMvc: MockMvc
|
||||
|
||||
|
||||
@BeforeEach
|
||||
fun setUp() {
|
||||
mockMvc = MockMvcBuilders.webAppContextSetup(context)
|
||||
.apply<DefaultMockMvcBuilder>(SecurityMockMvcConfigurers.springSecurity())
|
||||
.build()
|
||||
}
|
||||
|
||||
@Test
|
||||
@WithAnonymousUser
|
||||
fun apiV1AppsPostにformで匿名でappを作成できる() {
|
||||
mockMvc
|
||||
.post("/api/v1/apps") {
|
||||
contentType = MediaType.APPLICATION_FORM_URLENCODED
|
||||
param("client_name", "test-client")
|
||||
param("redirect_uris", "https://example.com")
|
||||
param("scopes", "write read")
|
||||
param("website", "https://example.com")
|
||||
}
|
||||
.asyncDispatch()
|
||||
.andExpect { status { isOk() } }
|
||||
|
||||
|
||||
val app = RegisteredClient
|
||||
.select { RegisteredClient.clientName eq "test-client" }
|
||||
.single()
|
||||
|
||||
assertThat(app[RegisteredClient.clientName]).isEqualTo("test-client")
|
||||
assertThat(app[RegisteredClient.redirectUris]).isEqualTo("https://example.com")
|
||||
assertThat(app[RegisteredClient.scopes]).isEqualTo("read,write")
|
||||
}
|
||||
|
||||
@Test
|
||||
@WithAnonymousUser
|
||||
fun apiV1AppsPostにjsonで匿名でappを作成できる() {
|
||||
mockMvc
|
||||
.post("/api/v1/apps") {
|
||||
contentType = MediaType.APPLICATION_JSON
|
||||
content = """{
|
||||
"client_name": "test-client-2",
|
||||
"redirect_uris": "https://example.com",
|
||||
"scopes": "write read",
|
||||
"website": "https;//example.com"
|
||||
}"""
|
||||
}
|
||||
.asyncDispatch()
|
||||
.andExpect { status { isOk() } }
|
||||
|
||||
val app = RegisteredClient
|
||||
.select { RegisteredClient.clientName eq "test-client-2" }
|
||||
.single()
|
||||
|
||||
assertThat(app[RegisteredClient.clientName]).isEqualTo("test-client-2")
|
||||
assertThat(app[RegisteredClient.redirectUris]).isEqualTo("https://example.com")
|
||||
assertThat(app[RegisteredClient.scopes]).isEqualTo("read,write")
|
||||
}
|
||||
}
|
||||
@@ -18,10 +18,10 @@ hideout:
|
||||
|
||||
spring:
|
||||
flyway:
|
||||
enabled: false
|
||||
enabled: true
|
||||
datasource:
|
||||
driver-class-name: org.h2.Driver
|
||||
url: "jdbc:h2:mem:test;MODE=POSTGRESQL;DB_CLOSE_DELAY=-1"
|
||||
url: "jdbc:h2:mem:test;MODE=POSTGRESQL;DB_CLOSE_DELAY=-1;CASE_INSENSITIVE_IDENTIFIERS=true;TRACE_LEVEL_FILE=4;"
|
||||
username: ""
|
||||
password:
|
||||
data:
|
||||
@@ -34,8 +34,8 @@ spring:
|
||||
console:
|
||||
enabled: true
|
||||
|
||||
exposed:
|
||||
generate-ddl: true
|
||||
excluded-packages: dev.usbharu.hideout.core.infrastructure.kjobexposed
|
||||
# exposed:
|
||||
# generate-ddl: true
|
||||
# excluded-packages: dev.usbharu.hideout.core.infrastructure.kjobexposed
|
||||
server:
|
||||
port: 8080
|
||||
|
||||
Reference in New Issue
Block a user