Spotless fixes.

This commit is contained in:
Vitor Pamplona
2024-01-06 10:44:32 -05:00
parent de61f7f383
commit ec867ae8a2
418 changed files with 74380 additions and 61924 deletions
@@ -1,3 +1,23 @@
/**
* Copyright (c) 2023 Vitor Pamplona
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.vitorpamplona.amethyst
import com.vitorpamplona.amethyst.service.firstFullChar
@@ -5,63 +25,79 @@ import org.junit.Assert
import org.junit.Test
class CharsetTest {
@Test
fun testASCIIChar() {
Assert.assertEquals("H", "Hi".firstFullChar())
}
@Test
fun testASCIIChar() {
Assert.assertEquals("H", "Hi".firstFullChar())
}
@Test
fun testUTF16JoinChar() {
Assert.assertEquals("\uD83C\uDF48", "\uD83C\uDF48Hi".firstFullChar())
}
@Test
fun testUTF16JoinChar() {
Assert.assertEquals("\uD83C\uDF48", "\uD83C\uDF48Hi".firstFullChar())
}
@Test
fun testUTF32JoinChar() {
Assert.assertEquals("\uD83E\uDDD1\uD83C\uDFFE", "\uD83E\uDDD1\uD83C\uDFFEHi".firstFullChar())
}
@Test
fun testUTF32JoinChar() {
Assert.assertEquals("\uD83E\uDDD1\uD83C\uDFFE", "\uD83E\uDDD1\uD83C\uDFFEHi".firstFullChar())
}
@Test
fun testUTF32JoinChar2() {
Assert.assertEquals("\uD83E\uDDD1\uD83C\uDFFE", "\uD83E\uDDD1\uD83C\uDFFEHi".firstFullChar())
}
@Test
fun testUTF32JoinChar2() {
Assert.assertEquals("\uD83E\uDDD1\uD83C\uDFFE", "\uD83E\uDDD1\uD83C\uDFFEHi".firstFullChar())
}
@Test
fun testAsciiWithUTF32Char() {
Assert.assertEquals("H", "Hi\uD83E\uDDD1\uD83C\uDFFEHi".firstFullChar())
}
@Test
fun testAsciiWithUTF32Char() {
Assert.assertEquals("H", "Hi\uD83E\uDDD1\uD83C\uDFFEHi".firstFullChar())
}
@Test
fun testBlank() {
Assert.assertEquals("", "".firstFullChar())
}
@Test
fun testBlank() {
Assert.assertEquals("", "".firstFullChar())
}
@Test
fun testSpecialChars() {
Assert.assertEquals("=", "=x".firstFullChar())
}
@Test
fun testSpecialChars() {
Assert.assertEquals("=", "=x".firstFullChar())
}
@Test
fun test5CharEmoji() {
Assert.assertEquals("\uD83D\uDC68\u200D\uD83D\uDCBB", "\uD83D\uDC68\u200D\uD83D\uDCBBadsfasdf".firstFullChar())
}
@Test
fun test5CharEmoji() {
Assert.assertEquals(
"\uD83D\uDC68\u200D\uD83D\uDCBB",
"\uD83D\uDC68\u200D\uD83D\uDCBBadsfasdf".firstFullChar(),
)
}
@Test
fun testFamily() {
Assert.assertEquals("\uD83D\uDC68\u200d\uD83D\uDC69\u200d\uD83D\uDC67\u200d\uD83D\uDC67", "\uD83D\uDC68\u200D\uD83D\uDC69\u200D\uD83D\uDC67\u200D\uD83D\uDC67adsfasdf".firstFullChar())
}
@Test
fun testFamily() {
Assert.assertEquals(
"\uD83D\uDC68\u200d\uD83D\uDC69\u200d\uD83D\uDC67\u200d\uD83D\uDC67",
"\uD83D\uDC68\u200D\uD83D\uDC69\u200D\uD83D\uDC67\u200D\uD83D\uDC67adsfasdf".firstFullChar(),
)
}
@Test
fun testTeacher() {
Assert.assertEquals("\uD83E\uDDD1\uD83C\uDFFF\u200D\uD83C\uDFEB", "\uD83E\uDDD1\uD83C\uDFFF\u200D\uD83C\uDFEBasdf".firstFullChar())
}
@Test
fun testTeacher() {
Assert.assertEquals(
"\uD83E\uDDD1\uD83C\uDFFF\u200D\uD83C\uDFEB",
"\uD83E\uDDD1\uD83C\uDFFF\u200D\uD83C\uDFEBasdf".firstFullChar(),
)
}
@Test
fun testVariation() {
Assert.assertEquals("\uD83D\uDC68\u200D\u2764\uFE0F\u200D\uD83D\uDC8B\u200D\uD83D\uDC68", "\uD83D\uDC68\u200D\u2764\uFE0F\u200D\uD83D\uDC8B\u200D\uD83D\uDC68ddd".firstFullChar())
}
@Test
fun testVariation() {
Assert.assertEquals(
"\uD83D\uDC68\u200D\u2764\uFE0F\u200D\uD83D\uDC8B\u200D\uD83D\uDC68",
"\uD83D\uDC68\u200D\u2764\uFE0F\u200D\uD83D\uDC8B\u200D\uD83D\uDC68ddd".firstFullChar(),
)
}
@Test
fun testMultipleEmoji() {
Assert.assertEquals("\uD83E\uDEC2\uD83E\uDEC2", "\uD83E\uDEC2\uD83E\uDEC2\uD83E\uDEC2\uD83E\uDEC2\uD83E\uDEC2\uD83E\uDEC2\uD83E\uDEC2\uD83E\uDEC2\uD83E\uDEC2\uD83E\uDEC2\uD83E\uDEC2\uD83E\uDEC2\uD83E\uDEC2\uD83E\uDEC2\uD83E\uDEC2\uD83E\uDEC2\uD83E\uDEC2\uD83E\uDEC2\uD83E\uDEC2\uD83E\uDEC2\uD83E\uDEC2\uD83E\uDEC2\uD83E\uDEC2\uD83E\uDEC2\uD83E\uDEC2\uD83E\uDEC2\uD83E\uDEC2\uD83E\uDEC2\uD83E\uDEC2\uD83E\uDEC2\uD83E\uDEC2\uD83E\uDEC2\uD83E\uDEC2\uD83E\uDEC2\uD83E\uDEC2\uD83E\uDEC2\uD83E\uDEC2\uD83E\uDEC2\uD83E\uDEC2\uD83E\uDEC2\uD83E\uDEC2".firstFullChar())
}
@Test
fun testMultipleEmoji() {
Assert.assertEquals(
"\uD83E\uDEC2\uD83E\uDEC2",
"\uD83E\uDEC2\uD83E\uDEC2\uD83E\uDEC2\uD83E\uDEC2\uD83E\uDEC2\uD83E\uDEC2\uD83E\uDEC2\uD83E\uDEC2\uD83E\uDEC2\uD83E\uDEC2\uD83E\uDEC2\uD83E\uDEC2\uD83E\uDEC2\uD83E\uDEC2\uD83E\uDEC2\uD83E\uDEC2\uD83E\uDEC2\uD83E\uDEC2\uD83E\uDEC2\uD83E\uDEC2\uD83E\uDEC2\uD83E\uDEC2\uD83E\uDEC2\uD83E\uDEC2\uD83E\uDEC2\uD83E\uDEC2\uD83E\uDEC2\uD83E\uDEC2\uD83E\uDEC2\uD83E\uDEC2\uD83E\uDEC2\uD83E\uDEC2\uD83E\uDEC2\uD83E\uDEC2\uD83E\uDEC2\uD83E\uDEC2\uD83E\uDEC2\uD83E\uDEC2\uD83E\uDEC2\uD83E\uDEC2\uD83E\uDEC2"
.firstFullChar(),
)
}
}
@@ -1,3 +1,23 @@
/**
* Copyright (c) 2023 Vitor Pamplona
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.vitorpamplona.amethyst
import com.vitorpamplona.amethyst.model.Note
@@ -14,97 +34,156 @@ import org.junit.Test
* See [testing documentation](http://d.android.com/tools/testing).
*/
class NewMessageTaggerKeyParseTest {
val dao: Dao = object : Dao {
override suspend fun getOrCreateUser(hex: String): User {
return User(hex)
}
val dao: Dao =
object : Dao {
override suspend fun getOrCreateUser(hex: String): User {
return User(hex)
}
override suspend fun getOrCreateNote(hex: String): Note {
return Note(hex)
}
override suspend fun getOrCreateNote(hex: String): Note {
return Note(hex)
}
override suspend fun checkGetOrCreateAddressableNote(hex: String): Note? {
return Note(hex)
}
override suspend fun checkGetOrCreateAddressableNote(hex: String): Note? {
return Note(hex)
}
}
@Test
fun keyParseTestNote() {
val result = NewMessageTagger(message = "", dao = dao).parseDirtyWordForKey("note1z5e2m0smx6d7e2d0zaq8d3rnd7httm6j0uf8tf90yqqjrs842czshwtkmn")
assertEquals(Nip19.Type.NOTE, result?.key?.type)
assertEquals("1532adbe1b369beca9af174076c4736faeb5ef527f1275a4af200121c0f55605", result?.key?.hex)
assertEquals("", result?.restOfWord)
}
@Test
fun keyParseTestNote() {
val result =
NewMessageTagger(message = "", dao = dao)
.parseDirtyWordForKey("note1z5e2m0smx6d7e2d0zaq8d3rnd7httm6j0uf8tf90yqqjrs842czshwtkmn")
assertEquals(Nip19.Type.NOTE, result?.key?.type)
assertEquals(
"1532adbe1b369beca9af174076c4736faeb5ef527f1275a4af200121c0f55605",
result?.key?.hex,
)
assertEquals("", result?.restOfWord)
}
@Test
fun keyParseTestPub() {
val result = NewMessageTagger(message = "", dao = dao).parseDirtyWordForKey("npub1gcxzte5zlkncx26j68ez60fzkvtkm9e0vrwdcvsjakxf9mu9qewqlfnj5z")
assertEquals(Nip19.Type.USER, result?.key?.type)
assertEquals("460c25e682fda7832b52d1f22d3d22b3176d972f60dcdc3212ed8c92ef85065c", result?.key?.hex)
assertEquals("", result?.restOfWord)
}
@Test
fun keyParseTestPub() {
val result =
NewMessageTagger(message = "", dao = dao)
.parseDirtyWordForKey("npub1gcxzte5zlkncx26j68ez60fzkvtkm9e0vrwdcvsjakxf9mu9qewqlfnj5z")
assertEquals(Nip19.Type.USER, result?.key?.type)
assertEquals(
"460c25e682fda7832b52d1f22d3d22b3176d972f60dcdc3212ed8c92ef85065c",
result?.key?.hex,
)
assertEquals("", result?.restOfWord)
}
@Test
fun keyParseTestNoteWithExtraChars() {
val result = NewMessageTagger(message = "", dao = dao).parseDirtyWordForKey("note1z5e2m0smx6d7e2d0zaq8d3rnd7httm6j0uf8tf90yqqjrs842czshwtkmn,")
assertEquals(Nip19.Type.NOTE, result?.key?.type)
assertEquals("1532adbe1b369beca9af174076c4736faeb5ef527f1275a4af200121c0f55605", result?.key?.hex)
assertEquals(",", result?.restOfWord)
}
@Test
fun keyParseTestNoteWithExtraChars() {
val result =
NewMessageTagger(message = "", dao = dao)
.parseDirtyWordForKey("note1z5e2m0smx6d7e2d0zaq8d3rnd7httm6j0uf8tf90yqqjrs842czshwtkmn,")
assertEquals(Nip19.Type.NOTE, result?.key?.type)
assertEquals(
"1532adbe1b369beca9af174076c4736faeb5ef527f1275a4af200121c0f55605",
result?.key?.hex,
)
assertEquals(",", result?.restOfWord)
}
@Test
fun keyParseTestPubWithExtraChars() {
val result = NewMessageTagger(message = "", dao = dao).parseDirtyWordForKey("npub1gcxzte5zlkncx26j68ez60fzkvtkm9e0vrwdcvsjakxf9mu9qewqlfnj5z,")
assertEquals(Nip19.Type.USER, result?.key?.type)
assertEquals("460c25e682fda7832b52d1f22d3d22b3176d972f60dcdc3212ed8c92ef85065c", result?.key?.hex)
assertEquals(",", result?.restOfWord)
}
@Test
fun keyParseTestPubWithExtraChars() {
val result =
NewMessageTagger(message = "", dao = dao)
.parseDirtyWordForKey("npub1gcxzte5zlkncx26j68ez60fzkvtkm9e0vrwdcvsjakxf9mu9qewqlfnj5z,")
assertEquals(Nip19.Type.USER, result?.key?.type)
assertEquals(
"460c25e682fda7832b52d1f22d3d22b3176d972f60dcdc3212ed8c92ef85065c",
result?.key?.hex,
)
assertEquals(",", result?.restOfWord)
}
@Test
fun keyParseTestNoteWithExtraCharsAndAt() {
val result = NewMessageTagger(message = "", dao = dao).parseDirtyWordForKey("@note1z5e2m0smx6d7e2d0zaq8d3rnd7httm6j0uf8tf90yqqjrs842czshwtkmn,")
assertEquals(Nip19.Type.NOTE, result?.key?.type)
assertEquals("1532adbe1b369beca9af174076c4736faeb5ef527f1275a4af200121c0f55605", result?.key?.hex)
assertEquals(",", result?.restOfWord)
}
@Test
fun keyParseTestNoteWithExtraCharsAndAt() {
val result =
NewMessageTagger(message = "", dao = dao)
.parseDirtyWordForKey("@note1z5e2m0smx6d7e2d0zaq8d3rnd7httm6j0uf8tf90yqqjrs842czshwtkmn,")
assertEquals(Nip19.Type.NOTE, result?.key?.type)
assertEquals(
"1532adbe1b369beca9af174076c4736faeb5ef527f1275a4af200121c0f55605",
result?.key?.hex,
)
assertEquals(",", result?.restOfWord)
}
@Test
fun keyParseTestPubWithExtraCharsAndAt() {
val result = NewMessageTagger(message = "", dao = dao).parseDirtyWordForKey("@npub1gcxzte5zlkncx26j68ez60fzkvtkm9e0vrwdcvsjakxf9mu9qewqlfnj5z,")
assertEquals(Nip19.Type.USER, result?.key?.type)
assertEquals("460c25e682fda7832b52d1f22d3d22b3176d972f60dcdc3212ed8c92ef85065c", result?.key?.hex)
assertEquals(",", result?.restOfWord)
}
@Test
fun keyParseTestPubWithExtraCharsAndAt() {
val result =
NewMessageTagger(message = "", dao = dao)
.parseDirtyWordForKey("@npub1gcxzte5zlkncx26j68ez60fzkvtkm9e0vrwdcvsjakxf9mu9qewqlfnj5z,")
assertEquals(Nip19.Type.USER, result?.key?.type)
assertEquals(
"460c25e682fda7832b52d1f22d3d22b3176d972f60dcdc3212ed8c92ef85065c",
result?.key?.hex,
)
assertEquals(",", result?.restOfWord)
}
@Test
fun keyParseTestNoteWithExtraCharsAndNostrPrefix() {
val result = NewMessageTagger(message = "", dao = dao).parseDirtyWordForKey("nostr:note1z5e2m0smx6d7e2d0zaq8d3rnd7httm6j0uf8tf90yqqjrs842czshwtkmn,")
assertEquals(Nip19.Type.NOTE, result?.key?.type)
assertEquals("1532adbe1b369beca9af174076c4736faeb5ef527f1275a4af200121c0f55605", result?.key?.hex)
assertEquals(",", result?.restOfWord)
}
@Test
fun keyParseTestNoteWithExtraCharsAndNostrPrefix() {
val result =
NewMessageTagger(message = "", dao = dao)
.parseDirtyWordForKey(
"nostr:note1z5e2m0smx6d7e2d0zaq8d3rnd7httm6j0uf8tf90yqqjrs842czshwtkmn,",
)
assertEquals(Nip19.Type.NOTE, result?.key?.type)
assertEquals(
"1532adbe1b369beca9af174076c4736faeb5ef527f1275a4af200121c0f55605",
result?.key?.hex,
)
assertEquals(",", result?.restOfWord)
}
@Test
fun keyParseTestPubWithExtraCharsAndNostrPrefix() {
val result = NewMessageTagger(message = "", dao = dao).parseDirtyWordForKey("nostr:npub1gcxzte5zlkncx26j68ez60fzkvtkm9e0vrwdcvsjakxf9mu9qewqlfnj5z,")
assertEquals(Nip19.Type.USER, result?.key?.type)
assertEquals("460c25e682fda7832b52d1f22d3d22b3176d972f60dcdc3212ed8c92ef85065c", result?.key?.hex)
assertEquals(",", result?.restOfWord)
}
@Test
fun keyParseTestPubWithExtraCharsAndNostrPrefix() {
val result =
NewMessageTagger(message = "", dao = dao)
.parseDirtyWordForKey(
"nostr:npub1gcxzte5zlkncx26j68ez60fzkvtkm9e0vrwdcvsjakxf9mu9qewqlfnj5z,",
)
assertEquals(Nip19.Type.USER, result?.key?.type)
assertEquals(
"460c25e682fda7832b52d1f22d3d22b3176d972f60dcdc3212ed8c92ef85065c",
result?.key?.hex,
)
assertEquals(",", result?.restOfWord)
}
@Test
fun keyParseTestUppercaseNoteWithExtraCharsAndNostrPrefix() {
val result = NewMessageTagger(message = "", dao = dao).parseDirtyWordForKey("Nostr:note1z5e2m0smx6d7e2d0zaq8d3rnd7httm6j0uf8tf90yqqjrs842czshwtkmn,")
assertEquals(Nip19.Type.NOTE, result?.key?.type)
assertEquals("1532adbe1b369beca9af174076c4736faeb5ef527f1275a4af200121c0f55605", result?.key?.hex)
assertEquals(",", result?.restOfWord)
}
@Test
fun keyParseTestUppercaseNoteWithExtraCharsAndNostrPrefix() {
val result =
NewMessageTagger(message = "", dao = dao)
.parseDirtyWordForKey(
"Nostr:note1z5e2m0smx6d7e2d0zaq8d3rnd7httm6j0uf8tf90yqqjrs842czshwtkmn,",
)
assertEquals(Nip19.Type.NOTE, result?.key?.type)
assertEquals(
"1532adbe1b369beca9af174076c4736faeb5ef527f1275a4af200121c0f55605",
result?.key?.hex,
)
assertEquals(",", result?.restOfWord)
}
@Test
fun keyParseTestUppercasePubWithExtraCharsAndNostrPrefix() {
val result = NewMessageTagger(message = "", dao = dao).parseDirtyWordForKey("nOstr:npub1gcxzte5zlkncx26j68ez60fzkvtkm9e0vrwdcvsjakxf9mu9qewqlfnj5z,")
assertEquals(Nip19.Type.USER, result?.key?.type)
assertEquals("460c25e682fda7832b52d1f22d3d22b3176d972f60dcdc3212ed8c92ef85065c", result?.key?.hex)
assertEquals(",", result?.restOfWord)
}
@Test
fun keyParseTestUppercasePubWithExtraCharsAndNostrPrefix() {
val result =
NewMessageTagger(message = "", dao = dao)
.parseDirtyWordForKey(
"nOstr:npub1gcxzte5zlkncx26j68ez60fzkvtkm9e0vrwdcvsjakxf9mu9qewqlfnj5z,",
)
assertEquals(Nip19.Type.USER, result?.key?.type)
assertEquals(
"460c25e682fda7832b52d1f22d3d22b3176d972f60dcdc3212ed8c92ef85065c",
result?.key?.hex,
)
assertEquals(",", result?.restOfWord)
}
}
@@ -1,3 +1,23 @@
/**
* Copyright (c) 2023 Vitor Pamplona
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.vitorpamplona.amethyst
import android.os.Looper
@@ -17,97 +37,96 @@ import org.junit.Before
import org.junit.Test
class SplitterTest {
@SpyK
var mySplit = Split<String>()
@SpyK var mySplit = Split<String>()
@Before
fun setUp() {
mockkStatic(Looper::class)
every { Looper.myLooper() } returns mockk<Looper>()
every { Looper.getMainLooper() } returns mockk<Looper>()
MockKAnnotations.init(this)
}
@Before
fun setUp() {
mockkStatic(Looper::class)
every { Looper.myLooper() } returns mockk<Looper>()
every { Looper.getMainLooper() } returns mockk<Looper>()
MockKAnnotations.init(this)
}
@After
fun tearDown() {
unmockkAll()
}
@After
fun tearDown() {
unmockkAll()
}
@Test
fun testSplit() = runBlocking {
val vitor = mySplit.addItem("Vitor")
@Test
fun testSplit() = runBlocking {
val vitor = mySplit.addItem("Vitor")
assertEquals(1f, mySplit.items[vitor].percentage, 0.01f)
assertTrue(mySplit.isEqualSplit())
assertEquals(1f, mySplit.items[vitor].percentage, 0.01f)
assertTrue(mySplit.isEqualSplit())
val pablo = mySplit.addItem("Pablo")
val pablo = mySplit.addItem("Pablo")
assertEquals(0.5f, mySplit.items[pablo].percentage, 0.01f)
assertEquals(0.5f, mySplit.items[vitor].percentage, 0.01f)
assertTrue(mySplit.isEqualSplit())
assertEquals(0.5f, mySplit.items[pablo].percentage, 0.01f)
assertEquals(0.5f, mySplit.items[vitor].percentage, 0.01f)
assertTrue(mySplit.isEqualSplit())
val gigi = mySplit.addItem("Gigi")
val gigi = mySplit.addItem("Gigi")
assertEquals(0.33f, mySplit.items[vitor].percentage, 0.01f)
assertEquals(0.33f, mySplit.items[pablo].percentage, 0.01f)
assertEquals(0.33f, mySplit.items[gigi].percentage, 0.01f)
assertTrue(mySplit.isEqualSplit())
assertEquals(0.33f, mySplit.items[vitor].percentage, 0.01f)
assertEquals(0.33f, mySplit.items[pablo].percentage, 0.01f)
assertEquals(0.33f, mySplit.items[gigi].percentage, 0.01f)
assertTrue(mySplit.isEqualSplit())
mySplit.updatePercentage(vitor, 0.5f)
mySplit.updatePercentage(vitor, 0.5f)
assertEquals(0.5f, mySplit.items[vitor].percentage, 0.01f)
assertEquals(0.33f, mySplit.items[pablo].percentage, 0.01f)
assertEquals(0.16f, mySplit.items[gigi].percentage, 0.01f)
assertFalse(mySplit.isEqualSplit())
assertEquals(0.5f, mySplit.items[vitor].percentage, 0.01f)
assertEquals(0.33f, mySplit.items[pablo].percentage, 0.01f)
assertEquals(0.16f, mySplit.items[gigi].percentage, 0.01f)
assertFalse(mySplit.isEqualSplit())
mySplit.updatePercentage(vitor, 0.95f)
mySplit.updatePercentage(vitor, 0.95f)
assertEquals(0.95f, mySplit.items[vitor].percentage, 0.01f)
assertEquals(0.05f, mySplit.items[pablo].percentage, 0.01f)
assertEquals(0.0f, mySplit.items[gigi].percentage, 0.01f)
assertFalse(mySplit.isEqualSplit())
assertEquals(0.95f, mySplit.items[vitor].percentage, 0.01f)
assertEquals(0.05f, mySplit.items[pablo].percentage, 0.01f)
assertEquals(0.0f, mySplit.items[gigi].percentage, 0.01f)
assertFalse(mySplit.isEqualSplit())
mySplit.updatePercentage(vitor, 0.15f)
mySplit.updatePercentage(vitor, 0.15f)
assertEquals(0.15f, mySplit.items[vitor].percentage, 0.01f)
assertEquals(0.05f, mySplit.items[pablo].percentage, 0.01f)
assertEquals(0.80f, mySplit.items[gigi].percentage, 0.01f)
assertFalse(mySplit.isEqualSplit())
assertEquals(0.15f, mySplit.items[vitor].percentage, 0.01f)
assertEquals(0.05f, mySplit.items[pablo].percentage, 0.01f)
assertEquals(0.80f, mySplit.items[gigi].percentage, 0.01f)
assertFalse(mySplit.isEqualSplit())
mySplit.updatePercentage(pablo, 0.95f)
mySplit.updatePercentage(pablo, 0.95f)
assertEquals(0.05f, mySplit.items[vitor].percentage, 0.01f)
assertEquals(0.95f, mySplit.items[pablo].percentage, 0.01f)
assertEquals(0.00f, mySplit.items[gigi].percentage, 0.01f)
assertEquals(0.05f, mySplit.items[vitor].percentage, 0.01f)
assertEquals(0.95f, mySplit.items[pablo].percentage, 0.01f)
assertEquals(0.00f, mySplit.items[gigi].percentage, 0.01f)
mySplit.updatePercentage(gigi, 1f)
mySplit.updatePercentage(gigi, 1f)
assertEquals(0.00f, mySplit.items[vitor].percentage, 0.01f)
assertEquals(0.00f, mySplit.items[pablo].percentage, 0.01f)
assertEquals(1.00f, mySplit.items[gigi].percentage, 0.01f)
assertEquals(0.00f, mySplit.items[vitor].percentage, 0.01f)
assertEquals(0.00f, mySplit.items[pablo].percentage, 0.01f)
assertEquals(1.00f, mySplit.items[gigi].percentage, 0.01f)
mySplit.updatePercentage(vitor, 0.5f)
mySplit.updatePercentage(vitor, 0.5f)
assertEquals(0.50f, mySplit.items[vitor].percentage, 0.01f)
assertEquals(0.00f, mySplit.items[pablo].percentage, 0.01f)
assertEquals(0.50f, mySplit.items[gigi].percentage, 0.01f)
assertEquals(0.50f, mySplit.items[vitor].percentage, 0.01f)
assertEquals(0.00f, mySplit.items[pablo].percentage, 0.01f)
assertEquals(0.50f, mySplit.items[gigi].percentage, 0.01f)
mySplit.updatePercentage(pablo, 0.3f)
mySplit.updatePercentage(pablo, 0.3f)
assertEquals(0.50f, mySplit.items[vitor].percentage, 0.01f)
assertEquals(0.30f, mySplit.items[pablo].percentage, 0.01f)
assertEquals(0.20f, mySplit.items[gigi].percentage, 0.01f)
assertEquals(0.50f, mySplit.items[vitor].percentage, 0.01f)
assertEquals(0.30f, mySplit.items[pablo].percentage, 0.01f)
assertEquals(0.20f, mySplit.items[gigi].percentage, 0.01f)
mySplit.updatePercentage(gigi, 1f)
mySplit.updatePercentage(gigi, 1f)
assertEquals(0.00f, mySplit.items[vitor].percentage, 0.01f)
assertEquals(0.00f, mySplit.items[pablo].percentage, 0.01f)
assertEquals(1.00f, mySplit.items[gigi].percentage, 0.01f)
assertEquals(0.00f, mySplit.items[vitor].percentage, 0.01f)
assertEquals(0.00f, mySplit.items[pablo].percentage, 0.01f)
assertEquals(1.00f, mySplit.items[gigi].percentage, 0.01f)
mySplit.updatePercentage(gigi, 0.5f)
mySplit.updatePercentage(gigi, 0.5f)
assertEquals(0.00f, mySplit.items[vitor].percentage, 0.01f)
assertEquals(0.50f, mySplit.items[pablo].percentage, 0.01f)
assertEquals(0.50f, mySplit.items[gigi].percentage, 0.01f)
}
assertEquals(0.00f, mySplit.items[vitor].percentage, 0.01f)
assertEquals(0.50f, mySplit.items[pablo].percentage, 0.01f)
assertEquals(0.50f, mySplit.items[gigi].percentage, 0.01f)
}
}
@@ -1,3 +1,23 @@
/**
* Copyright (c) 2023 Vitor Pamplona
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.vitorpamplona.amethyst.service
import android.os.Looper
@@ -17,115 +37,108 @@ import org.junit.Before
import org.junit.Test
class Nip05NostrAddressVerifierTest {
companion object {
private val ALL_UPPER_CASE_USER_NAME = "ONETWO"
private val ALL_LOWER_CASE_USER_NAME = "onetwo"
}
@SpyK
var nip05Verifier = Nip05NostrAddressVerifier()
@SpyK var nip05Verifier = Nip05NostrAddressVerifier()
@Before
fun setUp() {
mockkStatic(Looper::class)
every { Looper.myLooper() } returns mockk<Looper>()
every { Looper.getMainLooper() } returns mockk<Looper>()
MockKAnnotations.init(this)
}
@Before
fun setUp() {
mockkStatic(Looper::class)
every { Looper.myLooper() } returns mockk<Looper>()
every { Looper.getMainLooper() } returns mockk<Looper>()
MockKAnnotations.init(this)
}
@Test
fun `test with matching case on user name`() = runBlocking {
// Set-up
val userNameToTest = ALL_UPPER_CASE_USER_NAME
val expectedPubKey = "ca29c211f1c72d5b6622268ff43d2288ea2b2cb5b9aa196ff9f1704fc914b71b"
@Test
fun `test with matching case on user name`() = runBlocking {
// Set-up
val userNameToTest = ALL_UPPER_CASE_USER_NAME
val expectedPubKey = "ca29c211f1c72d5b6622268ff43d2288ea2b2cb5b9aa196ff9f1704fc914b71b"
val nostrJson = "{\n" +
" \"names\": {\n" +
" \"$userNameToTest\": \"$expectedPubKey\" \n" +
" }\n" +
"}"
val nostrJson =
"{\n" + " \"names\": {\n" + " \"$userNameToTest\": \"$expectedPubKey\" \n" + " }\n" + "}"
coEvery { nip05Verifier.fetchNip05Json(any(), any(), any()) } answers {
secondArg<(String) -> Unit>().invoke(nostrJson)
}
coEvery { nip05Verifier.fetchNip05Json(any(), any(), any()) } answers
{
secondArg<(String) -> Unit>().invoke(nostrJson)
}
val nip05 = "$userNameToTest@domain.com"
var actualPubkeyHex = ""
val nip05 = "$userNameToTest@domain.com"
var actualPubkeyHex = ""
// Execution
nip05Verifier.verifyNip05(
nip05,
onSuccess = {
actualPubkeyHex = it
},
onError = {
fail("Test failure")
}
)
// Execution
nip05Verifier.verifyNip05(
nip05,
onSuccess = { actualPubkeyHex = it },
onError = { fail("Test failure") },
)
// Verification
assertEquals(expectedPubKey, actualPubkeyHex)
}
// Verification
assertEquals(expectedPubKey, actualPubkeyHex)
}
@Test
fun `test with NOT matching case on user name`() = runBlocking {
// Set-up
val expectedPubKey = "ca29c211f1c72d5b6622268ff43d2288ea2b2cb5b9aa196ff9f1704fc914b71b"
@Test
fun `test with NOT matching case on user name`() = runBlocking {
// Set-up
val expectedPubKey = "ca29c211f1c72d5b6622268ff43d2288ea2b2cb5b9aa196ff9f1704fc914b71b"
val nostrJson = "{\n" +
" \"names\": {\n" +
" \"$ALL_UPPER_CASE_USER_NAME\": \"$expectedPubKey\" \n" +
" }\n" +
"}"
coEvery { nip05Verifier.fetchNip05Json(any(), any(), any()) } answers {
secondArg<(String) -> Unit>().invoke(nostrJson)
}
val nostrJson =
"{\n" +
" \"names\": {\n" +
" \"$ALL_UPPER_CASE_USER_NAME\": \"$expectedPubKey\" \n" +
" }\n" +
"}"
coEvery { nip05Verifier.fetchNip05Json(any(), any(), any()) } answers
{
secondArg<(String) -> Unit>().invoke(nostrJson)
}
val nip05 = "$ALL_LOWER_CASE_USER_NAME@domain.com"
var actualPubkeyHex = ""
val nip05 = "$ALL_LOWER_CASE_USER_NAME@domain.com"
var actualPubkeyHex = ""
// Execution
nip05Verifier.verifyNip05(
nip05,
onSuccess = {
actualPubkeyHex = it
},
onError = {
fail("Test failure")
}
)
// Execution
nip05Verifier.verifyNip05(
nip05,
onSuccess = { actualPubkeyHex = it },
onError = { fail("Test failure") },
)
// Verification
assertEquals(expectedPubKey, actualPubkeyHex)
}
// Verification
assertEquals(expectedPubKey, actualPubkeyHex)
}
@After
fun tearDown() {
unmockkAll()
}
@After
fun tearDown() {
unmockkAll()
}
@Test
fun `execute assemble url with invalid value returns null`() {
// given
val nip05address = "this@that@that.com"
@Test
fun `execute assemble url with invalid value returns null`() {
// given
val nip05address = "this@that@that.com"
// when
val actualValue = nip05Verifier.assembleUrl(nip05address)
// when
val actualValue = nip05Verifier.assembleUrl(nip05address)
// then
assertNull(actualValue)
}
// then
assertNull(actualValue)
}
@Test
fun `execute assemble url with valid value returns nip05 url`() {
// given
val userName = "TheUser"
val domain = "domain.com"
val nip05address = "$userName@$domain"
val expectedValue = "https://$domain/.well-known/nostr.json?name=$userName"
@Test
fun `execute assemble url with valid value returns nip05 url`() {
// given
val userName = "TheUser"
val domain = "domain.com"
val nip05address = "$userName@$domain"
val expectedValue = "https://$domain/.well-known/nostr.json?name=$userName"
// when
val actualValue = nip05Verifier.assembleUrl(nip05address)
// when
val actualValue = nip05Verifier.assembleUrl(nip05address)
// then
assertEquals(expectedValue, actualValue)
}
// then
assertEquals(expectedValue, actualValue)
}
}
@@ -1,58 +1,78 @@
/**
* Copyright (c) 2023 Vitor Pamplona
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.vitorpamplona.amethyst.service
import junit.framework.TestCase.assertEquals
import org.junit.Test
class Nip30Test {
@Test()
fun parseEmoji() {
val input = "Alex Gleason :soapbox:"
@Test()
fun parseEmoji() {
val input = "Alex Gleason :soapbox:"
assertEquals(
listOf("Alex Gleason ", ":soapbox:", ""),
Nip30CustomEmoji().buildArray(input)
)
}
assertEquals(
listOf("Alex Gleason ", ":soapbox:", ""),
Nip30CustomEmoji().buildArray(input),
)
}
@Test()
fun parseEmojiInverted() {
val input = ":soapbox:Alex Gleason"
@Test()
fun parseEmojiInverted() {
val input = ":soapbox:Alex Gleason"
assertEquals(
listOf("", ":soapbox:", "Alex Gleason"),
Nip30CustomEmoji().buildArray(input)
)
}
assertEquals(
listOf("", ":soapbox:", "Alex Gleason"),
Nip30CustomEmoji().buildArray(input),
)
}
@Test()
fun parseEmoji2() {
val input = "Hello :gleasonator: \uD83D\uDE02 :ablobcatrainbow: :disputed: yolo"
@Test()
fun parseEmoji2() {
val input = "Hello :gleasonator: \uD83D\uDE02 :ablobcatrainbow: :disputed: yolo"
assertEquals(
listOf("Hello ", ":gleasonator:", " 😂 ", ":ablobcatrainbow:", " ", ":disputed:", " yolo"),
Nip30CustomEmoji().buildArray(input)
)
assertEquals(
listOf("Hello ", ":gleasonator:", " 😂 ", ":ablobcatrainbow:", " ", ":disputed:", " yolo"),
Nip30CustomEmoji().buildArray(input),
)
println(Nip30CustomEmoji().buildArray(input).joinToString(","))
}
println(Nip30CustomEmoji().buildArray(input).joinToString(","))
}
@Test()
fun parseEmoji3() {
val input = "hello vitor: how can I help:"
@Test()
fun parseEmoji3() {
val input = "hello vitor: how can I help:"
assertEquals(
listOf("hello vitor: how can I help:"),
Nip30CustomEmoji().buildArray(input)
)
}
assertEquals(
listOf("hello vitor: how can I help:"),
Nip30CustomEmoji().buildArray(input),
)
}
@Test()
fun parseJapanese() {
val input = "\uD883\uDEDE\uD883\uDEDE麺の:x30EDE:。:\uD883\uDEDE:(Violation of NIP-30)"
@Test()
fun parseJapanese() {
val input = "\uD883\uDEDE\uD883\uDEDE麺の:x30EDE:。:\uD883\uDEDE:(Violation of NIP-30)"
assertEquals(
listOf("\uD883\uDEDE\uD883\uDEDE麺の", ":x30EDE:", "。:\uD883\uDEDE:(Violation of NIP-30)"),
Nip30CustomEmoji().buildArray(input)
)
}
assertEquals(
listOf("\uD883\uDEDE\uD883\uDEDE麺の", ":x30EDE:", "。:\uD883\uDEDE:(Violation of NIP-30)"),
Nip30CustomEmoji().buildArray(input),
)
}
}
@@ -1,11 +1,31 @@
/**
* Copyright (c) 2023 Vitor Pamplona
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.vitorpamplona.amethyst.service
import junit.framework.TestCase.assertEquals
import org.junit.Test
class Nip96Test {
val json = """
val json =
"""
{
"api_url": "https://nostr.build/api/v2/nip96/upload",
"download_url": "https://media.nostr.build",
@@ -92,28 +112,29 @@ class Nip96Test {
}
}
}
""".trimIndent()
"""
.trimIndent()
@Test()
fun parseNostrBuild() {
val info = Nip96Retriever().parse(json)
@Test()
fun parseNostrBuild() {
val info = Nip96Retriever().parse(json)
assertEquals("https://nostr.build/api/v2/nip96/upload", info.apiUrl)
assertEquals("https://media.nostr.build", info.downloadUrl)
assertEquals(listOf(94, 96, 98), info.supportedNips)
assertEquals("https://nostr.build/tos/", info.tosUrl)
assertEquals(listOf("image/*", "video/*", "audio/*"), info.contentTypes)
assertEquals("https://nostr.build/api/v2/nip96/upload", info.apiUrl)
assertEquals("https://media.nostr.build", info.downloadUrl)
assertEquals(listOf(94, 96, 98), info.supportedNips)
assertEquals("https://nostr.build/tos/", info.tosUrl)
assertEquals(listOf("image/*", "video/*", "audio/*"), info.contentTypes)
assertEquals(listOf("creator", "free", "professional"), info.plans.keys.sorted())
assertEquals(listOf("creator", "free", "professional"), info.plans.keys.sorted())
assertEquals("Free", info.plans["free"]?.name)
assertEquals(true, info.plans["free"]?.isNip98Required)
assertEquals("https://nostr.build", info.plans["free"]?.url)
assertEquals(26214400L, info.plans["free"]?.maxByteSize)
assertEquals(listOf(0, 0), info.plans["free"]?.fileExpiration)
assertEquals(listOf("image", "video"), info.plans["free"]?.mediaTransformations?.keys?.sorted())
assertEquals("Free", info.plans["free"]?.name)
assertEquals(true, info.plans["free"]?.isNip98Required)
assertEquals("https://nostr.build", info.plans["free"]?.url)
assertEquals(26214400L, info.plans["free"]?.maxByteSize)
assertEquals(listOf(0, 0), info.plans["free"]?.fileExpiration)
assertEquals(listOf("image", "video"), info.plans["free"]?.mediaTransformations?.keys?.sorted())
assertEquals(26843545600L, info.plans["creator"]?.maxByteSize)
assertEquals(10737418240L, info.plans["professional"]?.maxByteSize)
}
assertEquals(26843545600L, info.plans["creator"]?.maxByteSize)
assertEquals(10737418240L, info.plans["professional"]?.maxByteSize)
}
}
@@ -1,3 +1,23 @@
/**
* Copyright (c) 2023 Vitor Pamplona
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.vitorpamplona.amethyst.service.zaps
import com.vitorpamplona.amethyst.model.Note
@@ -6,50 +26,54 @@ import com.vitorpamplona.quartz.events.LnZapEventInterface
import com.vitorpamplona.quartz.events.zaps.UserZaps
import io.mockk.every
import io.mockk.mockk
import java.math.BigDecimal
import org.junit.Assert
import org.junit.Test
import java.math.BigDecimal
class UserZapsTest {
@Test
fun nothing() {
Assert.assertEquals(1, 1)
}
@Test
fun nothing() {
Assert.assertEquals(1, 1)
}
@Test
fun user_without_zaps() {
val actual = UserZaps.forProfileFeed(zaps = null)
@Test
fun user_without_zaps() {
val actual = UserZaps.forProfileFeed(zaps = null)
Assert.assertEquals(emptyList<Pair<Note, Note>>(), actual)
}
Assert.assertEquals(emptyList<Pair<Note, Note>>(), actual)
}
@Test
fun avoid_duplicates_with_same_zap_request() {
val zapRequest = mockk<Note>()
@Test
fun avoid_duplicates_with_same_zap_request() {
val zapRequest = mockk<Note>()
val zaps: Map<Note, Note?> = mapOf(
zapRequest to mockZapNoteWith("user-1", amount = 100),
zapRequest to mockZapNoteWith("user-1", amount = 200)
)
val zaps: Map<Note, Note?> =
mapOf(
zapRequest to mockZapNoteWith("user-1", amount = 100),
zapRequest to mockZapNoteWith("user-1", amount = 200),
)
val actual = UserZaps.forProfileFeed(zaps)
val actual = UserZaps.forProfileFeed(zaps)
Assert.assertEquals(1, actual.count())
Assert.assertEquals(zapRequest, actual.first().zapRequest)
Assert.assertEquals(
BigDecimal(200),
(actual.first().zapEvent.event as LnZapEventInterface).amount()
)
}
Assert.assertEquals(1, actual.count())
Assert.assertEquals(zapRequest, actual.first().zapRequest)
Assert.assertEquals(
BigDecimal(200),
(actual.first().zapEvent.event as LnZapEventInterface).amount(),
)
}
private fun mockZapNoteWith(pubkey: HexKey, amount: Int): Note {
val lnZapEvent = mockk<LnZapEventInterface>()
every { lnZapEvent.amount() } returns amount.toBigDecimal()
every { lnZapEvent.pubKey() } returns pubkey
private fun mockZapNoteWith(
pubkey: HexKey,
amount: Int,
): Note {
val lnZapEvent = mockk<LnZapEventInterface>()
every { lnZapEvent.amount() } returns amount.toBigDecimal()
every { lnZapEvent.pubKey() } returns pubkey
val zapNote = mockk<Note>()
every { zapNote.event } returns lnZapEvent
val zapNote = mockk<Note>()
every { zapNote.event } returns lnZapEvent
return zapNote
}
return zapNote
}
}