-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* test: 테스트 수정 * style: 스타일 수정
- Loading branch information
Showing
7 changed files
with
248 additions
and
3 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
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
139 changes: 139 additions & 0 deletions
139
app/src/test/kotlin/com/wespot/user/service/CheckedUserRestrictionServiceTest.kt
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 |
---|---|---|
@@ -0,0 +1,139 @@ | ||
package com.wespot.user.service | ||
|
||
import com.wespot.common.service.ServiceTest | ||
import com.wespot.user.RestrictionType | ||
import com.wespot.user.fixture.UserFixture | ||
import com.wespot.user.port.out.UserPort | ||
import io.kotest.matchers.shouldBe | ||
import org.springframework.beans.factory.annotation.Autowired | ||
import java.time.LocalDate | ||
import kotlin.test.Test | ||
|
||
class CheckedUserRestrictionServiceTest @Autowired constructor( | ||
private val userPort: UserPort, | ||
private val checkedUserRestrictionService: CheckedUserRestrictionService | ||
) : ServiceTest() { | ||
|
||
@Test | ||
fun `사용자가 제한을 당하지 않은 것을 확인한다`() { | ||
// given | ||
val user = UserFixture.createWithId(0) | ||
val savedUser = userPort.save(user) | ||
UserFixture.setSecurityContextUser(savedUser) | ||
|
||
// when | ||
val response = checkedUserRestrictionService.getUserRestriction() | ||
|
||
// then | ||
response.messageRestrictionType shouldBe RestrictionType.NONE | ||
response.messageReleaseDate shouldBe LocalDate.of(9999, 12, 31) | ||
response.voteRestrictionType shouldBe RestrictionType.NONE | ||
response.voteReleaseDate shouldBe LocalDate.of(9999, 12, 31) | ||
} | ||
|
||
@Test | ||
fun `사용자가 메시지로 인해 제한을 당한 것을 확인한다`() { | ||
// given | ||
val user = | ||
UserFixture.createUserWithRestrictionTypeAndRestrictDay( | ||
listOf( | ||
Pair( | ||
RestrictionType.PERMANENT_BAN_MESSAGE_REPORT, | ||
Long.MAX_VALUE | ||
) | ||
) | ||
) | ||
val savedUser = userPort.save(user) | ||
UserFixture.setSecurityContextUser(savedUser) | ||
|
||
// when | ||
val response = checkedUserRestrictionService.getUserRestriction() | ||
|
||
// then | ||
response.messageRestrictionType shouldBe RestrictionType.PERMANENT_BAN_MESSAGE_REPORT | ||
response.messageReleaseDate shouldBe LocalDate.of(9999, 12, 31) | ||
response.voteRestrictionType shouldBe RestrictionType.NONE | ||
response.voteReleaseDate shouldBe LocalDate.of(9999, 12, 31) | ||
} | ||
|
||
@Test | ||
fun `사용자가 투표로 인해 제한을 당한 것을 확인한다`() { | ||
// given | ||
val user = | ||
UserFixture.createUserWithRestrictionTypeAndRestrictDay( | ||
listOf( | ||
Pair( | ||
RestrictionType.PERMANENT_BAN_VOTE_REPORT, | ||
Long.MAX_VALUE | ||
) | ||
) | ||
) | ||
val savedUser = userPort.save(user) | ||
UserFixture.setSecurityContextUser(savedUser) | ||
|
||
// when | ||
val response = checkedUserRestrictionService.getUserRestriction() | ||
|
||
// then | ||
response.messageRestrictionType shouldBe RestrictionType.NONE | ||
response.messageReleaseDate shouldBe LocalDate.of(9999, 12, 31) | ||
response.voteRestrictionType shouldBe RestrictionType.PERMANENT_BAN_VOTE_REPORT | ||
response.voteReleaseDate shouldBe LocalDate.of(9999, 12, 31) | ||
} | ||
|
||
@Test | ||
fun `사용자가 투표, 쪽지로 인해 제한을 당한 것을 확인한다`() { | ||
// given | ||
val user = | ||
UserFixture.createUserWithRestrictionTypeAndRestrictDay( | ||
listOf( | ||
Pair( | ||
RestrictionType.PERMANENT_BAN_VOTE_REPORT, | ||
Long.MAX_VALUE | ||
), | ||
Pair( | ||
RestrictionType.PERMANENT_BAN_MESSAGE_REPORT, | ||
Long.MAX_VALUE | ||
) | ||
) | ||
) | ||
val savedUser = userPort.save(user) | ||
UserFixture.setSecurityContextUser(savedUser) | ||
|
||
// when | ||
val response = checkedUserRestrictionService.getUserRestriction() | ||
|
||
// then | ||
response.messageRestrictionType shouldBe RestrictionType.PERMANENT_BAN_MESSAGE_REPORT | ||
response.messageReleaseDate shouldBe LocalDate.of(9999, 12, 31) | ||
response.voteRestrictionType shouldBe RestrictionType.PERMANENT_BAN_VOTE_REPORT | ||
response.voteReleaseDate shouldBe LocalDate.of(9999, 12, 31) | ||
} | ||
|
||
@Test | ||
fun `쪽지 90일 제한을 받은 사용자의 제한을 확인한다`() { | ||
// given | ||
val now = LocalDate.now() | ||
val user = | ||
UserFixture.createUserWithRestrictionTypeAndRestrictDay( | ||
listOf( | ||
Pair( | ||
RestrictionType.TEMPORARY_BAN_MESSAGE_REPORT, | ||
90 | ||
) | ||
) | ||
) | ||
val savedUser = userPort.save(user) | ||
UserFixture.setSecurityContextUser(savedUser) | ||
|
||
// when | ||
val response = checkedUserRestrictionService.getUserRestriction() | ||
|
||
// then | ||
response.messageRestrictionType shouldBe RestrictionType.TEMPORARY_BAN_MESSAGE_REPORT | ||
response.messageReleaseDate shouldBe now.plusDays(90) | ||
response.voteRestrictionType shouldBe RestrictionType.NONE | ||
response.voteReleaseDate shouldBe LocalDate.of(9999, 12, 31) | ||
} | ||
|
||
} |
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
27 changes: 27 additions & 0 deletions
27
core/src/main/kotlin/com/wespot/user/dto/response/CheckedRestrictionResponse.kt
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.wespot.user.dto.response | ||
|
||
import com.wespot.user.RestrictionType | ||
import com.wespot.user.User | ||
import java.time.LocalDate | ||
|
||
data class CheckedRestrictionResponse( | ||
val messageRestrictionType: RestrictionType, | ||
val messageReleaseDate: LocalDate, | ||
val voteRestrictionType: RestrictionType, | ||
val voteReleaseDate: LocalDate, | ||
) { | ||
|
||
companion object { | ||
|
||
fun from(user: User): CheckedRestrictionResponse { | ||
return CheckedRestrictionResponse( | ||
user.restriction.messageRestriction.restrictionType, | ||
user.restriction.messageRestriction.releaseDate, | ||
user.restriction.voteRestriction.restrictionType, | ||
user.restriction.voteRestriction.releaseDate | ||
) | ||
} | ||
|
||
} | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
core/src/main/kotlin/com/wespot/user/port/in/CheckedUserRestrictionUseCase.kt
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.wespot.user.port.`in` | ||
|
||
import com.wespot.user.dto.response.CheckedRestrictionResponse | ||
|
||
interface CheckedUserRestrictionUseCase { | ||
|
||
fun getUserRestriction(): CheckedRestrictionResponse | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
core/src/main/kotlin/com/wespot/user/service/CheckedUserRestrictionService.kt
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.wespot.user.service | ||
|
||
import com.wespot.auth.service.SecurityUtils | ||
import com.wespot.user.dto.response.CheckedRestrictionResponse | ||
import com.wespot.user.port.`in`.CheckedUserRestrictionUseCase | ||
import com.wespot.user.port.out.UserPort | ||
import org.springframework.stereotype.Service | ||
import org.springframework.transaction.annotation.Transactional | ||
|
||
@Service | ||
class CheckedUserRestrictionService( | ||
private val userPort: UserPort | ||
) : CheckedUserRestrictionUseCase { | ||
|
||
@Transactional(readOnly = true) | ||
override fun getUserRestriction(): CheckedRestrictionResponse { | ||
val loginUser = SecurityUtils.getLoginUser(userPort) | ||
|
||
return CheckedRestrictionResponse.from(loginUser) | ||
} | ||
|
||
} |