Skip to content

Commit

Permalink
additional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alyssaruth committed Mar 5, 2024
1 parent 198a5f8 commit 4a37b35
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/test/kotlin/dartzee/helper/InMemoryDatabaseHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,45 @@ fun insertParticipant(
return pe
}

fun insertTeamAndParticipants(
gameId: String = randomGuid(),
ordinal: Int = 1,
finishingPosition: Int = -1,
finalScore: Int = -1,
dtFinished: Timestamp = DateStatics.END_OF_TIME,
playerOne: PlayerEntity = insertPlayer(),
playerTwo: PlayerEntity = insertPlayer(),
database: Database = mainDatabase
): TeamEntity {
val t =
insertTeam(
gameId = gameId,
ordinal = ordinal,
finishingPosition = finishingPosition,
finalScore = finalScore,
dtFinished = dtFinished,
database = database
)

insertParticipant(
gameId = gameId,
playerId = playerOne.rowId,
teamId = t.rowId,
ordinal = 0,
database = database
)

insertParticipant(
gameId = gameId,
playerId = playerTwo.rowId,
teamId = t.rowId,
ordinal = 1,
database = database
)

return t
}

fun insertTeam(
uuid: String = randomGuid(),
gameId: String = randomGuid(),
Expand Down
49 changes: 49 additions & 0 deletions src/test/kotlin/dartzee/reporting/TestReportParameters.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import dartzee.helper.insertGame
import dartzee.helper.insertGameForReport
import dartzee.helper.insertParticipant
import dartzee.helper.insertPlayerForGame
import dartzee.helper.insertTeamAndParticipants
import dartzee.helper.makeIncludedPlayerParameters
import dartzee.helper.makeReportParametersGame
import dartzee.helper.makeReportParametersPlayers
Expand Down Expand Up @@ -250,6 +251,54 @@ class TestReportParameters : AbstractTest() {
resultsAliceAndBob.shouldContainExactly(gAllPlayers.localId, gAliceAndBob.localId)
}

@Test
fun `Should account for teams when restricting to specific players`() {
val gAllPlayers = insertGame()
val alice = insertPlayerForGame("Alice", gAllPlayers.rowId)
val bob = insertPlayerForGame("Bob", gAllPlayers.rowId)
val clive = insertPlayerForGame("Clive", gAllPlayers.rowId)
val daisy = insertPlayerForGame("Daisy", gAllPlayers.rowId)

val gAliceAndBob = insertGame()
insertTeamAndParticipants(gameId = gAliceAndBob.rowId, playerOne = alice, playerTwo = bob)

val gAliceCliveDaisy = insertGame()
insertTeamAndParticipants(
gameId = gAliceCliveDaisy.rowId,
playerOne = alice,
playerTwo = clive
)
insertParticipant(playerId = daisy.rowId, gameId = gAliceCliveDaisy.rowId)

val gBobAndDaisy = insertGame()
insertTeamAndParticipants(gameId = gBobAndDaisy.rowId, playerOne = bob, playerTwo = daisy)

val gCliveDaisy = insertGame()
insertTeamAndParticipants(gameId = gCliveDaisy.rowId, playerOne = clive, playerTwo = daisy)

val rpIncludeAlice =
makeReportParametersPlayers(
includedPlayers = mapOf(alice to makeIncludedPlayerParameters())
)
val resultsAlice = runReportForTest(player = rpIncludeAlice)
resultsAlice.shouldContainExactlyInAnyOrder(
gAllPlayers.localId,
gAliceAndBob.localId,
gAliceCliveDaisy.localId
)

val rpIncludeAliceAndBob =
makeReportParametersPlayers(
includedPlayers =
mapOf(
alice to makeIncludedPlayerParameters(),
bob to makeIncludedPlayerParameters()
)
)
val resultsAliceAndBob = runReportForTest(player = rpIncludeAliceAndBob)
resultsAliceAndBob.shouldContainExactly(gAllPlayers.localId, gAliceAndBob.localId)
}

@Test
fun `Should only include games with at least one human player if specified`() {
val gAllPlayers = insertGame()
Expand Down
25 changes: 25 additions & 0 deletions src/test/kotlin/dartzee/reporting/TestReportingSqlUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import dartzee.helper.insertGame
import dartzee.helper.insertParticipant
import dartzee.helper.insertPlayer
import dartzee.helper.insertPlayerForGame
import dartzee.helper.insertTeamAndParticipants
import dartzee.helper.makeReportParameters
import io.kotest.matchers.shouldBe
import org.junit.jupiter.api.Test
Expand Down Expand Up @@ -42,6 +43,30 @@ class TestReportingSqlUtil : AbstractTest() {
)
}

@Test
fun `Should parse teams correctly`() {
val alice = insertPlayer(name = "Alice")
val bob = insertPlayer(name = "Bob")
val clive = insertPlayer(name = "Clive")

val g1 = insertGame()
insertParticipant(gameId = g1.rowId, playerId = alice.rowId, finishingPosition = 1)
insertTeamAndParticipants(
gameId = g1.rowId,
playerOne = bob,
playerTwo = clive,
finishingPosition = 2
)

val results = runReport(makeReportParameters())
results.size shouldBe 1
val wrapper = results.first()

val row = wrapper.getTableRow()
row shouldBe
arrayOf(g1.localId, "501", "Alice (1), Bob & Clive (2)", g1.dtCreation, g1.dtFinish, "")
}

@Test
fun `Should return a game not part of a match`() {
val alice = insertPlayer(name = "Alice")
Expand Down

0 comments on commit 4a37b35

Please sign in to comment.