-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dc7f085
commit d069f02
Showing
8 changed files
with
222 additions
and
226 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,11 +3,9 @@ package com.few.api.web.controller.admin | |
import com.epages.restdocs.apispec.ResourceDocumentation.resource | ||
import com.epages.restdocs.apispec.ResourceSnippetParameters | ||
import com.epages.restdocs.apispec.Schema | ||
import com.few.api.domain.admin.document.usecase.* | ||
import com.few.api.domain.admin.document.usecase.dto.* | ||
import com.few.api.web.controller.ControllerTestSpec | ||
import com.few.api.web.controller.admin.request.* | ||
import com.few.api.web.controller.admin.response.ImageSourceResponse | ||
import com.few.api.web.controller.description.Description | ||
import com.few.api.web.controller.helper.* | ||
import com.few.data.common.code.CategoryType | ||
|
@@ -24,12 +22,13 @@ import org.springframework.restdocs.payload.PayloadDocumentation | |
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status | ||
import org.springframework.web.util.UriComponentsBuilder | ||
import java.net.URL | ||
import java.util.stream.IntStream | ||
|
||
class AdminControllerTest : ControllerTestSpec() { | ||
|
||
companion object { | ||
private val BASE_URL = "/api/v1/admin" | ||
private val TAG = "AdminController" | ||
private const val BASE_URL = "/api/v1/admin" | ||
private const val TAG = "AdminController" | ||
} | ||
|
||
@Test | ||
|
@@ -44,9 +43,10 @@ class AdminControllerTest : ControllerTestSpec() { | |
val description = "description" | ||
val request = AddWorkbookRequest(title, mainImageUrl, category, description) | ||
val body = objectMapper.writeValueAsString(request) | ||
`when`(addWorkbookUseCase.execute(AddWorkbookUseCaseIn(title, mainImageUrl, category, description))).thenReturn( | ||
AddWorkbookUseCaseOut(1L) | ||
) | ||
|
||
val useCaseIn = AddWorkbookUseCaseIn(title, mainImageUrl, category, description) | ||
val useCaseOut = AddWorkbookUseCaseOut(1L) | ||
`when`(addWorkbookUseCase.execute(useCaseIn)).thenReturn(useCaseOut) | ||
|
||
// when | ||
mockMvc.perform( | ||
|
@@ -83,76 +83,54 @@ class AdminControllerTest : ControllerTestSpec() { | |
// given | ||
val api = "AddArticle" | ||
val uri = UriComponentsBuilder.newInstance().path("$BASE_URL/articles").build().toUriString() | ||
val request = AddArticleRequest( | ||
"[email protected]", | ||
URL("http://localhost:8080"), | ||
"title", | ||
CategoryType.fromCode(0)!!.name, | ||
"md", | ||
"content source", | ||
listOf( | ||
ProblemDto( | ||
"title1", | ||
listOf( | ||
ProblemContentDto(1L, "content1"), | ||
ProblemContentDto(2L, "content2"), | ||
ProblemContentDto(3L, "content3"), | ||
ProblemContentDto(4L, "content4") | ||
), | ||
"1", | ||
"explanation" | ||
), | ||
ProblemDto( | ||
"title2", | ||
listOf( | ||
ProblemContentDto(1L, "content1"), | ||
ProblemContentDto(2L, "content2"), | ||
ProblemContentDto(3L, "content3"), | ||
ProblemContentDto(4L, "content4") | ||
), | ||
"2", | ||
"explanation" | ||
) | ||
val writerEmail = "[email protected]" | ||
val articleImageURL = URL("http://localhost:8080") | ||
val title = "title" | ||
val category = CategoryType.fromCode(0)!!.name | ||
val contentType = "md" | ||
val contentSource = "content source" | ||
val problemDTOs = IntStream.range(0, 2).mapToObj { | ||
ProblemDto( | ||
"title$it", | ||
IntStream.range(0, 4).mapToObj { ProblemContentDto(it.toLong(), "content$it") }.toList(), | ||
"$it", | ||
"explanation$it" | ||
) | ||
}.toList() | ||
val problemDetails = problemDTOs.map { | ||
ProblemDetail( | ||
it.title, | ||
it.contents.map { content -> ProblemContentDetail(content.number, content.content) }, | ||
it.answer, | ||
it.explanation | ||
) | ||
} | ||
val request = AddArticleRequest( | ||
writerEmail, | ||
articleImageURL, | ||
title, | ||
category, | ||
contentType, | ||
contentSource, | ||
problemDTOs | ||
) | ||
val body = objectMapper.writeValueAsString(request) | ||
|
||
val useCaseIn = AddArticleUseCaseIn( | ||
writerEmail, | ||
articleImageURL, | ||
title, | ||
category, | ||
contentType, | ||
contentSource, | ||
problemDetails | ||
) | ||
val useCaseOut = AddArticleUseCaseOut(1L) | ||
`when`( | ||
addArticleUseCase.execute( | ||
AddArticleUseCaseIn( | ||
"[email protected]", | ||
URL("http://localhost:8080"), | ||
"title", | ||
CategoryType.fromCode(0)!!.name, | ||
"md", | ||
"content source", | ||
listOf( | ||
ProblemDetail( | ||
"title1", | ||
listOf( | ||
ProblemContentDetail(1L, "content1"), | ||
ProblemContentDetail(2L, "content2"), | ||
ProblemContentDetail(3L, "content3"), | ||
ProblemContentDetail(4L, "content4") | ||
), | ||
"1", | ||
"explanation" | ||
), | ||
ProblemDetail( | ||
"title2", | ||
listOf( | ||
ProblemContentDetail(1L, "content1"), | ||
ProblemContentDetail(2L, "content2"), | ||
ProblemContentDetail(3L, "content3"), | ||
ProblemContentDetail(4L, "content4") | ||
), | ||
"2", | ||
"explanation" | ||
) | ||
) | ||
) | ||
useCaseIn | ||
) | ||
).thenReturn(AddArticleUseCaseOut(1L)) | ||
).thenReturn(useCaseOut) | ||
|
||
// when | ||
mockMvc.perform( | ||
|
@@ -189,9 +167,14 @@ class AdminControllerTest : ControllerTestSpec() { | |
// given | ||
val api = "MapArticle" | ||
val uri = UriComponentsBuilder.newInstance().path("$BASE_URL/relations/articles").build().toUriString() | ||
val request = MapArticleRequest(1L, 1L, 1) | ||
val workbookId = 1L | ||
val articleId = 1L | ||
val dayCol = 1 | ||
val request = MapArticleRequest(workbookId, articleId, dayCol) | ||
val body = objectMapper.writeValueAsString(request) | ||
doNothing().`when`(mapArticleUseCase).execute(MapArticleUseCaseIn(1L, 1L, 1)) | ||
|
||
val useCaseIn = MapArticleUseCaseIn(workbookId, articleId, dayCol) | ||
doNothing().`when`(mapArticleUseCase).execute(useCaseIn) | ||
|
||
// when | ||
mockMvc.perform( | ||
|
@@ -221,7 +204,12 @@ class AdminControllerTest : ControllerTestSpec() { | |
// given | ||
val api = "ConvertContent" | ||
val uri = UriComponentsBuilder.newInstance().path("$BASE_URL/utilities/conversion/content").build().toUriString() | ||
val request = ConvertContentRequest(MockMultipartFile("content", "test.md", "text/markdown", "#test".toByteArray())) | ||
val name = "content" | ||
val originalFilename = "test.md" | ||
val contentType = "text/markdown" | ||
val content = "#test".toByteArray() | ||
val request = ConvertContentRequest(MockMultipartFile(name, originalFilename, contentType, content)) | ||
|
||
val useCaseOut = ConvertContentUseCaseOut("converted content", URL("http://localhost:8080/test.md")) | ||
val useCaseIn = ConvertContentUseCaseIn(request.content) | ||
`when`(convertContentUseCase.execute(useCaseIn)).thenReturn(useCaseOut) | ||
|
@@ -265,9 +253,13 @@ class AdminControllerTest : ControllerTestSpec() { | |
// given | ||
val api = "PutImage" | ||
val uri = UriComponentsBuilder.newInstance().path("$BASE_URL/utilities/conversion/image").build().toUriString() | ||
val request = ImageSourceRequest(source = MockMultipartFile("source", "test.jpg", "image/jpeg", "test".toByteArray())) | ||
val response = ImageSourceResponse(URL("http://localhost:8080/test.jpg"), listOf("jpg", "webp")) | ||
val useCaseOut = PutImageUseCaseOut(response.url, response.supportSuffix) | ||
val name = "source" | ||
val originalFilename = "test.jpg" | ||
val contentType = "image/jpeg" | ||
val content = "test".toByteArray() | ||
val request = ImageSourceRequest(source = MockMultipartFile(name, originalFilename, contentType, content)) | ||
|
||
val useCaseOut = PutImageUseCaseOut(URL("http://localhost:8080/test.jpg"), listOf("jpg", "webp")) | ||
val useCaseIn = PutImageUseCaseIn(request.source) | ||
`when`(putImageUseCase.execute(useCaseIn)).thenReturn(useCaseOut) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.