mirror of https://github.com/usbharu/Hideout.git
wip
This commit is contained in:
parent
92e13e3782
commit
d5cb840270
|
@ -16,8 +16,10 @@
|
||||||
|
|
||||||
package dev.usbharu.hideout.core.domain.model.actor
|
package dev.usbharu.hideout.core.domain.model.actor
|
||||||
|
|
||||||
@JvmInline
|
|
||||||
value class ActorDescription(val description: String) {
|
class ActorDescription(description: String) {
|
||||||
|
val description: String = description.take(length)
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
val length = 10000
|
val length = 10000
|
||||||
val empty = ActorDescription("")
|
val empty = ActorDescription("")
|
||||||
|
|
|
@ -18,8 +18,14 @@ package dev.usbharu.hideout.core.domain.model.actor
|
||||||
|
|
||||||
@JvmInline
|
@JvmInline
|
||||||
value class ActorName(val name: String) {
|
value class ActorName(val name: String) {
|
||||||
|
init {
|
||||||
|
require(name.isNotBlank())
|
||||||
|
require(name.length <= length)
|
||||||
|
require(regex.matches(name))
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
val length = 300
|
val length = 300
|
||||||
|
private val regex = Regex("^[a-zA-Z0-9_-]{1,$length}\$")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,9 +22,6 @@ value class ActorPostsCount(val postsCount: Int) {
|
||||||
require(0 <= this.postsCount) { "Posts count must be greater than 0" }
|
require(0 <= this.postsCount) { "Posts count must be greater than 0" }
|
||||||
}
|
}
|
||||||
|
|
||||||
operator fun inc() = ActorPostsCount(postsCount + 1)
|
|
||||||
operator fun dec() = ActorPostsCount(postsCount - 1)
|
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
val ZERO = ActorPostsCount(0)
|
val ZERO = ActorPostsCount(0)
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,4 @@ value class ActorRelationshipCount(val relationshipCount: Int) {
|
||||||
init {
|
init {
|
||||||
require(0 <= relationshipCount) { "Followers count must be > 0" }
|
require(0 <= relationshipCount) { "Followers count must be > 0" }
|
||||||
}
|
}
|
||||||
|
|
||||||
operator fun inc(): ActorRelationshipCount = ActorRelationshipCount(relationshipCount + 1)
|
|
||||||
operator fun dec(): ActorRelationshipCount = ActorRelationshipCount(relationshipCount - 1)
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,8 +16,11 @@
|
||||||
|
|
||||||
package dev.usbharu.hideout.core.domain.model.actor
|
package dev.usbharu.hideout.core.domain.model.actor
|
||||||
|
|
||||||
@JvmInline
|
|
||||||
value class ActorScreenName(val screenName: String) {
|
class ActorScreenName(screenName: String) {
|
||||||
|
|
||||||
|
val screenName: String = screenName.take(length)
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
val length = 300
|
val length = 300
|
||||||
val empty = ActorScreenName("")
|
val empty = ActorScreenName("")
|
||||||
|
|
|
@ -18,6 +18,10 @@ package dev.usbharu.hideout.core.domain.model.shared
|
||||||
|
|
||||||
@JvmInline
|
@JvmInline
|
||||||
value class Domain(val domain: String) {
|
value class Domain(val domain: String) {
|
||||||
|
init {
|
||||||
|
require(domain.length <= length)
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
val length = 1000
|
val length = 1000
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,35 @@
|
||||||
|
package dev.usbharu.hideout.core.domain.model.actor
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test
|
||||||
|
import org.junit.jupiter.api.assertDoesNotThrow
|
||||||
|
import org.junit.jupiter.api.assertThrows
|
||||||
|
|
||||||
|
class ActorNameTest {
|
||||||
|
@Test
|
||||||
|
fun blankはダメ() {
|
||||||
|
assertThrows<IllegalArgumentException> {
|
||||||
|
ActorName("")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun 長過ぎるとダメ() {
|
||||||
|
assertThrows<IllegalArgumentException> {
|
||||||
|
ActorName("a".repeat(1000))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun 指定外の文字は使えない() {
|
||||||
|
assertThrows<IllegalArgumentException> {
|
||||||
|
ActorName("あ")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun 普通に作成できる() {
|
||||||
|
assertDoesNotThrow {
|
||||||
|
ActorName("test-user")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,13 @@
|
||||||
package dev.usbharu.hideout.core.domain.model.actor
|
package dev.usbharu.hideout.core.domain.model.actor
|
||||||
|
|
||||||
class ActorScreenNameTest {
|
import org.junit.jupiter.api.Test
|
||||||
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
|
class ActorScreenNameTest {
|
||||||
|
@Test
|
||||||
|
fun screenNameがlengthを超えると無視される() {
|
||||||
|
val actorScreenName = ActorScreenName("a".repeat(1000))
|
||||||
|
|
||||||
|
assertEquals(ActorScreenName.length, actorScreenName.screenName.length)
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -1,9 +1,53 @@
|
||||||
package dev.usbharu.hideout.core.domain.model.actor
|
package dev.usbharu.hideout.core.domain.model.actor
|
||||||
|
|
||||||
|
import dev.usbharu.hideout.core.domain.event.actor.ActorEvent
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import org.junit.jupiter.api.assertThrows
|
import org.junit.jupiter.api.assertThrows
|
||||||
|
import utils.AssertDomainEvent.assertContainsEvent
|
||||||
|
import utils.AssertDomainEvent.assertEmpty
|
||||||
|
import kotlin.test.assertEquals
|
||||||
|
import kotlin.test.assertFalse
|
||||||
|
import kotlin.test.assertNull
|
||||||
|
|
||||||
class ActorsTest {
|
class ActorsTest {
|
||||||
|
@Test
|
||||||
|
fun suspendがtrueのときactorSuspendイベントが発生する() {
|
||||||
|
val actor = TestActor2Factory.create(publicKey = ActorPublicKey(""))
|
||||||
|
|
||||||
|
actor.suspend = true
|
||||||
|
|
||||||
|
assertContainsEvent(actor, ActorEvent.actorSuspend.eventName)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun suspendがfalseになったときactorUnsuspendイベントが発生する() {
|
||||||
|
val actor = TestActor2Factory.create(publicKey = ActorPublicKey(""), suspend = true)
|
||||||
|
|
||||||
|
actor.suspend = false
|
||||||
|
|
||||||
|
assertContainsEvent(actor, ActorEvent.actorUnsuspend.eventName)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun alsoKnownAsに自分自身が含まれない場合更新される() {
|
||||||
|
val actor = TestActor2Factory.create(publicKey = ActorPublicKey(""))
|
||||||
|
|
||||||
|
val actorIds = setOf(ActorId(100), ActorId(200))
|
||||||
|
actor.alsoKnownAs = actorIds
|
||||||
|
|
||||||
|
assertEquals(actorIds, actor.alsoKnownAs)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun moveToに自分自身が設定された場合moveイベントが発生し更新される() {
|
||||||
|
val actor = TestActor2Factory.create(publicKey = ActorPublicKey(""))
|
||||||
|
|
||||||
|
|
||||||
|
actor.moveTo = ActorId(100)
|
||||||
|
|
||||||
|
assertContainsEvent(actor, ActorEvent.move.eventName)
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun alsoKnownAsに自分自身が含まれてはいけない() {
|
fun alsoKnownAsに自分自身が含まれてはいけない() {
|
||||||
val actor = TestActor2Factory.create(publicKey = ActorPublicKey(""))
|
val actor = TestActor2Factory.create(publicKey = ActorPublicKey(""))
|
||||||
|
@ -22,5 +66,65 @@ class ActorsTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun descriptionが更新されたときupdateイベントが発生する() {
|
||||||
|
val actor = TestActor2Factory.create(publicKey = ActorPublicKey(""))
|
||||||
|
|
||||||
|
actor.description = ActorDescription("hoge fuga")
|
||||||
|
|
||||||
|
assertContainsEvent(actor, ActorEvent.update.eventName)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun screenNameが更新されたときupdateイベントが発生する() {
|
||||||
|
val actor = TestActor2Factory.create(publicKey = ActorPublicKey(""))
|
||||||
|
|
||||||
|
actor.screenName = ActorScreenName("fuga hoge")
|
||||||
|
|
||||||
|
assertContainsEvent(actor, ActorEvent.update.eventName)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun deleteが実行されたときすでにdeletedがtrueなら何もしない() {
|
||||||
|
val actor = TestActor2Factory.create(publicKey = ActorPublicKey(""), deleted = true)
|
||||||
|
|
||||||
|
actor.delete()
|
||||||
|
|
||||||
|
assertEmpty(actor)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun deleteが実行されたときdeletedがfalseならdeleteイベントが発生する() {
|
||||||
|
val actor = TestActor2Factory.create(publicKey = ActorPublicKey(""))
|
||||||
|
|
||||||
|
actor.delete()
|
||||||
|
|
||||||
|
assertEquals(ActorScreenName.empty, actor.screenName)
|
||||||
|
assertEquals(ActorDescription.empty, actor.description)
|
||||||
|
assertEquals(emptySet(), actor.emojis)
|
||||||
|
assertNull(actor.lastPostAt)
|
||||||
|
assertEquals(ActorPostsCount.ZERO, actor.postsCount)
|
||||||
|
assertNull(actor.followersCount)
|
||||||
|
assertNull(actor.followingCount)
|
||||||
|
assertContainsEvent(actor, ActorEvent.delete.eventName)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun restoreが実行されたときcheckUpdateイベントが発生する() {
|
||||||
|
val actor = TestActor2Factory.create(publicKey = ActorPublicKey(""), deleted = true)
|
||||||
|
|
||||||
|
actor.restore()
|
||||||
|
|
||||||
|
assertFalse(actor.deleted)
|
||||||
|
assertContainsEvent(actor, ActorEvent.checkUpdate.eventName)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun checkUpdateが実行されたときcheckUpdateイベントがh() {
|
||||||
|
val actor = TestActor2Factory.create(publicKey = ActorPublicKey(""))
|
||||||
|
|
||||||
|
actor.checkUpdate()
|
||||||
|
|
||||||
|
assertContainsEvent(actor, ActorEvent.checkUpdate.eventName)
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -54,8 +54,8 @@ object TestActor2Factory {
|
||||||
keyId = ActorKeyId(keyId),
|
keyId = ActorKeyId(keyId),
|
||||||
followersEndpoint = followersEndpoint,
|
followersEndpoint = followersEndpoint,
|
||||||
followingEndpoint = followingEndpoint,
|
followingEndpoint = followingEndpoint,
|
||||||
InstanceId(instanceId),
|
instance = InstanceId(instanceId),
|
||||||
locked,
|
locked = locked,
|
||||||
followersCount = ActorRelationshipCount(followersCount),
|
followersCount = ActorRelationshipCount(followersCount),
|
||||||
followingCount = ActorRelationshipCount(followingCount),
|
followingCount = ActorRelationshipCount(followingCount),
|
||||||
postsCount = ActorPostsCount(postCount),
|
postsCount = ActorPostsCount(postCount),
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
package dev.usbharu.hideout.core.domain.model.post
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test
|
||||||
|
|
||||||
|
class PostTest {
|
||||||
|
@Test
|
||||||
|
fun deletedがtrueのときghostのidが返される() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,35 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2024 usbharu
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package utils
|
||||||
|
|
||||||
|
import dev.usbharu.hideout.core.domain.shared.domainevent.DomainEventStorable
|
||||||
|
|
||||||
|
object AssertDomainEvent {
|
||||||
|
fun assertContainsEvent(domainEventStorable: DomainEventStorable, eventName: String) {
|
||||||
|
val find = domainEventStorable.getDomainEvents().find { it.name == eventName }
|
||||||
|
|
||||||
|
if (find == null) {
|
||||||
|
throw AssertionError("Domain Event not found: $eventName")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun assertEmpty(domainEventStorable: DomainEventStorable) {
|
||||||
|
if (domainEventStorable.getDomainEvents().isNotEmpty()) {
|
||||||
|
throw AssertionError("Domain Event found")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue