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.Post
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 [DeletePostCommand].
16 class DeletePostCommandTest : SoneCommandTest() {
18 private val postFromRemoteSone = mock<Post>().apply { whenever(sone).thenReturn(remoteSone) }
19 private val postFromLocalSone = mock<Post>().apply { whenever(sone).thenReturn(localSone) }
20 override fun createCommand(core: Core) = DeletePostCommand(core)
23 fun `command requires write access`() {
24 assertThat(command.requiresWriteAccess(), equalTo(true))
28 fun `request without any parameter results in fcp exception`() {
29 requestWithoutAnyParameterResultsInFcpException()
33 fun `request with invalid post parameter results in fcp exception`() {
34 parameters += "Post" to "InvalidPostId"
35 executeCommandAndExpectFcpException()
39 fun `request with post from remote sone returns error response`() {
40 parameters += "Post" to "RemotePostId"
41 whenever(core.getPost("RemotePostId")).thenReturn(postFromRemoteSone)
42 val response = command.execute(parameters)
43 assertThat(response.replyParameters["Message"], equalTo("Error"))
44 assertThat(response.replyParameters["ErrorCode"], equalTo("401"))
48 fun `request with post from local sone deletes posts`() {
49 parameters += "Post" to "LocalPostId"
50 whenever(core.getPost("LocalPostId")).thenReturn(postFromLocalSone)
51 val response = command.execute(parameters)
52 assertThat(response.replyParameters["Message"], equalTo("PostDeleted"))
53 verify(core).deletePost(postFromLocalSone)