1 package net.pterodactylus.sone.fcp
3 import com.google.common.base.Optional.of
4 import net.pterodactylus.sone.core.Core
5 import net.pterodactylus.sone.data.PostReply
6 import net.pterodactylus.sone.test.mock
7 import net.pterodactylus.sone.test.whenever
8 import org.hamcrest.MatcherAssert.assertThat
9 import org.hamcrest.Matchers.equalTo
11 import org.mockito.Mockito.verify
14 * Unit test for [DeleteReplyCommand].
16 class DeleteReplyCommandTest : SoneCommandTest() {
18 private val remotePostReply = mock<PostReply>().apply { whenever(sone).thenReturn(remoteSone) }
19 private val localPostReply = mock<PostReply>().apply { whenever(sone).thenReturn(localSone) }
21 override fun createCommand(core: Core) = DeleteReplyCommand(core)
24 fun `command requires write access`() {
25 assertThat(command.requiresWriteAccess(), equalTo(true))
29 fun `request without any parameters results in fcp exception`() {
30 requestWithoutAnyParameterResultsInFcpException()
34 fun `request with invalid post reply parameter results in fcp exception`() {
35 parameters += "Reply" to "InvalidReplyId"
36 executeCommandAndExpectFcpException()
40 fun `request with remote post reply parameter results in error response`() {
41 parameters += "Reply" to "RemoteReplyId"
42 whenever(core.getPostReply("RemoteReplyId")).thenReturn(of(remotePostReply))
43 val response = command.execute(parameters)
44 assertThat(response.replyParameters["Message"], equalTo("Error"))
45 assertThat(response.replyParameters["ErrorCode"], equalTo("401"))
49 fun `request with local post reply parameter deletes reply`() {
50 parameters += "Reply" to "RemoteReplyId"
51 whenever(core.getPostReply("RemoteReplyId")).thenReturn(of(localPostReply))
52 val response = command.execute(parameters)
53 assertThat(response.replyParameters["Message"], equalTo("ReplyDeleted"))
54 verify(core).deleteReply(localPostReply)