🔀 Merge “release/v81” into “master”
[Sone.git] / src / test / kotlin / net / pterodactylus / sone / freenet / wot / PluginWebOfTrustConnectorTest.kt
index e5d7da2..a9c0412 100644 (file)
@@ -17,7 +17,6 @@ import kotlin.test.*
 class PluginWebOfTrustConnectorTest {
 
        private val ownIdentity = DefaultOwnIdentity("id", "nickname", "requestUri", "insertUri")
-       private val identity = DefaultIdentity("id-a", "alpha", "url://alpha")
 
        @Test
        fun `wot plugin can be pinged`() {
@@ -99,11 +98,25 @@ class PluginWebOfTrustConnectorTest {
                assertThat(trustedIdentities, contains(
                                allOf(
                                                isIdentity("id0", "nickname0", "request-uri0", empty<String>(), isEmptyMap()),
-                                               isTrusted(ownIdentity, isTrust(null, 0, 0))
+                                               isTrusted(ownIdentity, isTrust(null, null, null))
                                ),
                                allOf(
                                                isIdentity("id1", "nickname1", "request-uri1", empty<String>(), isEmptyMap()),
-                                               isTrusted(ownIdentity, isTrust(null, 0, 0))
+                                               isTrusted(ownIdentity, isTrust(null, null, null))
+                               )
+               ))
+       }
+
+       @Test
+       fun `trusted identity without nickname is returned correctly`() {
+               val trustedIdentities = createPluginConnector("GetIdentitiesByScore") {
+                       put("Identity0", "id0")
+                       put("RequestURI0", "request-uri0")
+               }.connect { loadTrustedIdentities(ownIdentity) }
+               assertThat(trustedIdentities, contains(
+                               allOf(
+                                               isIdentity("id0", null, "request-uri0", empty<String>(), isEmptyMap()),
+                                               isTrusted(ownIdentity, isTrust(null, null, null))
                                )
                ))
        }
@@ -210,94 +223,6 @@ class PluginWebOfTrustConnectorTest {
                                .connect { removeProperty(ownIdentity, "TestProperty") }
        }
 
-       @Test
-       fun `getting trust sends correct own identity id`() {
-               createPluginConnector("GetIdentity", hasField("Truster", equalTo(ownIdentity.id)))
-                               .connect { getTrust(ownIdentity, identity) }
-       }
-
-       @Test
-       fun `getting trust sends correct identity id`() {
-               createPluginConnector("GetIdentity", hasField("Identity", equalTo(identity.id)))
-                               .connect { getTrust(ownIdentity, identity) }
-       }
-
-       @Test
-       fun `getting trust returns correct trust values`() {
-               val trust = createPluginConnector("GetIdentity", hasField("Identity", equalTo(identity.id))) {
-                       put("Trust", "12")
-                       put("Score", "34")
-                       put("Rank", "56")
-               }.connect { getTrust(ownIdentity, identity) }
-               assertThat(trust, isTrust(12, 34, 56))
-       }
-
-       @Test
-       fun `getting trust reads incorrect numbers for trust as null`() {
-               val trust = createPluginConnector("GetIdentity", hasField("Identity", equalTo(identity.id))) {
-                       put("Trust", "incorrect")
-                       put("Score", "34")
-                       put("Rank", "56")
-               }.connect { getTrust(ownIdentity, identity) }
-               assertThat(trust, isTrust(null, 34, 56))
-       }
-
-       @Test
-       fun `getting trust reads incorrect numbers for score as null`() {
-               val trust = createPluginConnector("GetIdentity", hasField("Identity", equalTo(identity.id))) {
-                       put("Trust", "12")
-                       put("Score", "incorrect")
-                       put("Rank", "56")
-               }.connect { getTrust(ownIdentity, identity) }
-               assertThat(trust, isTrust(12, null, 56))
-       }
-
-       @Test
-       fun `getting trust reads incorrect numbers for rank as null`() {
-               val trust = createPluginConnector("GetIdentity", hasField("Identity", equalTo(identity.id))) {
-                       put("Trust", "12")
-                       put("Score", "34")
-                       put("Rank", "incorrect")
-               }.connect { getTrust(ownIdentity, identity) }
-               assertThat(trust, isTrust(12, 34, null))
-       }
-
-       @Test
-       fun `setting trust sends correct own identity id`() {
-               createPluginConnector("SetTrust", hasField("Truster", equalTo(ownIdentity.id)))
-                               .connect { setTrust(ownIdentity, identity, 123, "Test Trust") }
-       }
-
-       @Test
-       fun `setting trust sends correct identity id`() {
-               createPluginConnector("SetTrust", hasField("Trustee", equalTo(identity.id)))
-                               .connect { setTrust(ownIdentity, identity, 123, "Test Trust") }
-       }
-
-       @Test
-       fun `setting trust sends correct trust value`() {
-               createPluginConnector("SetTrust", hasField("Value", equalTo("123")))
-                               .connect { setTrust(ownIdentity, identity, 123, "Test Trust") }
-       }
-
-       @Test
-       fun `setting trust sends correct comment`() {
-               createPluginConnector("SetTrust", hasField("Comment", equalTo("Test Trust")))
-                               .connect { setTrust(ownIdentity, identity, 123, "Test Trust") }
-       }
-
-       @Test
-       fun `removing trust sends correct own identity id`() {
-               createPluginConnector("RemoveTrust", hasField("Truster", equalTo(ownIdentity.id)))
-                               .connect { removeTrust(ownIdentity, identity) }
-       }
-
-       @Test
-       fun `removing trust sends correct identity id`() {
-               createPluginConnector("RemoveTrust", hasField("Trustee", equalTo(identity.id)))
-                               .connect { removeTrust(ownIdentity, identity) }
-       }
-
 }
 
 private fun <R> PluginConnector.connect(block: PluginWebOfTrustConnector.() -> R) =
@@ -305,7 +230,7 @@ private fun <R> PluginConnector.connect(block: PluginWebOfTrustConnector.() -> R
 
 fun createPluginConnector(message: String, fieldsMatcher: Matcher<SimpleFieldSet> = IsAnything<SimpleFieldSet>(), build: SimpleFieldSetBuilder.() -> Unit = {}) =
                object : PluginConnector {
-                       override fun sendRequest(pluginName: String, identifier: String, fields: SimpleFieldSet, data: Bucket?) =
+                       override suspend fun sendRequest(pluginName: String, fields: SimpleFieldSet, data: Bucket?) =
                                        if ((pluginName != wotPluginName) || (fields.get("Message") != message)) {
                                                throw PluginException()
                                        } else {