mirror of https://github.com/usbharu/Hideout.git
test: テストを修正
This commit is contained in:
parent
64cd9c0a34
commit
1089f63e36
|
@ -28,6 +28,7 @@ class OutboxControllerImplTest {
|
||||||
fun `outbox GETに501を返す`() {
|
fun `outbox GETに501を返す`() {
|
||||||
mockMvc
|
mockMvc
|
||||||
.get("/outbox")
|
.get("/outbox")
|
||||||
|
.asyncDispatch()
|
||||||
.andDo { print() }
|
.andDo { print() }
|
||||||
.andExpect { status { isNotImplemented() } }
|
.andExpect { status { isNotImplemented() } }
|
||||||
}
|
}
|
||||||
|
@ -36,6 +37,7 @@ class OutboxControllerImplTest {
|
||||||
fun `user-outbox GETに501を返す`() {
|
fun `user-outbox GETに501を返す`() {
|
||||||
mockMvc
|
mockMvc
|
||||||
.get("/users/hoge/outbox")
|
.get("/users/hoge/outbox")
|
||||||
|
.asyncDispatch()
|
||||||
.andDo { print() }
|
.andDo { print() }
|
||||||
.andExpect { status { isNotImplemented() } }
|
.andExpect { status { isNotImplemented() } }
|
||||||
}
|
}
|
||||||
|
@ -44,6 +46,7 @@ class OutboxControllerImplTest {
|
||||||
fun `outbox POSTに501を返す`() {
|
fun `outbox POSTに501を返す`() {
|
||||||
mockMvc
|
mockMvc
|
||||||
.post("/outbox")
|
.post("/outbox")
|
||||||
|
.asyncDispatch()
|
||||||
.andDo { print() }
|
.andDo { print() }
|
||||||
.andExpect { status { isNotImplemented() } }
|
.andExpect { status { isNotImplemented() } }
|
||||||
}
|
}
|
||||||
|
@ -52,6 +55,7 @@ class OutboxControllerImplTest {
|
||||||
fun `user-outbox POSTに501を返す`() {
|
fun `user-outbox POSTに501を返す`() {
|
||||||
mockMvc
|
mockMvc
|
||||||
.post("/users/hoge/outbox")
|
.post("/users/hoge/outbox")
|
||||||
|
.asyncDispatch()
|
||||||
.andDo { print() }
|
.andDo { print() }
|
||||||
.andExpect { status { isNotImplemented() } }
|
.andExpect { status { isNotImplemented() } }
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package dev.usbharu.hideout.core.service.reaction
|
||||||
|
|
||||||
import dev.usbharu.hideout.activitypub.service.activity.like.APReactionService
|
import dev.usbharu.hideout.activitypub.service.activity.like.APReactionService
|
||||||
import dev.usbharu.hideout.application.service.id.TwitterSnowflakeIdGenerateService
|
import dev.usbharu.hideout.application.service.id.TwitterSnowflakeIdGenerateService
|
||||||
|
import dev.usbharu.hideout.core.domain.exception.FailedToGetResourcesException
|
||||||
import dev.usbharu.hideout.core.domain.model.reaction.Reaction
|
import dev.usbharu.hideout.core.domain.model.reaction.Reaction
|
||||||
import dev.usbharu.hideout.core.domain.model.reaction.ReactionRepository
|
import dev.usbharu.hideout.core.domain.model.reaction.ReactionRepository
|
||||||
import dev.usbharu.hideout.core.query.ReactionQueryService
|
import dev.usbharu.hideout.core.query.ReactionQueryService
|
||||||
|
@ -88,7 +89,9 @@ class ReactionServiceImplTest {
|
||||||
@Test
|
@Test
|
||||||
fun `sendReaction リアクションが存在しないとき保存して配送する`() = runTest {
|
fun `sendReaction リアクションが存在しないとき保存して配送する`() = runTest {
|
||||||
val post = PostBuilder.of()
|
val post = PostBuilder.of()
|
||||||
whenever(reactionQueryService.reactionAlreadyExist(eq(post.id), eq(post.userId), eq(0))).doReturn(false)
|
whenever(reactionQueryService.findByPostIdAndUserIdAndEmojiId(eq(post.id), eq(post.userId), eq(0))).doThrow(
|
||||||
|
FailedToGetResourcesException::class
|
||||||
|
)
|
||||||
val generateId = TwitterSnowflakeIdGenerateService.generateId()
|
val generateId = TwitterSnowflakeIdGenerateService.generateId()
|
||||||
whenever(reactionRepository.generateId()).doReturn(generateId)
|
whenever(reactionRepository.generateId()).doReturn(generateId)
|
||||||
|
|
||||||
|
@ -101,23 +104,28 @@ class ReactionServiceImplTest {
|
||||||
@Test
|
@Test
|
||||||
fun `sendReaction リアクションが存在するときは削除して保存して配送する`() = runTest {
|
fun `sendReaction リアクションが存在するときは削除して保存して配送する`() = runTest {
|
||||||
val post = PostBuilder.of()
|
val post = PostBuilder.of()
|
||||||
whenever(reactionQueryService.reactionAlreadyExist(eq(post.id), eq(post.userId), eq(0))).doReturn(true)
|
val id = TwitterSnowflakeIdGenerateService.generateId()
|
||||||
|
whenever(reactionQueryService.findByPostIdAndUserIdAndEmojiId(eq(post.id), eq(post.userId), eq(0))).doReturn(
|
||||||
|
Reaction(id, 0, post.id, post.userId)
|
||||||
|
)
|
||||||
val generateId = TwitterSnowflakeIdGenerateService.generateId()
|
val generateId = TwitterSnowflakeIdGenerateService.generateId()
|
||||||
whenever(reactionRepository.generateId()).doReturn(generateId)
|
whenever(reactionRepository.generateId()).doReturn(generateId)
|
||||||
|
|
||||||
reactionServiceImpl.sendReaction("❤", post.userId, post.id)
|
reactionServiceImpl.sendReaction("❤", post.userId, post.id)
|
||||||
|
|
||||||
|
|
||||||
verify(reactionRepository, times(1)).delete(eq(Reaction(generateId, 0, post.id, post.userId)))
|
verify(reactionRepository, times(1)).delete(eq(Reaction(id, 0, post.id, post.userId)))
|
||||||
verify(reactionRepository, times(1)).save(eq(Reaction(generateId, 0, post.id, post.userId)))
|
verify(reactionRepository, times(1)).save(eq(Reaction(generateId, 0, post.id, post.userId)))
|
||||||
verify(apReactionService, times(1)).removeReaction(eq(Reaction(generateId, 0, post.id, post.userId)))
|
verify(apReactionService, times(1)).removeReaction(eq(Reaction(id, 0, post.id, post.userId)))
|
||||||
verify(apReactionService, times(1)).reaction(eq(Reaction(generateId, 0, post.id, post.userId)))
|
verify(apReactionService, times(1)).reaction(eq(Reaction(generateId, 0, post.id, post.userId)))
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `removeReaction リアクションが存在する場合削除して配送`() = runTest {
|
fun `removeReaction リアクションが存在する場合削除して配送`() = runTest {
|
||||||
val post = PostBuilder.of()
|
val post = PostBuilder.of()
|
||||||
whenever(reactionQueryService.reactionAlreadyExist(eq(post.id), eq(post.userId), eq(0))).doReturn(true)
|
whenever(reactionQueryService.findByPostIdAndUserIdAndEmojiId(eq(post.id), eq(post.userId), eq(0))).doReturn(
|
||||||
|
Reaction(0, 0, post.id, post.userId)
|
||||||
|
)
|
||||||
|
|
||||||
reactionServiceImpl.removeReaction(post.userId, post.id)
|
reactionServiceImpl.removeReaction(post.userId, post.id)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue