Remove @author tags
[Sone.git] / src / test / kotlin / net / pterodactylus / sone / fcp / DeletePostCommandTest.kt
1 package net.pterodactylus.sone.fcp
2
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
10 import org.junit.Test
11 import org.mockito.Mockito.verify
12
13 /**
14  * Unit test for [DeletePostCommand].
15  */
16 class DeletePostCommandTest : SoneCommandTest() {
17
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)
21
22         @Test
23         fun `command requires write access`() {
24                 assertThat(command.requiresWriteAccess(), equalTo(true))
25         }
26
27         @Test
28         fun `request without any parameter results in fcp exception`() {
29                 requestWithoutAnyParameterResultsInFcpException()
30         }
31
32         @Test
33         fun `request with invalid post parameter results in fcp exception`() {
34                 parameters += "Post" to "InvalidPostId"
35                 executeCommandAndExpectFcpException()
36         }
37
38         @Test
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"))
45         }
46
47         @Test
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)
54         }
55
56 }