From 6d233a1d39ee1c0bd06afcf26384bcfdbf0977a0 Mon Sep 17 00:00:00 2001 From: usbharu Date: Wed, 18 Sep 2024 12:49:07 +0900 Subject: [PATCH] wip --- .../model/followtimeline/FollowTimeline.kt | 22 --- .../FollowTimelineRepository.kt | 22 --- .../domain/model/relationship/Relationship.kt | 2 +- .../model/relationship/RelationshipTest.kt | 140 ++++++++++++++++++ 4 files changed, 141 insertions(+), 45 deletions(-) delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/followtimeline/FollowTimeline.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/followtimeline/FollowTimelineRepository.kt create mode 100644 hideout-core/src/test/kotlin/dev/usbharu/hideout/core/domain/model/relationship/RelationshipTest.kt diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/followtimeline/FollowTimeline.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/followtimeline/FollowTimeline.kt deleted file mode 100644 index 463e4c32..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/followtimeline/FollowTimeline.kt +++ /dev/null @@ -1,22 +0,0 @@ -/* - * 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 dev.usbharu.hideout.core.domain.model.followtimeline - -import dev.usbharu.hideout.core.domain.model.timeline.TimelineId -import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailId - -class FollowTimeline(val userDetailId: UserDetailId, val timelineId: TimelineId) diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/followtimeline/FollowTimelineRepository.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/followtimeline/FollowTimelineRepository.kt deleted file mode 100644 index 92273f70..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/followtimeline/FollowTimelineRepository.kt +++ /dev/null @@ -1,22 +0,0 @@ -/* - * 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 dev.usbharu.hideout.core.domain.model.followtimeline - -interface FollowTimelineRepository { - suspend fun save(followTimeline: FollowTimeline): FollowTimeline - suspend fun delete(followTimeline: FollowTimeline) -} diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/relationship/Relationship.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/relationship/Relationship.kt index f1f48851..87bccaea 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/relationship/Relationship.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/relationship/Relationship.kt @@ -53,7 +53,7 @@ class Relationship( } fun block() { - require(following.not()) + unfollow() blocking = true addDomainEvent(RelationshipEventFactory(this).createEvent(RelationshipEvent.BLOCK)) } diff --git a/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/domain/model/relationship/RelationshipTest.kt b/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/domain/model/relationship/RelationshipTest.kt new file mode 100644 index 00000000..7a299558 --- /dev/null +++ b/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/domain/model/relationship/RelationshipTest.kt @@ -0,0 +1,140 @@ +package dev.usbharu.hideout.core.domain.model.relationship + +import dev.usbharu.hideout.core.domain.event.relationship.RelationshipEvent +import dev.usbharu.hideout.core.domain.model.actor.ActorId +import org.junit.jupiter.api.Test +import utils.AssertDomainEvent.assertContainsEvent +import kotlin.test.assertFalse +import kotlin.test.assertTrue + +class RelationshipTest { + @Test + fun unfollow_フォローとフォローリクエストが取り消されUNFOLLOWとUNFOLLOW_REQUESTが発生する() { + val relationship = Relationship( + actorId = ActorId(1), + targetActorId = ActorId(2), + following = true, + blocking = false, + muting = false, + followRequesting = false, + mutingFollowRequest = false + ) + + relationship.unfollow() + + assertFalse(relationship.following) + assertFalse(relationship.followRequesting) + assertContainsEvent(relationship, RelationshipEvent.UNFOLLOW.eventName) + assertContainsEvent(relationship, RelationshipEvent.UNFOLLOW_REQUEST.eventName) + } + + @Test + fun block_unfollowされblockが発生する() { + val relationship = Relationship( + actorId = ActorId(1), + targetActorId = ActorId(2), + following = true, + blocking = false, + muting = false, + followRequesting = false, + mutingFollowRequest = false + ) + + relationship.block() + + assertTrue(relationship.blocking) + assertContainsEvent(relationship, RelationshipEvent.BLOCK.eventName) + } + + @Test + fun mute_MUTEが発生する() { + val relationship = Relationship( + actorId = ActorId(1), + targetActorId = ActorId(2), + following = true, + blocking = false, + muting = false, + followRequesting = false, + mutingFollowRequest = false + ) + + relationship.mute() + + assertTrue(relationship.muting) + assertContainsEvent(relationship, RelationshipEvent.MUTE.eventName) + } + + @Test + fun unmute_UNMUTEが発生する() { + val relationship = Relationship( + actorId = ActorId(1), + targetActorId = ActorId(2), + following = true, + blocking = false, + muting = true, + followRequesting = false, + mutingFollowRequest = true + ) + + relationship.unmute() + + assertFalse(relationship.muting) + assertContainsEvent(relationship, RelationshipEvent.UNMUTE.eventName) + } + + @Test + fun muteFollowRequest_muteFollowiRequestがtrueになる() { + val relationship = Relationship( + actorId = ActorId(1), + targetActorId = ActorId(2), + following = true, + blocking = false, + muting = false, + followRequesting = true, + mutingFollowRequest = false + ) + + relationship.muteFollowRequest() + + assertTrue(relationship.mutingFollowRequest) + } + + @Test + fun unmuteFollowRequest_muteFollowiRequestがfalseになる() { + val relationship = Relationship( + actorId = ActorId(1), + targetActorId = ActorId(2), + following = true, + blocking = false, + muting = false, + followRequesting = true, + mutingFollowRequest = true + ) + + relationship.unmuteFollowRequest() + + assertFalse(relationship.mutingFollowRequest) + } + + @Test + fun followRequest_followRequestingがtrueになりFOLLOW_REQUESTが発生する() { + + } + + @Test + fun followRequest_ブロックしている場合はフォローリクエストを送れない() { + + } + + @Test + fun unfollowRequest_followRequestingがfalseになりUNFOLLOW_REQUESTが発生する() { + + } + + @Test + fun acceptFollowRequest_followingがtrueにfollowRequestingがfalseになりaccept_followが発生する() { + + } + + +} \ No newline at end of file