test: MediaAPIのテストを復活

This commit is contained in:
usbharu 2024-09-16 01:08:25 +09:00
parent 33d7bcb665
commit 5cc8267135
Signed by: usbharu
GPG Key ID: 95CBCF7046307B77
4 changed files with 16 additions and 1 deletions

1
.gitignore vendored
View File

@ -51,3 +51,4 @@ out/
/http-client.private.env.json /http-client.private.env.json
/logs/ /logs/
/hideout-mastodon/logs/ /hideout-mastodon/logs/
/hideout-mastodon/files/

View File

@ -21,9 +21,12 @@ import dev.usbharu.hideout.core.application.media.UploadMediaApplicationService
import dev.usbharu.hideout.core.infrastructure.springframework.oauth2.SpringSecurityOauth2PrincipalContextHolder import dev.usbharu.hideout.core.infrastructure.springframework.oauth2.SpringSecurityOauth2PrincipalContextHolder
import dev.usbharu.hideout.mastodon.interfaces.api.generated.MediaApi import dev.usbharu.hideout.mastodon.interfaces.api.generated.MediaApi
import dev.usbharu.hideout.mastodon.interfaces.api.generated.model.MediaAttachment import dev.usbharu.hideout.mastodon.interfaces.api.generated.model.MediaAttachment
import org.slf4j.LoggerFactory
import org.springframework.http.HttpStatus
import org.springframework.http.ResponseEntity import org.springframework.http.ResponseEntity
import org.springframework.stereotype.Controller import org.springframework.stereotype.Controller
import org.springframework.web.multipart.MultipartFile import org.springframework.web.multipart.MultipartFile
import org.springframework.web.server.ResponseStatusException
import java.nio.file.Files import java.nio.file.Files
@Controller @Controller
@ -37,6 +40,13 @@ class SpringMediaApi(
description: String?, description: String?,
focus: String?, focus: String?,
): ResponseEntity<MediaAttachment> { ): ResponseEntity<MediaAttachment> {
if (file.size == 0L) {
logger.warn("File is empty.")
throw ResponseStatusException(HttpStatus.BAD_REQUEST, "File is empty.")
}
val tempFile = Files.createTempFile("hideout-tmp-file", ".tmp") val tempFile = Files.createTempFile("hideout-tmp-file", ".tmp")
Files.newOutputStream(tempFile).use { outputStream -> Files.newOutputStream(tempFile).use { outputStream ->
@ -73,4 +83,8 @@ class SpringMediaApi(
) )
) )
} }
companion object {
private val logger = LoggerFactory.getLogger(SpringMediaApi::class.java)
}
} }

View File

@ -40,7 +40,7 @@ import org.springframework.web.context.WebApplicationContext
@SpringBootTest(classes = [SpringApplication::class]) @SpringBootTest(classes = [SpringApplication::class])
@AutoConfigureMockMvc @AutoConfigureMockMvc
@Transactional @Transactional
@Sql("/sql/actors.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_CLASS) @Sql("/sql/actors.sql","/sql/userdetail.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_CLASS)
class MediaTest { class MediaTest {
@Autowired @Autowired

View File

Before

Width:  |  Height:  |  Size: 7.1 KiB

After

Width:  |  Height:  |  Size: 7.1 KiB