Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ASAP-212 fix: 새 행성 생성 시 메인 행성으로 수정하도록 변경 #99

Merged
merged 1 commit into from
Oct 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ interface SpaceManagementPort {
spaceId: DomainId,
): Space

fun getIndexedSpaceNotNull(
userId: DomainId,
spaceId: DomainId,
): IndexedSpace

fun getAllIndexedSpace(userId: DomainId): List<IndexedSpace>

fun save(space: Space): Space
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ class SpaceCommandService(
userId = DomainId(command.userId),
name = command.spaceName,
templateType = command.templateType,
).let {
spaceManagementPort.save(it)
).apply {
spaceManagementPort.save(this)
}
reIndexingSpaceOrder(DomainId(command.userId))
}

override fun update(command: UpdateSpaceNameUsecase.Command) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,8 @@ import org.springframework.context.annotation.Bean

@TestConfiguration
class SpaceApplicationConfig(
private val spaceManagementPort: SpaceManagementPort
private val spaceManagementPort: SpaceManagementPort,
) {

@Bean
fun spaceMockManager(): SpaceMockManager {
return SpaceMockManager(spaceManagementPort)
}
}
fun spaceMockManager(): SpaceMockManager = SpaceMockManager(spaceManagementPort)
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,22 @@ import com.asap.domain.space.entity.Space
class SpaceMockManager(
private val spaceManagementPort: SpaceManagementPort,
) {
fun settingSpace(userId: String): Space {
fun settingSpace(
userId: String,
index: Int = 0,
): Space {
val space =
Space.create(
userId = DomainId(userId),
name = "test",
templateType = 0,
)
return spaceManagementPort.save(space)
return spaceManagementPort.save(space).also {
spaceManagementPort.getIndexedSpaceNotNull(DomainId(userId), it.id).apply {
updateIndex(index)
spaceManagementPort.update(this)
}
}
}

fun getSpaceIndexes(userId: String): List<Pair<String, Int>> =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,26 +112,81 @@ class SpaceApiIntegrationTest : IntegrationSupporter() {
}
}

@Test
fun createSpace() {
// given
val userId = userMockManager.settingUser()
val accessToken = jwtMockManager.generateAccessToken(userId)
val request =
CreateSpaceRequest(
spaceName = "spaceName",
templateType = 0,
)
// when
val response =
@Nested
inner class CreateSpace {
@Test
fun createSpace() {
// given
val userId = userMockManager.settingUser()
val accessToken = jwtMockManager.generateAccessToken(userId)
val request =
CreateSpaceRequest(
spaceName = "spaceName",
templateType = 0,
)
// when
val response =
mockMvc.post("/api/v1/spaces") {
contentType = MediaType.APPLICATION_JSON
content = objectMapper.writeValueAsString(request)
header("Authorization", "Bearer $accessToken")
}
// then
response.andExpect {
status { isOk() }
}
}

@Test
fun createSpace_and_get_main_space() {
// given
val userId = userMockManager.settingUser()
val accessToken = jwtMockManager.generateAccessToken(userId)
(0..2).forEach {
spaceMockManager.settingSpace(userId)
}
val request =
CreateSpaceRequest(
spaceName = "createdSpace",
templateType = 0,
)
// when
mockMvc.post("/api/v1/spaces") {
contentType = MediaType.APPLICATION_JSON
content = objectMapper.writeValueAsString(request)
header("Authorization", "Bearer $accessToken")
}
// then
response.andExpect {
status { isOk() }
val response =
mockMvc.get("/api/v1/spaces/main") {
contentType = MediaType.APPLICATION_JSON
header("Authorization", "Bearer $accessToken")
}

// then
response.andExpect {
status { isOk() }
jsonPath("$.spaceId") {
exists()
isString()
isNotEmpty()
}
jsonPath("$.username") {
exists()
isString()
isNotEmpty()
}
jsonPath("$.templateType") {
exists()
isNumber()
value(request.templateType)
}
jsonPath("$.spaceName") {
exists()
isString()
isNotEmpty()
value(request.spaceName)
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ class SpaceManagementJpaAdapter(
SpaceMapper.toSpace(it)
} ?: throw SpaceException.SpaceNotFoundException()

override fun getIndexedSpaceNotNull(
userId: DomainId,
spaceId: DomainId,
): IndexedSpace {
spaceJpaRepository.findActiveSpaceByIdAndUserId(spaceId.value, userId.value)?.let {
return SpaceMapper.toIndexedSpace(it)
} ?: throw SpaceException.SpaceNotFoundException()
}

override fun getAllIndexedSpace(userId: DomainId): List<IndexedSpace> =
spaceJpaRepository
.findAllActiveSpaceByUserId(userId.value)
Expand All @@ -42,7 +51,7 @@ class SpaceManagementJpaAdapter(
val entity =
SpaceMapper.toSpaceEntity(
space = space,
index = spaceJpaRepository.countActiveSpaceByUserId(space.userId.value).toInt(),
index = -1,
)
return spaceJpaRepository.save(entity).let {
SpaceMapper.toSpace(it)
Expand Down
Loading