diff --git a/server/action/src/commonMain/kotlin/com/zegreatrob/coupling/server/action/pairassignmentdocument/FindNewPairsAction.kt b/server/action/src/commonMain/kotlin/com/zegreatrob/coupling/server/action/pairassignmentdocument/FindNewPairsAction.kt index 8c7979d608..f8e6b40cf3 100644 --- a/server/action/src/commonMain/kotlin/com/zegreatrob/coupling/server/action/pairassignmentdocument/FindNewPairsAction.kt +++ b/server/action/src/commonMain/kotlin/com/zegreatrob/coupling/server/action/pairassignmentdocument/FindNewPairsAction.kt @@ -13,7 +13,9 @@ import kotools.types.collection.toNotEmptyList @ActionMint data class FindNewPairsAction(val game: Game) { - interface Dispatcher : CannonProvider { + interface Dispatcher : CannonProvider + where D : CreatePairCandidateReportListAction.Dispatcher, + D : NextPlayerAction.Dispatcher { val wheel: Wheel diff --git a/server/action/src/commonMain/kotlin/com/zegreatrob/coupling/server/action/pairassignmentdocument/NextPlayerAction.kt b/server/action/src/commonMain/kotlin/com/zegreatrob/coupling/server/action/pairassignmentdocument/NextPlayerAction.kt index 1f2dd45a53..56347aaa1d 100644 --- a/server/action/src/commonMain/kotlin/com/zegreatrob/coupling/server/action/pairassignmentdocument/NextPlayerAction.kt +++ b/server/action/src/commonMain/kotlin/com/zegreatrob/coupling/server/action/pairassignmentdocument/NextPlayerAction.kt @@ -7,14 +7,14 @@ import com.zegreatrob.testmints.action.async.SimpleSuspendAction import kotools.types.collection.NotEmptyList data class NextPlayerAction(val gameSpin: GameSpin) : - SimpleSuspendAction { - override val performFunc = link(Dispatcher::perform) + SimpleSuspendAction, PairCandidateReport> { + override val performFunc = link(Dispatcher<*>::perform) - interface Dispatcher { + interface Dispatcher { val execute: ExecutableActionExecutor - fun perform(action: NextPlayerAction): PairCandidateReport = with(action.createPairCandidateReports()) { + suspend fun perform(action: NextPlayerAction): PairCandidateReport = with(action.createPairCandidateReports()) { toList().fold(head) { reportWithLongestTime, report -> when { reportWithLongestTime.timeResult == report.timeResult -> diff --git a/server/action/src/commonMain/kotlin/com/zegreatrob/coupling/server/action/pairassignmentdocument/ServerSpinCommandDispatcher.kt b/server/action/src/commonMain/kotlin/com/zegreatrob/coupling/server/action/pairassignmentdocument/ServerSpinCommandDispatcher.kt index cab4f570f1..e5cb829a19 100644 --- a/server/action/src/commonMain/kotlin/com/zegreatrob/coupling/server/action/pairassignmentdocument/ServerSpinCommandDispatcher.kt +++ b/server/action/src/commonMain/kotlin/com/zegreatrob/coupling/server/action/pairassignmentdocument/ServerSpinCommandDispatcher.kt @@ -33,7 +33,8 @@ interface ServerSpinCommandDispatcher : PartyIdLoadPlayersSyntax, PartyIdHistorySyntax, PartyIdPinRecordsSyntax, - CannonProvider where D : NextPlayerAction.Dispatcher, + CannonProvider where D : CreatePairCandidateReportListAction.Dispatcher, + D : NextPlayerAction.Dispatcher, D : FindNewPairsAction.Dispatcher, D : AssignPinsAction.Dispatcher, D : ShufflePairsAction.Dispatcher { diff --git a/server/action/src/commonMain/kotlin/com/zegreatrob/coupling/server/action/pairassignmentdocument/ShufflePairsAction.kt b/server/action/src/commonMain/kotlin/com/zegreatrob/coupling/server/action/pairassignmentdocument/ShufflePairsAction.kt index cc28ea403a..e6be338134 100644 --- a/server/action/src/commonMain/kotlin/com/zegreatrob/coupling/server/action/pairassignmentdocument/ShufflePairsAction.kt +++ b/server/action/src/commonMain/kotlin/com/zegreatrob/coupling/server/action/pairassignmentdocument/ShufflePairsAction.kt @@ -22,7 +22,8 @@ data class ShufflePairsAction( val history: List, ) { interface Dispatcher : Clock, CannonProvider - where D : NextPlayerAction.Dispatcher, + where D : CreatePairCandidateReportListAction.Dispatcher, + D : NextPlayerAction.Dispatcher, D : FindNewPairsAction.Dispatcher, D : AssignPinsAction.Dispatcher { diff --git a/server/action/src/commonTest/kotlin/com/zegreatrob/coupling/server/action/pairassignmentdocument/FindNewPairsActionTest.kt b/server/action/src/commonTest/kotlin/com/zegreatrob/coupling/server/action/pairassignmentdocument/FindNewPairsActionTest.kt index 9d614e4a18..3711d27a35 100644 --- a/server/action/src/commonTest/kotlin/com/zegreatrob/coupling/server/action/pairassignmentdocument/FindNewPairsActionTest.kt +++ b/server/action/src/commonTest/kotlin/com/zegreatrob/coupling/server/action/pairassignmentdocument/FindNewPairsActionTest.kt @@ -11,6 +11,7 @@ import com.zegreatrob.minassert.assertIsEqualTo import com.zegreatrob.minspy.Spy import com.zegreatrob.minspy.SpyData import com.zegreatrob.minspy.spyFunction +import com.zegreatrob.testmints.action.ExecutableActionExecutor import com.zegreatrob.testmints.async.asyncSetup import kotlinx.coroutines.channels.Channel import kotools.types.collection.notEmptyListOf @@ -18,11 +19,19 @@ import kotlin.test.Test class FindNewPairsActionTest { + interface FindNewPairsActionTestDispatcher : + NextPlayerAction.Dispatcher, + CreatePairCandidateReportListAction.Dispatcher, + CreatePairCandidateReportAction.Dispatcher { + override val execute: ExecutableActionExecutor + get() = TODO("Not yet implemented") + } + @Test fun withTwoPlayersEachShouldBeRemovedFromWheelBeforeEachPlay() = asyncSetup(object : - FindNewPairsAction.Dispatcher { + FindNewPairsAction.Dispatcher { override val wheel = StubWheel() - override val cannon = StubCannon(mutableListOf(), Channel()) + override val cannon = StubCannon(mutableListOf(), Channel()) val bill: Player = Player(id = "Bill", avatarType = null) val ted: Player = Player(id = "Ted", avatarType = null) val players = notEmptyListOf(bill, ted) @@ -39,8 +48,8 @@ class FindNewPairsActionTest { @Test fun shouldRemoveAPlayerFromTheWheelBeforeEachPlay() = asyncSetup(object : - FindNewPairsAction.Dispatcher { - override val cannon = StubCannon(mutableListOf(), Channel()) + FindNewPairsAction.Dispatcher { + override val cannon = StubCannon(mutableListOf(), Channel()) override val wheel = StubWheel() val bill: Player = Player(id = "Bill", avatarType = null) val ted: Player = Player(id = "Ted", avatarType = null) diff --git a/server/action/src/commonTest/kotlin/com/zegreatrob/coupling/server/action/pairassignmentdocument/GameExamplesTest.kt b/server/action/src/commonTest/kotlin/com/zegreatrob/coupling/server/action/pairassignmentdocument/GameExamplesTest.kt index 20b2a0866d..16a6e9da2f 100644 --- a/server/action/src/commonTest/kotlin/com/zegreatrob/coupling/server/action/pairassignmentdocument/GameExamplesTest.kt +++ b/server/action/src/commonTest/kotlin/com/zegreatrob/coupling/server/action/pairassignmentdocument/GameExamplesTest.kt @@ -33,7 +33,7 @@ class GameExamplesTest { ShufflePairsAction.Dispatcher, FindNewPairsAction.Dispatcher, AssignPinsAction.Dispatcher, - NextPlayerAction.Dispatcher, + NextPlayerAction.Dispatcher, CreatePairCandidateReportAction.Dispatcher, CreatePairCandidateReportListAction.Dispatcher, DispatchingActionExecutor, diff --git a/server/action/src/commonTest/kotlin/com/zegreatrob/coupling/server/action/pairassignmentdocument/ShufflePairsActionTest.kt b/server/action/src/commonTest/kotlin/com/zegreatrob/coupling/server/action/pairassignmentdocument/ShufflePairsActionTest.kt index 3328772d19..71f5515d33 100644 --- a/server/action/src/commonTest/kotlin/com/zegreatrob/coupling/server/action/pairassignmentdocument/ShufflePairsActionTest.kt +++ b/server/action/src/commonTest/kotlin/com/zegreatrob/coupling/server/action/pairassignmentdocument/ShufflePairsActionTest.kt @@ -14,6 +14,7 @@ import com.zegreatrob.coupling.model.player.Player import com.zegreatrob.coupling.stubmodel.stubPlayer import com.zegreatrob.coupling.testaction.StubCannon import com.zegreatrob.minassert.assertIsEqualTo +import com.zegreatrob.testmints.action.ExecutableActionExecutor import com.zegreatrob.testmints.async.ScopeMint import com.zegreatrob.testmints.async.asyncSetup import kotlinx.coroutines.channels.Channel @@ -25,8 +26,13 @@ class ShufflePairsActionTest { interface ShufflePairsActionInner : FindNewPairsAction.Dispatcher, - AssignPinsAction.Dispatcher, - NextPlayerAction.Dispatcher + NextPlayerAction.Dispatcher, + CreatePairCandidateReportListAction.Dispatcher, + CreatePairCandidateReportAction.Dispatcher, + AssignPinsAction.Dispatcher { + override val execute: ExecutableActionExecutor + get() = TODO("Not yet implemented") + } @Test fun willBuildAGameRunWithAllAvailablePlayersAndThenReturnTheResults() = asyncSetup(object : diff --git a/server/action/src/commonTest/kotlin/com/zegreatrob/coupling/server/action/player/NextPlayerActionTest.kt b/server/action/src/commonTest/kotlin/com/zegreatrob/coupling/server/action/player/NextPlayerActionTest.kt index 4de3c04788..5d531f84aa 100644 --- a/server/action/src/commonTest/kotlin/com/zegreatrob/coupling/server/action/player/NextPlayerActionTest.kt +++ b/server/action/src/commonTest/kotlin/com/zegreatrob/coupling/server/action/player/NextPlayerActionTest.kt @@ -10,12 +10,13 @@ import com.zegreatrob.coupling.server.action.pairassignmentdocument.NextPlayerAc import com.zegreatrob.coupling.server.action.pairassignmentdocument.PairCandidateReport import com.zegreatrob.coupling.server.action.stubActionExecutor import com.zegreatrob.minassert.assertIsEqualTo -import com.zegreatrob.testmints.setup +import com.zegreatrob.testmints.async.asyncSetup import kotools.types.collection.NotEmptyList import kotools.types.collection.notEmptyListOf import kotlin.test.Test -class NextPlayerActionTest : NextPlayerAction.Dispatcher { +class NextPlayerActionTest : NextPlayerAction.Dispatcher { + override val execute = stubActionExecutor(CreatePairCandidateReportListAction::class) private val bill = Player(id = "Bill", avatarType = null) @@ -24,7 +25,7 @@ class NextPlayerActionTest : NextPlayerAction.Dispatcher { private val shorty = Player(id = "Napoleon", avatarType = null) @Test - fun willUseHistoryToProduceSequenceInOrderOfLongestTimeSinceLastPairedToShortest() = setup(object { + fun willUseHistoryToProduceSequenceInOrderOfLongestTimeSinceLastPairedToShortest() = asyncSetup(object { val players = notEmptyListOf(bill, ted, amadeus, shorty) val billsPairCandidates = PairCandidateReport(bill, emptyList(), TimeResultValue(3)) @@ -42,7 +43,7 @@ class NextPlayerActionTest : NextPlayerAction.Dispatcher { } @Test - fun aPersonWhoJustPairedHasLowerPriorityThanSomeoneWhoHasNotPairedInALongTime() = setup(object { + fun aPersonWhoJustPairedHasLowerPriorityThanSomeoneWhoHasNotPairedInALongTime() = asyncSetup(object { val players = notEmptyListOf(bill, ted, amadeus, shorty) val amadeusPairCandidates = PairCandidateReport(amadeus, emptyList(), TimeResultValue(5)) val shortyPairCandidates = PairCandidateReport(shorty, emptyList(), TimeResultValue(0)) @@ -53,7 +54,7 @@ class NextPlayerActionTest : NextPlayerAction.Dispatcher { } verify { it.assertIsEqualTo(amadeusPairCandidates) } @Test - fun sequenceWillBeFromLongestToShortest() = setup(object { + fun sequenceWillBeFromLongestToShortest() = asyncSetup(object { val players = notEmptyListOf(bill, amadeus, shorty) val billsPairCandidates = PairCandidateReport(bill, emptyList(), TimeResultValue(3)) @@ -68,7 +69,7 @@ class NextPlayerActionTest : NextPlayerAction.Dispatcher { } verify { it.assertIsEqualTo(shortyPairCandidates) } @Test - fun sequenceWillPreferPlayerWhoHasNeverPaired() = setup(object { + fun sequenceWillPreferPlayerWhoHasNeverPaired() = asyncSetup(object { val players = notEmptyListOf(bill, amadeus, shorty) val billsPairCandidates = PairCandidateReport(bill, emptyList(), TimeResultValue(3)) @@ -83,7 +84,7 @@ class NextPlayerActionTest : NextPlayerAction.Dispatcher { } verify { it.assertIsEqualTo(shortyPairCandidates) } @Test - fun willPrioritizeTheReportWithFewestPlayersGivenEqualAmountsOfTime() = setup(object { + fun willPrioritizeTheReportWithFewestPlayersGivenEqualAmountsOfTime() = asyncSetup(object { val players = notEmptyListOf(bill, amadeus, shorty) val billsPairCandidates = PairCandidateReport( diff --git a/server/src/jsMain/kotlin/com/zegreatrob/coupling/server/CommandDispatcher.kt b/server/src/jsMain/kotlin/com/zegreatrob/coupling/server/CommandDispatcher.kt index c56e227ce0..4c423784f5 100644 --- a/server/src/jsMain/kotlin/com/zegreatrob/coupling/server/CommandDispatcher.kt +++ b/server/src/jsMain/kotlin/com/zegreatrob/coupling/server/CommandDispatcher.kt @@ -25,6 +25,7 @@ import com.zegreatrob.coupling.server.action.connection.ConnectionsQuery import com.zegreatrob.coupling.server.action.connection.DisconnectPartyUserCommand import com.zegreatrob.coupling.server.action.connection.ReportDocCommand import com.zegreatrob.coupling.server.action.pairassignmentdocument.CurrentPairAssignmentDocumentQuery +import com.zegreatrob.coupling.server.action.pairassignmentdocument.NextPlayerAction import com.zegreatrob.coupling.server.action.pairassignmentdocument.PairAssignmentDocumentListQuery import com.zegreatrob.coupling.server.action.pairassignmentdocument.ServerDeletePairAssignmentsCommandDispatcher import com.zegreatrob.coupling.server.action.pairassignmentdocument.ServerSavePairAssignmentDocumentCommandDispatcher @@ -122,6 +123,7 @@ class CurrentPartyDispatcher( DispatchingActionExecutor, ShufflePairsAction.Dispatcher, AssignPinsAction.Dispatcher, + NextPlayerAction.Dispatcher, PairAssignmentDispatcher, ServerSpinCommandDispatcher, ServerSaveSlackIntegrationCommandDispatcher, diff --git a/server/src/jsMain/kotlin/com/zegreatrob/coupling/server/entity/pairassignment/PairAssignmentDispatcher.kt b/server/src/jsMain/kotlin/com/zegreatrob/coupling/server/entity/pairassignment/PairAssignmentDispatcher.kt index efef55d079..5bb6ba6f16 100644 --- a/server/src/jsMain/kotlin/com/zegreatrob/coupling/server/entity/pairassignment/PairAssignmentDispatcher.kt +++ b/server/src/jsMain/kotlin/com/zegreatrob/coupling/server/entity/pairassignment/PairAssignmentDispatcher.kt @@ -12,10 +12,11 @@ import com.zegreatrob.testmints.action.ExecutableActionExecutor interface PairAssignmentDispatcher : ShufflePairsAction.Dispatcher, FindNewPairsAction.Dispatcher, - NextPlayerAction.Dispatcher, + NextPlayerAction.Dispatcher, CreatePairCandidateReportListAction.Dispatcher, CreatePairCandidateReportAction.Dispatcher, - Wheel where D : NextPlayerAction.Dispatcher, + Wheel where D : CreatePairCandidateReportListAction.Dispatcher, + D : NextPlayerAction.Dispatcher, D : AssignPinsAction.Dispatcher, D : FindNewPairsAction.Dispatcher { override val execute: ExecutableActionExecutor>